Image Processing in the Browser with Canvas

By BoltQuickTools team · May 18, 2026 · Updated November 8, 2026 · 7 min read

The usual way to build an image tool is a server endpoint: accept an upload, run ImageMagick or libvips, send the result back. For everyday resizing, compression, and format conversion, the browser can do the same work with built-in APIs and no upload. This post covers how that pipeline works, what it cannot do, and when a server is still the better choice.

The resizer, compressor, converter, and upscaler on BoltQuickTools all use this approach: the page decodes the file, draws it to a canvas, and encodes a new file. OCR is the exception and has its own section below.

Where the time goes

On a server, the transfer comes first. A 3 MB file is 24 megabits, so it needs about half a second on a 50 Mbps upload link and about 2.4 seconds on a 10 Mbps link, before the server has started. After processing, the result has to come back down.

In the browser there is no transfer, but the work runs on the visitor's hardware, so the time depends on image size and device. There is no fixed file size at which one side wins: a small image on a laptop finishes locally before an upload would, and a huge image on an old phone may be faster on a server. To get a real number for your own images, wrap the code below with performance.now() and run it on the devices you care about.

The Canvas pipeline, end to end

A minimal resize takes five steps:

const file = event.target.files[0];

// 1. Decode the file (no network involved)
const bitmap = await createImageBitmap(file);

// 2. Set up a canvas at the target size
const canvas = document.createElement('canvas');
canvas.width = newWidth;
canvas.height = newHeight;
const ctx = canvas.getContext('2d');

// 3. Draw with smoothing
ctx.imageSmoothingEnabled = true;
ctx.imageSmoothingQuality = 'high';
ctx.drawImage(bitmap, 0, 0, newWidth, newHeight);

// 4. Encode to the chosen format
const blob = await new Promise(resolve =>
  canvas.toBlob(resolve, 'image/jpeg', 0.9)
);

// 5. Offer the result as a download
const url = URL.createObjectURL(blob);

Two details matter in practice. JPEG has no alpha channel, so transparent pixels come out black unless you fill the canvas with a background color first; the image resizer fills it with white for JPEG output. And imageSmoothingQuality is only a hint that browsers implement differently, so if a large downscale looks jagged, reduce the image in steps of one half instead of one big jump.

Format support

Reading. Canvas can draw anything the browser's image decoder understands: PNG, JPEG, WebP, BMP, AVIF in current browsers, and the first frame of a GIF.

Writing. The HTML specification only requires toBlob() to produce PNG. JPEG is available everywhere and WebP in most browsers. If the browser cannot encode the type you asked for, it silently returns PNG, so check the result:

canvas.toBlob(blob => {
  if (blob.type !== 'image/webp') {
    // The browser fell back to PNG. Safari has historically done this.
  }
}, 'image/webp', 0.8);

Do not rely on canvas to encode AVIF; that takes a WebAssembly encoder. BMP, GIF, and ICO output also need code that writes those file formats directly, because canvas will not produce them.

SVG is drawn by loading it into an <img> first, which turns it into pixels at the size you choose. The SVG converter works this way.

HEIC, the default iPhone format, decodes natively in Safari but not in Chrome or Firefox. The image converter here has no HEIC decoder of its own, so it can only read HEIC in a browser that can already decode it. On an iPhone, setting Camera > Formats to Most Compatible avoids the problem.

RAW files (CR2, NEF, ARW) are out of scope for Canvas. Use desktop software.

Where Canvas hits its limits

Memory

Decoded size depends on pixels, not on the file. A 24-megapixel photo takes about 96 MB as raw RGBA (4 bytes per pixel), even if the JPEG is only 5 MB, and a resize holds the source and the destination at the same time. Browsers also cap canvas dimensions and total area, with lower limits on mobile. When a canvas is too large, toBlob() passes null to its callback, so handle that case instead of assuming a result.

The main thread

Canvas work on the main thread blocks the page. For long operations, move it into a Web Worker with OffscreenCanvas, which every major browser now supports (Safari since version 16.4 in 2023):

// Inside a worker
const off = new OffscreenCanvas(newWidth, newHeight);
off.getContext('2d').drawImage(bitmap, 0, 0, newWidth, newHeight);
const blob = await off.convertToBlob({ type: 'image/webp', quality: 0.8 });

Color

A 2D canvas is sRGB by default. A wide-gamut photo, such as a Display P3 image from a recent phone, is converted to sRGB when drawn, and the output file does not carry the original ICC profile. That is usually fine for web images and a real loss for photo editing. You can request a wide-gamut canvas with getContext('2d', { colorSpace: 'display-p3' }) where the browser supports it.

EXIF metadata

Re-encoding through a canvas writes a new file from pixels alone, so GPS coordinates, camera details, and copyright tags are all gone. For a photo you are about to post publicly, that is what you want. For a photographer who needs to keep a copyright tag, it is not. Orientation still comes out right, because both createImageBitmap and <img> apply the EXIF rotation by default, so the pixels are already upright when they reach the canvas.

The EXIF viewer shows what a file contains and can strip it, so you can see what would be lost.

What "no upload" does and does not mean

When a tool does its work on a canvas, your image does not need to travel anywhere, and a server cannot log or retain a file it never received. The page around the tool still loads scripts for ads, analytics, and translation, so the claim is about the tool's own behavior. You can check it yourself: open the Network tab in DevTools, process a file, and see whether any request carries it.

The OCR exception

The OCR tool does make network requests. Its page loads Tesseract.js from the jsDelivr CDN, and the engine downloads a trained language model from a CDN the first time you use a language (roughly 1 to 15 MB depending on the language, and your browser may cache it). Recognition itself runs in your browser using WebAssembly, so your image stays local, but the tool will not work without a connection to those CDNs.

When a server is the better choice

If you are building an image tool

  1. Start with Canvas. It covers resizing, compression, and common format conversion.
  2. Prefer createImageBitmap over new Image() for decoding. It is asynchronous and browsers can do the work off the main thread.
  3. Move long operations into a Web Worker with OffscreenCanvas.
  4. Add a WebAssembly module only for formats Canvas cannot handle, and tell users if it is downloaded from a CDN.
  5. Process very large images in tiles so peak memory stays manageable.
  6. State on the tool page what gets removed (EXIF, ICC profiles), and check blob.type and null results.

Related image tools