Browser-only tool

Base64 Image Compressor

Decode a Base64 image, resize or re-encode it locally, and keep a standard result that works in img src, CSS, JSON, and APIs.

Runs locally in your browser · No upload · No account

Paste raw Base64 with optional whitespace, or a complete data:image/...;base64,... value. Remote URLs are intentionally unsupported.

Compression settings

Result

Original preview

Choose or paste an image to preview it.

Result preview

Choose or paste an image to preview it.

Original information

Result information

Base64 is encoding, not image compression

Standard Base64 turns each three input bytes into four text characters, so its length is 4 × ceil(n / 3) and the long-run overhead is about 33.3%. A data URL adds a MIME prefix on top of those characters.

This tool reduces the image bytes first: it decodes the image, changes dimensions, quality, or format when useful, and then creates standard Base64 again. The result needs no custom decompressor.

Why Gzip is a different output

Gzipping Base64 produces compressed binary data that must be decompressed before an image element can read it. Encoding that Gzip stream again does not make it a normal image data URL.

JPEG, PNG, and WebP are already compressed formats. Canvas re-encoding may help by reducing pixels, changing a lossy quality, removing metadata, or choosing another format, but it is not guaranteed to be lossless or smaller.

Target size without returning a larger string

For JPEG and WebP, the tool searches quality with a fixed iteration limit. If the lowest useful quality is still too large, it reduces dimensions in bounded steps while preserving aspect ratio.

If no valid result has fewer standard Base64 characters, the original bytes are kept. A near-target result is clearly marked when the requested KB limit cannot be reached.

Local processing and format boundaries

The image stays in this browser tab. No file upload, account, remote URL, telemetry, or third-party image library is used. The 20 MiB decoded-byte and 16 megapixel limits protect the tab from accidental memory pressure.

SVG, GIF, ICO, and animated WebP are rejected rather than executed or silently flattened. Transparency is preserved in Auto mode; converting transparent pixels to JPEG requires an explicit background color. Canvas re-encoding is not a malware scan.

When not to use Base64

Data URLs are useful for small self-contained assets, fixtures, and paste-ready API fields. Large images usually work better as Blob URLs, separate files, or binary uploads because they can be cached and streamed independently.

Use the byte and Base64 comparisons below to judge the real result. Removing a data: prefix is never counted as compression.

Common failures this tool explains

  • Malformed Base64, impossible padding, or characters outside the Base64 alphabets.
  • A declared data URL MIME type does not match the decoded magic bytes.
  • The image exceeds 20 MiB, 16 megapixels, or the browser cannot decode it.
  • The source is animated, multi-frame, SVG, or already too optimized to become smaller.

Equivalent commands

Use the runtime or shell already available in your workflow. Validate untrusted input and keep binary output out of terminals.

Python

from PIL import Image
from io import BytesIO
import base64
image = Image.open(BytesIO(base64.b64decode(value)))
out = BytesIO(); image.save(out, 'WEBP', quality=82)
result = base64.b64encode(out.getvalue()).decode('ascii')

JavaScript

const blob = new Blob([bytes], { type: mime });
const bitmap = await createImageBitmap(blob);
ctx.drawImage(bitmap, 0, 0, width, height);
const output = await new Promise(r => canvas.toBlob(r, 'image/webp', 0.82));
bitmap.close();

Shell

printf '%s' "$VALUE" | base64 --decode > input.png
magick input.png -resize '1920x1920>' -quality 82 output.webp
base64 --wrap=0 output.webp

Standards and official references

Base64 image compression FAQ

Can Base64 itself be compressed?

A general compressor can compress the text, but the result is a different binary format. To keep standard image Base64, optimize the decoded image bytes and encode them again.

Can the result still be used directly in img src?

Yes. Raw output is standard Base64, and Data URL output is a normal data:image/...;base64 value.

How can I reduce a Base64 image to 100 KB?

Choose Custom, select 100 KB, and run the tool. It searches bounded quality values and then dimensions; some images cannot reach the target without unacceptable or unsupported changes.

Does compression reduce quality?

It can. Resizing and JPEG/WebP quality changes are lossy. PNG output can remain pixel-lossless, but re-encoding may not reduce its size.

Why is Base64 about 33% larger?

Base64 represents every three bytes with four characters. The exact character count is 4 × ceil(n / 3).

Is my image uploaded?

No. Parsing, decoding, Canvas work, previews, copying, and downloads happen locally in the browser.

Should I Gzip before or after Base64?

For network transfer, compress the enclosing HTTP response when appropriate. A Gzip payload is not directly usable as an image data URL without decompression code.