pngquant is a command-line utility and a library for converting 24/32-bit PNG images to paletted (8-bit) PNGs.
The conversion reduces file sizes significantly (often as much as 70%) and preserves full alpha transparency. Generated images are compatible with all modern web browsers, and have better fallback in IE6 than 24-bit PNGs.
NB: don't use version 1.0 of
pngquant. There is massive difference in quality and compression between recent versions and the obsolete version that can still be found in many Linux distributions and GUIs. Use
pngquant -v to check.
Current version is 1.8.3 (changelog, feed, all releases).
pngquantand other tools.
sudo dpkg -i pngquant_*.deb)
rpm -ivp pngquant-1.8.1*.rpm)
dpkg-source -x pngquant_*.dsc; cd pngquant-*; debuild -us -uc)
Written in C99. Available under a BSD-like license. The project is hosted on GitHub.
git clone git://github.com/pornel/improved-pngquant.git
pngquant 256 *.png(recursive processing)
… | pngquant 16 | …
To further reduce file size use optipng or ImageOptim.
pngquant -h for full list of options.
Set custom extension for output filename. By default
-fs8.png is used.
pngquant to use the least amount of colors required to meet or exceed the max quality. If conversion results in quality below the min quality the image won't be saved (if outputting to stdout, 24-bit original will be output) and
pngquant will exit with status code 99.
pngquant --quality=65-80 image.png
Speed/quality trade-off from 1 (brute-force) to 10 (fastest). The default is 3. Speed 10 has 5% lower quality, but is 8 times faster than the default.
Workaround for IE6, which only displays fully opaque pixels.
pngquant will make almost-opaque pixels fully opaque and will avoid creating new transparent colors.
Print version information to stdout.
Read image from stdin and send result to stdout.
Stops processing of arguments. This allows use of file names that start with
-. If you're using
pngquant in a script, it's advisable to put this before file names:
pngquant $OPTIONS -- "$FILE"
pngquant uses modified version of Median Cut quantization algorithm and additional techniques to mitigate deficiencies of Median Cut.
Instead of splitting boxes with largest volume or number of colors, boxes are selected to minimize variance from their median value.
Histogram is built with addition of a basic perception model, which gives less weight to noisy areas of the image.
To improve color further, histogram is adjusted in a process similar to gradient descent (Median Cut is repeated many times with more weight on poorly represented colors).
Finally, colors are corrected using Voronoi iteration, which guarantees locally optimal palette.
pngquant works in premultiplied alpha color space to give less weight to transparent colors.
When remapping, error diffusion is applied only to areas where several neighboring pixels quantize to the same value, and which are not edges. This avoids adding noise to areas which have high visual quality without dithering.