How Photo2KB Hits an Exact KB Target

Most compressors give you a quality slider and let you guess. Photo2KB treats "100 KB" as a hard requirement and searches for it automatically — here is the exact algorithm.

1. Re-Encode, Don't Just Crop

Your image is redrawn onto a canvas and re-encoded. JPEG and WebP encoders accept a quality parameter from 5 to 96 — each value produces a different file size at the same resolution.

2. Binary Search over Quality

Instead of trying every value top to bottom, we binary-search: encode at the midpoint, compare against your target, and halve the search space. Seven passes are enough to converge — typically within ±2 KB.

3. If Quality Alone Can't Get There, Shrink Pixels

A 12-megapixel photo may not reach 20 KB at any quality. When the lowest quality still exceeds the target, the engine reduces resolution by 20% and searches again — the same trade-off you'd make manually, but automated. PNG has no quality parameter, so PNG targets always search over size.

4. It All Happens in Your Browser

The engine is JavaScript running on your device. No upload, no queue, no server cost — which is why it's free and works offline.

Every Long-Tail Page Ships with a Real Benchmark

We run the same algorithm against a reference photo for every size/format page (like compress image to 100 KB) and publish the measured input, output and time on the page. No invented numbers.