lossy PNG optimization

unlike JPEG, PNG is lossless format. however, you can use some lossy pre-processing on the image data — to make it more compressible for PNG compression by reducing image quality. this can be done by pingo with various methods, from very strong to barely possible to detect with human eyes

color quantization (to paletted)

it is one of the most known method but also one of the most efficient regarding the filesize. it converts the image data to 256 colors maximum so PNG can be encoded as paletted. you could use pngquant v2 for this — be sure you are using the latest version, not the embedded one in your distribution — or pingo, like this:

pingo -pngpalette image.png

quality and compression

you could also set a quality factor to the -pngpalette (from 0 = low quality, to 100 = best) or the compression level with -sN. if you set a high compression level, pingo could re-order the entries in the palette in a way to improve how the data could be encoded

pingo -pngpalette=100 -s9 image.png
pingo 0.98.39
original pingo -pngpalette=100 -s9
Rose Rose
18162 colors 256 colors
61,4 KB 17,8 KB

this method as, however, some limitations regarding the number of colors — a paletted PNG can not contain more than 256 colors. even with an accurate algorithm, the image quality could be worse in some case — that can be noticed by human eyes. that is why pingo is offering other way to do lossy

Color quantizer targets image area

Color quantizer is a GUI for Windows that does color quantization with advanced settings. if user selects 256 colors or less, it will produce a paletted PNG. the tool let the user to select more sensible area to give a great control on the quantization

Color Quantizer

Color quantizer let the user to use a mask to protect some sensible area. this requires an human intervention, but it could offer a better compromise between image quality and the filesize

Color Quantizer
Original (22774 colors)pingo -pngpalette=100 -noditheringColor Quantizer (no dithering)
Paint icon with high colors Paint icon with pngquant Paint icon with Color Quantizer
76,9 KB 21,1 KB 20,1 KB
PNG paletted tools
tool usage
Color Quantizer (windows) — an image editor with advanced quantization settings
exoquant-rs (multi) — color quantization library
greedy-palettization (multi) — fast color quantization
pingo (windows, linux) — advanced color quantization and deep optimization
pngnq-s9 (multi) — color quantization using neural network
pngquant (multi) — advanced color quantization using median cut (using libimagequant)
TruePNG (windows) — old implementation of color quantizer

lossy filter

this picks the difference between an RGB value and the one predicted by the filter — and feed the encoder with it, so it makes the data more compressible. this is a fast transformation using the average filter. the quality and the compression could be set like this

pingo -pngfilter=100 -s9 image.png

lossy filter: high quality 100

if the user selects such high quality level, it is barely possible to detect differences by eyes. on the following sample, it could save 72.94 KB

pingo 0.98.39
original pingo -pngfilter=100 -s9
Peach Peach 100 filter s9
quality metrics (original - optimized)
  • DSSIM 2.9.9 (2e6b8ac): 0.00008984
  • butteraugli 22 Jun (832436e): 0.673127
193 KB 120 KB

lossy filter: average quality 50

at this quality level, it could be possible to save 123.59 KB from the original PNG, while preserving an acceptable score for Web

pingo 0.98.39
original pingo -pngfilter=50 -s9
Peach Peach 50 filter s9
quality metrics (original - optimized)
  • DSSIM 2.9.9 (2e6b8ac): 0.00043293
  • butteraugli 22 Jun (832436e): 1.574337
193 KB 69,6 KB

lossy filter: low quality 5

the lower quality in pingo could save 148.32 KB from the original PNG. at such low quality, it could require more control for the visual quality

pingo 0.98.39
original pingo -pngfilter=5 -s9
Peach Peach 5 filter s9
quality metrics (original - optimized)
  • DSSIM 2.9.9 (2e6b8ac): 0.00202700
  • butteraugli 22 Jun (832436e): 3.388240
193 KB 44,9 KB
PNG lossy filter tools
tool usage
lossypng (multi) — implementation of a lossy filter
Median Cut Posterizer (multi) — implementation of posterization or a lossy filter
pingo (windows, linux) — advanced lossy filter and deep optimization
TruePNG (windows) — implementation of lossy filter with control on filter type

color quantization

color quantization does not always mean the conversion to paletted encoding. it is possible to reduce the number of colors in the image data by various ways

fast color reduction

it reduces the number of colors using a fast quantization based on the lossy filter. using this at top quality levels is basically most of the time a near-lossless compression according to metrics, while lower quality could be very aggressive regarding the visual quality

pingo -pngcolor=100 -s9 image.png
pingo 0.98.39
original pingo -pngcolor=100 -s9
Color palette Color palette color 100
-
  • DSSIM 2.9.9 (2e6b8ac): 0.00002155
  • butteraugli 22 Jun (832436e): 0.354679
66,3 KB 54,9 KB
pingo -pngcolor=50 -s9 pingo -pngcolor=5 -s9
Color palette Color palette color 100
  • DSSIM 2.9.9 (2e6b8ac): 0.00010067
  • butteraugli 22 Jun (832436e): 0.990995
  • DSSIM 2.9.9 (2e6b8ac): 0.00057391
  • butteraugli 22 Jun (832436e): 1.690902
44 KB 34,1 KB

color quantization

Color quantizer 0.7.4.4
original Color quantizer
Lab Mac icon Lab Mac icon
quality metrics (original - optimized)
  • DSSIM 2.9.9 (2e6b8ac): 0.00035193
  • butteraugli 22 Jun (832436e): 2.896830
90,6 KB 42 KB

posterization

Median Cut PNG Posterizer (f5f6765) - Q 60
original Color quantizer
Books Books posterized
quality metrics (original - optimized)
  • DSSIM 2.9.9 (2e6b8ac): 0.00034153
  • butteraugli 22 Jun (832436e): 2.609371
266 KB 142 KB

color quantization (by area)

it reduces the number of colors while keeping the data intact in some area. it let the tool to be a bit less aggressive than the paletted results, but could leave the PNG in non-paletted encoding

pingo -pngrgb=100 -s9 image.png
pingo 0.98.39
original pingo -pngrgb=100 -s9
twitter twitter rgb
quality metrics (original - optimized)
  • DSSIM 2.9.9 (2e6b8ac): 0.00018401
  • butteraugli 22 Jun (832436e): 2.925011
60,2 KB 38,9 KB