๐Ÿงฐ UtlKit

How to Use the Image Compressor: JPEG Re-encoding at Quality 10 to 95 from a Local File, in the Browser

One local image file, re-encoded to JPEG at a quality from 10 to 95 on a canvas, with the size delta read off a base64 length estimate, all computed in the browser.

The Image Compressor reads one local image file, re-encodes it as JPEG on a canvas, and shows the size change before you download anything. You pick the file with the file picker, the page draws it at its original dimensions, and the canvas re-encodes it at the quality on the slider, which defaults to 70%. The readout then prints the original size, the estimated compressed size, and the percentage, like 2,400,000B โ†’ 833,351B (-65%), and a side-by-side preview shows the original next to the result. Everything is a browser-side canvas call: the file bytes never leave the device, and no upload happens at any point.

What the tool takes and what it gives

The input is a single file field that accepts image files, and nothing else is asked. The original size is the file's exact on-disk byte count, so the left half of the readout is precise. The output is always a JPEG: the canvas hands its pixels to the browser's JPEG encoder, the output format is fixed and not selectable, and the width and height stay exactly what the input was. The only control is the quality slider, which runs from 10 to 95 in steps of 5, giving 18 stops, and moving it re-encodes the kept original immediately, so the readout and the preview update live. When you are happy with the size, the download button writes the result to your disk as compressed.jpg; the file you save is the ground truth for the actual byte count.

Why the output is always JPEG

The re-encode is one canvas call whose output type is hard-set to JPEG, so a PNG in becomes a JPEG out, a WebP in becomes a JPEG out, and a GIF in keeps only its first frame, because the image element decodes only the first frame of an animated file. Two consequences follow from the fixed format. First, JPEG has no alpha channel, so a transparent PNG does not stay transparent: the transparent pixels are composited over black before encoding, and what you download has black where the input had transparency. Second, the tool uses the browser's own decoder with no fallback, so a format the browser cannot decode, such as HEIC on most platforms, simply never finishes decoding and the page renders nothing for it.

How the size is read out

The compressed size is an estimate, and a deliberately simple one. The canvas returns a data URL, a 23-character data:image/jpeg;base64, prefix followed by base64, and the page takes the whole string length and multiplies it by three quarters, since base64 uses four characters for every three bytes. That estimate overshoots the true byte count by the prefix alone, which works out to 17 to 19 bytes over: a 1,000,000-byte JPEG reads as 1,000,019B, and a 999,999-byte one reads as 1,000,016B. In a full run, a 2,400,000B file whose encoder output is 833,333 bytes prints 2,400,000B โ†’ 833,351B (-65%); the percentage is rounded, so the displayed number and the exact arithmetic can differ by one point.

When the file gets bigger

The savings percentage is the round of one minus the compressed size over the original size, times one hundred, and a negative result is shown with a plus, so a file that grew is reported as, for example, 45,000B โ†’ 47,018B (+4%). That happens for small images, where the encoder's fixed overhead dominates, for a JPEG that is already compressed at or below the selected quality, and whenever the slider sits above the quality the original file was actually saved at. The direction is not a bug: at 10 the output is the smallest it will get and at 95 the largest, so if the readout climbs as you raise the quality, the original was already leaner than the encoder wants to make it.

Where the pixels go

The file is read with the FileReader into a data URL on the page, and the only computation is the canvas draw plus the JPEG encode, so the bytes never leave the device and there is no network request at any point. There is also no persistence: the page keeps the data URL only while it is open, there is no history and no cache, and closing or reloading the tab discards the image and the result. The single artifact that can leave the device is the compressed.jpg you choose to download, and you choose that yourself.

What it is not

The tool keeps the input dimensions exactly, so it is not a resizer; changing the pixel size is what the Image Resizer does. It is not a format converter either, because the output is fixed to JPEG; choosing the output format is the job of the Image Converter. It does not read or display the file's metadata, which the Image Info Viewer shows, and it does not crop the frame; for that, see the cropping guide.

Related Tools

Frequently Asked Questions

Does the Image Compressor upload my image to a server?

No. The file is read by the FileReader into a data URL on the page, and the only computation is the canvas draw plus the JPEG encode, so the bytes never leave the device and no network request is made at any point. The only thing that can leave is the compressed.jpg you choose to download.

Why is the transparency of my PNG gone and the background black?

The output is always a JPEG, and JPEG has no alpha channel. Before encoding, the transparent pixels are composited over black on the canvas, so the file you download has black where the input had transparency. There is no setting that keeps the transparency, because the output format is fixed.

Why does the size readout differ from the downloaded file by a few bytes?

The readout is an estimate: the length of the data URL, a 23-character base64 prefix plus the base64 body, times three quarters, rounded. The prefix alone pushes the number 17 to 19 bytes above the true count. The file you download is encoded directly from the canvas, so it is the ground truth; treat the readout as a same-shape preview, not a byte-exact promise.

Why is my compressed file bigger than the original?

The savings percentage can go negative, and a negative result is shown with a plus, for example 45,000B โ†’ 47,018B (+4%). That happens for small images, where the encoder fixed overhead dominates, for a JPEG already compressed at or below the selected quality, and whenever the slider is above the quality the original was saved at. At 10 the output is at its smallest and at 95 at its largest, so the readout can climb as you raise the quality.

Which quality should I pick?

The slider has 18 stops, from 10 to 95 in steps of 5, and it defaults to 70. Moving it re-encodes the kept original immediately, so the readout and the preview update live; pick the lowest quality where the preview still looks right for what you are using the image for, and check the size readout at that stop.

Related Articles