How PNG Compression Works
Every PNG file uses DEFLATE compression, a combination of LZ77 (byte-level repetition matching) and Huffman coding. The compression level (0-9 in zlib) controls how hard the encoder searches for repeated patterns. At level 9, the encoder finds the best possible lossless encoding; at level 1, it finishes faster but leaves file size on the table. Most PNGs saved by image editors use level 6. jpg.now always writes at level 9, giving 10-30% savings over typical editor output with no pixel change whatsoever.
PNG Filter Optimization
Before DEFLATE runs, PNG applies a filter to each row of pixels. Filters transform raw pixel values into differences between neighboring pixels. Small differences with lots of zeros compress much better than large absolute values. PNG supports five filter types (None, Sub, Up, Average, Paeth), and the optimal choice depends on image content. jpg.now's PNG compressor tests multiple filter combinations to find the smallest output, squeezing out an additional 5-15% versus a single-filter approach.
Lossy Compression via Color Quantization
Standard PNG stores up to 16.7 million colors (24-bit RGB). Most images such as logos, icons, UI screenshots, and illustrations use far fewer distinct colors in practice. Color quantization reduces the palette to 256 colors or fewer (8-bit indexed PNG), then applies lossless DEFLATE on top. The result is technically lossy but visually identical for most content. Savings are 40-70% on top of lossless optimization, making total reductions of 50-80% common for flat-color graphics.
jpg.now uses pngquant's libimagequant library when available, which produces dithered, perceptually tuned palettes far superior to basic median-cut. The quality slider maps to pngquant's min-max quality range, giving you continuous control over the size/quality trade-off.
Lossless vs Lossy: Choosing the Right Setting
| Quality | Method | Typical savings | Best for |
|---|---|---|---|
| 100% (Lossless) | zlib level 9 + filter optimization | 10-30% | Photos, images where pixel accuracy matters, archiving |
| 80-99% | Conservative quantization + optimize | 30-50% | Web images, icons, logos with gradients |
| 60-79% | Moderate quantization (256 colors) | 50-70% | UI screenshots, flat-color graphics, favicons |
| Below 60% | Aggressive palette reduction | 60-80% | Thumbnails, email attachments where smallest size wins |
When to Convert to JPEG Instead
Even after aggressive compression, PNG is the right choice for images with transparency, logos, text, screenshots, and any image you plan to edit again (JPEG re-encoding accumulates generation loss). If your PNG is a photograph with no transparency requirement, converting to JPEG at quality 80-90 will produce a substantially smaller file than even an aggressively compressed PNG.