Lossy PNG optimization
if you have to optimize PNG files for Web, you could use a lossy way. you should avoid to use your image editor or embedded version of old tools for that: be sure to run the latest updated tools. you have to test and see or try pingo for auto lossy.
note that those files generated by tools presented here could be compressed more by some other PNG compressors, like ECT or PNGOUT. TruePNG or pingo are also useful on paletted images, since they should try to order the colors in palette automatically.
Color quantization (to palette mode)
the first trial seems to be a bit agressive, but it is also the most efficient. it consists to reduce the number of colors to 256 (or less). it will convert the PNG to paletted mode. if this decrease quality too much, there are few other methods you should try.
pngquant v2 is a great solution to convert true color images to paletted mode, but be sure you are using the latest version (at least 2.8.0): do not use the embedded version you can find in some distributions. it uses combination of median-cut algorithm and others few tricks that should preserve quality. it can use a custom floyd-steinberg dithering to have less noise on some images.
pngquant--speed 1 image.png
|original (18162 colors)||pngquant (256 colors)|
|61,4 KB||18,8 KB|
pngquant is one of the best tools to preserve quality, as you can see in this sample. the quality is well preserved and reduction is usually 50-70% of the original size. on flat simple images, you can set
--nofs option that should disable the dithering and decrease even more the filesize.
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. where pngquant meets some limitations, a human check will let you to convert images with more visual perception quality.
|Original (22774 colors)||pngquant --speed 1 --nofs 256||Color Quantizer|
|76,9 KB||20,9 KB||20,1 KB|
a color quantizer tool like Color Quantizer can be also used to do the same operation but with more colors. if user picks more than 256 colors, the PNG will not be converted to paletted mode. this often increases filesize but should preserve quality. note that Color Quantizer can batch this.
|original (31896 colors)||Color Quantizer (256 colors)||Color Quantizer (1024 colors)|
|90,6 KB||21,2 KB||36,2 KB|
Lossy averaging filter
there is also another lossy method that makes data more compressible especially for a filter, also called
lossy filtering. unlike quantization or posterization, this does not reduce the number of colors. it should process faster than color quantization and quality/size compromise is nice enought to be considered.
Median Cut Posterizer
Median Cut Posterizer is not just a tool that can use posterization on PNG files. you can use a blurizer that transforms data using a lossy average filter. it makes image more compressible by making it more predictable for PNG's diagonal average prediction filter.
posterize-b -q 90 image.png image-lossy.png
|90,6 KB||57,4 KB|
TruePNG can do the same job with more control : you can set various settings (filter, method, level) that let you to do trials and compare results. most of the time, it should be more efficient to use the average filtering that could give nice quality - size compromise.
truepng-f3 -l image.png
|90,6 KB||58,5 KB|
a posterization should be useful to decrease the number of unique colors in the image. this way could be, however, less efficient than color quantization or
lossy filtering because of the quality/size compromise which is worst. this can be done with an image editor, but some tools are actually better.
Median Cut Posterizer
Median Cut Posterizer can do some posterization by tyring to pick levels using median-cut and Voronoi iteration. this will decrease the number of colors in the image but could badly impact quality with some samples, or will not decrease filesize significantly.
posterize-d -q 90 image.png image-lossy.png
|original||posterization (quality 50)|
|90,6 KB||65,1 KB|
pingo (auto lossy)
pingo 0.6x could try to select the optimal speed/quality tradeoff, by choosing itself the specifications. it could use most of methods described here and more (like JPG conversion) without comparisons or trials. this can be done like this:
if you do not provide any options, pingo will try to optimize all PNG/JPG with lossy or lossless optimization automatically. be aware of some points however:
- pingo could overwrite or convert without any notifications or backup some PNG/JPG files
- it should process all subdirectories
- it is not guaranteed that it will pick the optimal settings
- always use this tool on test files
like the precedent tools, pingo could use its own settings with lossy paletted or average filter instead of choosing by itself:
- -palette reduces the number of colors below 257, and force the output to be paletted
- -lossyfilter uses the lossy filter transformation
- those options can be combined with -sN to optimize or compress more
|pngquant||multi - color quantizer that converts to palette mode|
|Color Quantizer||windows - gui that does color quantization with advanced settings|
|ImageAlpha||mac - gui that uses pngquant and Median Cut Posterizer|
|Median Cut Posterizer||multi - posterizer and blurizer to optimize true colors PNG|
|TruePNG||windows - an advanced PNG optimizer (see also TruePNG tutorial)|
|pingo||windows - another PNG/JPG optimizer with lossless or lossy compression|