How Image Compression to 20 KB Works
A technical look into our bounded search algorithm, binary validation, and client-side execution.

1. Pure Client-Side Binary Header Validation
Before allocating canvas memory or calling browser decoders, the application runs hand-rolled, pure binary parsers on the image's raw bytes:
- JPEG: Checks the
0xFFD8SOI marker, walks segment markers, parses SOF segments for component counts and bit depth, and inspects EXIF APP1 tags for orientation (1–8). - PNG: Validates the 8-byte PNG header, verifies CRC32 checksums on structural chunks, determines alpha transparency, and rejects animated APNG chunks (
acTL). - WebP: Reads the RIFF container header, checks VP8/VP8L/VP8X chunks, verifies alpha channels, and rejects animated frames (
ANIM).
2. The Bounded Multi-Stage Quality Search
Unlike naive compressors that compress once and hope the file happens to be small enough, our engine runs a deterministic bounded search:
Quality Grid Sampling
Tests quality levels across a calibrated grid from 94% down to 10% (e.g. 0.94, 0.86, 0.76, 0.66, 0.56, 0.46, 0.36, 0.27, 0.18, 0.10).
Midpoint Refinement
When a quality level fits under the byte limit, a binary midpoint refinement searches up to 3 midpoints to find the maximum possible visual fidelity.
Smart Downscaling
If the file cannot fit at original resolution even at 10% quality, the engine calculates an optimal scale factor using square-root byte ratios and restarts at smaller pixel dimensions.
Alpha Flattening
When converting transparent PNGs to JPEG, transparent areas are automatically rendered over a clean white background to prevent black or corrupted alpha artifacts.
3. Strict Post-Encode Verification Gate
A file is never made available for download until its encoded Blob size has been verified against the exact target ceiling (e.g. size ≤ 20,000 bytes) and its magic header bytes confirm the intended format. If verification fails, no download link is shown.
Try the exact byte limit you need
Every portal declares a different ceiling. The engine above runs identically on each dedicated limit page: exam photos on resize image to 20 KB, banking forms on compress image to 50 KB, certificate scans on compress image to 100 KB, and photos with transparency on compress PNG online. Confused by portal wording? The 20 KB vs 20 KiB explainer covers why the byte count, not the label, is what gets validated.