# Compress a JPG photo

> Lower the JPEG quality of a camera or phone photo to cut its file size, keep the same pixel size and drop the GPS tags, all inside your browser.

Use it online (free, runs in your browser): https://directory.milunir.com/image-tools/image-editors/image-compressor/compress-jpg/

A JPEG saved by a camera at 95% quality often halves in size at 75% with no change you can see at normal viewing size. This page opens with that setting for JPG photos.

## Worked example

- Mode: By quality
- Quality: 75
- Largest file size: 200
- Unit: KB
- Save as: JPG

Result: Compressed size: 4.5 KB Compared with the original: 19% smaller Pixel size: 400 × 300 px

## How it works

`chosen quality = the highest q in 5–95% where encoded size(q) ≤ limit; limit in bytes = KB × 1,024 or MB × 1,048,576`

- `q`: the JPEG or WebP quality passed to the browser encoder
- `limit`: the largest file size you typed, in bytes

The browser decodes the picture, turns it upright from its EXIF orientation tag and redraws it on a canvas. In To a file size mode it first saves at 5% quality. If that already fits, a halving search over six more saves narrows down the best quality under the limit. If even 5% is too large, the width and height are cut by about the square root of the size ratio and the search repeats. PNG output is lossless, so only the scaling step applies to it.

Sources:

- [HTML Standard: the canvas element, toBlob()](https://html.spec.whatwg.org/multipage/canvas.html#dom-canvas-toblob), WHATWG
