how to optimize PNG losslessly for web

last modified on 9 July 2019, by Cédric Louvrier

pingo could do some lossless image transformations for web to decrease the filesize. this is done without any loss regarding how the image is rendered once fully decoded. this can be done like this:

N: from 0 to 9 — 0: fast and good compression — 9: slow, but better compression
pingo -sN target

better image data transformations

pingo is able to process files using an adaptive image data transformations which do not affect the rendered image data. the following sample shows that even with at fast level, it could beat other trials by speed and size, including brute-force

original file: tweet-book-write.png (56.07 KB): optimization comparison of with ZopfliPNG and pingo
ZopfliPNG --lossy_transparent ZopfliPNG (brute) pingo -s1
tweeter book writing - ZopfliPNG tweeter book writing - ZopfliPNG (brute) tweeter book writing - pingo
52.35 KB (2.65s) 52.21 KB (562.01s) 52.08 KB (0.35s)
original file: box.png (30.40 KB): optimization comparison of with ZopfliPNG and pingo
ZopfliPNG --lossy_transparent ZopfliPNG (brute) pingo -s1
brown box - ZopfliPNG brown box - ZopfliPNG (brute) brown box - pingo
20.17 KB (0.97s) 20.16 KB (56.26s) 16.78 KB (0.06s)

non-rendered image data

a PNG file can store data which could not be rendered by browsers or viewers. some PNG chunks or image data where alpha is fully transparent (0) should not be rendered. a tool could remove meta-data from PNG or transform image data if you plan to use the PNG for web, because it often offers great filesize reduction

RGB data
original file: rose.png (70 KB): remove non-rendered image data
OptiPNG -o7 PNGOUT pingo -s1
rose - OptiPNG rose rose - pingo
69.92 KB (3.49s) no savings 31.95 KB (0.13s)
non-critical chunks

by default, pingo should remove some non-critical chunks. in the following sample, the iTXt chunk does not affect the image rendering and is much larger than the image data itself

original file: bear-yellow-itxt.png (98.34 KB): remove non-critical chunks
original pingo -s0
bear yellow - original bear yellow - original
98.34 KB 18.36 KB (0.07s)

chunks which affect how the image is rendered

PNG can store some additionnal chunks like iCCP, gAMA, etc. which could affect how the image is rendered over the image data decoding. in this case, you could convert PNG to sRGB colour space (lossy), or simply preserve those chunks

pingo should preserve by default ICC profiles if the size is 600 bytes or less. if the iCCP chunk is larger and you want to keep it, you should set the -strip=1 flag, according to the following table:

pingo -sN -strip=N target
pingo -strip=N
option what it does
-strip=1 keep ICC profile (whatever the size)
-strip=2 (or default) keep ICC profile (only if < 600 bytes)
-strip=3 do not keep ICC profile