A compression step in a pipeline should be idempotent: run it twice and the second run should change nothing. For PNG, several common steps are not. Some of them make the file bigger on the second pass.
Here is one concrete case. A 2880×1800 UI screenshot was quantized to 256 colours once, and then each of the usual follow-up steps was applied to that result separately. Everything below is from one run of each tool on one Apple-silicon Mac, on a handful of procedurally generated samples, plus one CC0 photo. The generated content is fictional. Because generated images have a lot of flat colour, they compress better than real design files, so treat the percentages as relative, not as promises.
The setup
The source is a fake merchant-dashboard screenshot, 378,956 bytes, 3,039 colours. First pass: pngquant at 256 colours. That saved 62.3% and changed only 1.9% of the pixels, which is invisible when you zoom in. The output is a 142,869-byte indexed PNG. Call it the already-optimized file.
Now treat that file as input to a pipeline that does not know its history.
What happened on the second pass
| Step applied to the already-quantized PNG | Size change |
|---|---|
| pngquant 256 colours again | 0.0%, output pixel-identical |
| Lossless re-compress (oxipng) | -7.3% |
| Lossless re-compress (zopflipng) | -10.3% |
| Lossy WebP, quality 80 | +5.1% |
| Halve width and height, save as PNG | +56.7% |
| Halve width and height, then quantize to 256 | -29.5% |
| WebP lossless | -42.2% |
| AVIF, quality 60 | -55.9% (lossy) |
For comparison, the same screenshot before the first quantization: pngquant saved 62.3%, lossy WebP q80 saved 60.4%, and halving the dimensions as a PNG saved 41.7%. The identical step that was a big win on the original was a no-op, a loss, or a disaster on the optimized copy.
Why each one behaves that way
Re-quantizing is the benign case. The image already has at most 256 colours, so the quantizer finds nothing to merge. The output was identical to the input, pixel for pixel. This is idempotent in the useful sense: nothing broke and nothing grew. It just burned CPU.
Lossy WebP is where it turns negative. A 256-colour screenshot is mostly long runs of identical pixels, which PNG handles well. A plausible reason for the loss is that a lossy codec has to approximate sharp text edges with transform blocks (inference, the encoder was not inspected), and on this file the result came out 5.1% larger than the input. It also dropped quality: the PSNR was 41.9 dB, so you pay in fidelity and get a bigger file. That lines up with "png转webp变大" ("PNG to WebP gets bigger"), a phrase that appears in Baidu's search suggestions. In this run it showed up only on the already-reduced file; the other five sources got smaller with lossy WebP.
The 56.7% is the one a code review should catch. Downscaling interpolates pixels, and interpolation produces in-between colours, so the indexed image becomes a truecolour image again. If the pipeline then writes a plain PNG, you have thrown away the palette that made the file small. Resize first, quantize last, and the same file ends at 29.5% smaller.
What still works
Three things reduced this file without a penalty. Lossless recompression gave 7.3% (oxipng) and 10.3% (zopflipng), and the pixels did not change. WebP lossless gave 42.2%, also pixel-exact. AVIF gave 55.9%, but it is lossy, so it belongs in the other bucket.
So "can't compress it further" is wrong. "Can't compress it further the way I did the first time" is closer. A photo is stuck for a different reason. The 3.30 MB test photo (Wikimedia Commons, "Avions à l'aéroport de Madrid - 2015.JPG", CC0) saved only 7.5% with lossless PNG recompression, while lossy WebP q80 and AVIF q60 saved 94.4% and 95.8%.
A guard instead of a hope
A cheaper fix than a cleverer optimizer is a pre-check. Before any lossy step, look at the file: is it indexed already, is the palette at or under 256 entries, do the colours repeat in long runs? If so, the lossy steps get skipped, and only lossless recompression or a lossless format change is allowed. After any resize, quantize again as the last step. Both rules are about ordering and state, not about tuning quality numbers. This is a design suggestion; no such guard was built or tested here.
The same logic applies to one-off tools. ImgIng at https://imging.ai/ runs in the browser and picks a format from the content of the image. On the gradient sample, in a desktop browser, its default output went from 346.7 KB to 27.5 KB, which is 92% saved. That test did not include an already-quantized file, so what it does on a second pass is unknown.
What this run did not cover
Only one quantizer (pngquant 3.0.3) and one WebP and AVIF encoder. Only one already-optimized sample, derived from one screenshot, with every step run once. No real production design files. No timing. The exact percentages will move with your images and your tools.
If you own a pipeline that touches PNGs on every upload, the cheap experiment is to run it twice on its own output and compare the byte counts. That one diff will show you which of your steps are idempotent and which are not.