React does not compress images itself. In a React upload flow, take the selected browser File, compress it asynchronously in the browser, then upload the returned File through your existing upload path. A library such as browser-image-compression is a straightforward way to do this.
Compress the selected file before uploading it
Install the package with npm install browser-image-compression, then call it from the file input’s change handler. The example below keeps the selected file in state and passes the compressed result to a placeholder upload function; connect that function to your application’s existing API or storage provider.
import { useState } from 'react';
import imageCompression from 'browser-image-compression';
export default function ImageUpload() {
const [file, setFile] = useState(null);
const [status, setStatus] = useState('');
async function handleFileChange(event) {
const selected = event.target.files?.[0];
if (!selected) return;
setStatus('Compressing…');
try {
const compressed = await imageCompression(selected, {
maxSizeMB: 1,
maxWidthOrHeight: 1920,
useWebWorker: true,
});
setFile(compressed);
setStatus(`Ready to upload (${compressed.size} bytes)`);
} catch (error) {
setStatus(error.name === 'AbortError' ? 'Compression cancelled.' : 'Could not compress this image.');
console.error(error);
}
}
async function handleUpload() {
if (!file) return;
setStatus('Uploading…');
try {
await uploadFile(file);
setStatus('Upload complete.');
} catch (error) {
setStatus('Upload failed.');
console.error(error);
}
}
return (
{status}
);
}
async function uploadFile(file) {
const formData = new FormData();
formData.append('image', file, file.name);
const response = await fetch('/api/upload', { method: 'POST', body: formData });
if (!response.ok) throw new Error(`Upload failed: ${response.status}`);
}
The sample’s 1 MB target and 1,920-pixel maximum dimension are illustrative settings, not universal recommendations or measured savings. Set limits based on your product’s upload rules and the image quality it needs. The package documentation describes its Promise-based React-compatible API and options at browser-image-compression on npm.
Choose the compression settings for your upload requirements
Byte size and pixel dimensions solve different problems. A maximum dimension limits how large the image can be in pixels; a size target controls the encoded output size. Use one or both constraints only when your product needs them. Lower dimensions or more aggressive lossy encoding can reduce detail, so inspect results using representative photographs and graphics.
#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
maxSizeMB: target a maximum output size in megabytes.maxWidthOrHeight: limit the longer image dimension while preserving its proportions.initialQuality: configure the initial lossy encoding quality where supported by the chosen output format.fileType: request an output format such as JPEG or WebP when appropriate and supported by the target browser.useWebWorkerandonProgress: opt into worker processing and report progress when the UI needs it.preserveExif: decide whether EXIF metadata should be retained; orientation handling is a separate concern.signal: pass an abort signal if the interface lets users cancel an in-progress compression.
Check the package documentation for the complete current option list and details: browser-image-compression options.
Handle the result safely in your upload flow
- Validate that a file was selected, and catch compression failures or cancellation rather than leaving the form stuck in a loading state.
- Compare
compressed.sizewith the originalFile.size. A result is not guaranteed to be smaller in every case; decide whether to keep the original when compression increases the size. - Preserve a useful filename and send the actual output type with the upload. If you change formats, ensure your server does not rely on the original filename extension or MIME type.
- Do not upload until the asynchronous compression promise resolves. Pass the returned
Fileto the upload code, not the original input file. - Test camera images for orientation. Decide explicitly whether to preserve metadata; retaining EXIF is not the same as correcting orientation.
Browser APIs for a custom compression pipeline
You can build the pipeline without a compression package, but then your application owns more compatibility and error handling. A typical flow fetches or reads a Blob, decodes it with createImageBitmap, draws it to a canvas, and encodes the canvas with toBlob. Chrome’s overview describes this pattern and using createImageBitmap in workers: Chrome for Developers: createImageBitmap in Chrome 50. MDN documents worker decoding options, orientation and resizing behavior: MDN: WorkerGlobalScope.createImageBitmap.
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
A custom implementation must choose output type and quality, handle a null canvas encoding result, manage filenames and MIME types, and account for orientation, metadata, cancellation and browser differences. For browser image resizing specifically, pica documents approaches including workers, WebAssembly, createImageBitmap and JavaScript fallbacks. The cited documentation does not establish a comparable speed or quality benchmark for these approaches or libraries; test them with your own files and target devices.
Performance, compatibility and deployment checks
- Image decoding and canvas re-encoding can take time and use memory, especially for large source images. Worker processing can keep work off the main thread when supported; the package documents fallback to the main thread and notes that its non-blocking worker path depends on browser support for
OffscreenCanvas. - Review your Content Security Policy if using the worker path. The package documents that it may require
blob:and a library URL inscript-src, or a self-hosted worker-library URL. - Browser canvas dimensions have limits. The package says it adjusts dimensions to remain within browser limits, but test very large images in the browsers and devices you support.
- Do not force WebP or another output format until you have verified it works for the browsers and downstream systems in your support matrix. The package documents JPEG, PNG, WebP and BMP support and notes browser-specific canvas and WebP considerations.
- There is no documented universal compression ratio or processing-time figure for this workflow. Measure representative input types and devices before claiming savings or setting performance expectations.
Project documentation and implementation notes are available in the browser-image-compression repository.
Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
Or skip the browser setup
If what you need is a screenshot of a website rather than compression of a user-selected upload, ScreenshotNeo is a website screenshot API and MCP server. It returns an image or PDF from one GET request; it is not a replacement for compressing files selected in your React form.
For example, request a WebP screenshot of a page with cURL:
Quick Recap
Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
See the ScreenshotNeo API documentation for request options. It removes cookie banners, newsletter popups and chat widgets before capture; bot checks, blank pages and failed loads are never billed; its MCP server lets AI agents take screenshots; and 1,000 screenshots a month are free with no card, with paid plans starting at $5 for 3,000. Sign up for free screenshots.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

