I’ve taken the liberty of creating WIN32 builds of Kornel Lesinski’s improved pngnq and improved pngquant open source tools.
pngnq and pngquant reduce the file size of a PNG file by reducing the number of colours, using advanced algorithms which produce the most visually pleasing results given the limitations.
pngnq and pngquant are capable of producing 8-bit (or less) optimised images which still contain alpha transparency (fully varied transparency), something which Photoshop cannot do!
This package contains
- Improved pngnq v0.9 (January 2009)
- Improved pngquant v1.1.1 (January 2009)
- Sample batch files
- Full source code and any original open source licenses
Download pngnq and pngquant command-line tools for Win32 now
What they’re for
pngnq and pngquant perform lossy compression of PNG images, by reducing the number of colours appearing in the image.
There are many different approaches to doing this, and most graphics applications capable of saving to PNG or GIF images have some algorithm for reducing a full colour image down to an image with a limited number of colours. Different algorithms vary in terms of visual quality and processing time. pngnq and pngquant aim for maximum possible visual quality at the expense of a longer processing time (though they are, to some extent, adjustable), and generally do perform better at this than most graphics software.
Choosing a fixed number of colours to best present a full-colour image is not an easy task, and as such there are a few different approaches.
One approach is to use a fixed set of colours regardless of the image; this is the simplest but also the worst quality approach.
Other approaches look at what colours actually appear in the image, and try to cover the most common ones. Of these, there is still a variety of approaches: median-cut based colour selection picks colours by repeatedly calculating median values of the colours in the full-colour image. Other, more ‘perceptual’ approaches try to place more emphasis on areas of the image where small colour variations are more likely to be noticed by the human eye, and less emphasis on ‘busier’ areas of the image. In the best case, such an algorithm can often produce a reduced colour image that is indistinguishable from the original, by the human eye.
pngquant is a general open source tool to do just this, and can accept pretty much any type of PNG image as its input, though a true-colour PNG, optionally with alpha transparency information, is best. It is a command-line tool, and is cross-platform.
pngnq is an alternative to pngquant which uses the neuquant algorithm, a more complex algorithm which aims to produce better results. It is also command-line and cross-platform. It evolved from an earlier version of pngquant.
Kornel Lesinski’s improved pngnq and improved pngquant tools add some further minor improvements to pngnq and pngquant’s algorithms, giving more pleasing (to my eye) results for images with alpha transparency, especially antialiased boundaries for example on icons. They also contain other various fixes, as documented on their respective web pages, which improve results in some edge cases.
You can choose how many colours you want to end up with, with 256 as the maximum; unlike GIF, PNG’s efficiency does not really suffer if you choose a palette size that is not a power of two.
The resulting PNG images will be viewable in all modern browsers, with an important exception: in Internet Explorer 6, images with alpha transparency will not display their partially transparent areas. Thus, the images will look a lot like they have just 1-bit transparency. Some see this as still better than the alternative of not using alpha transparency, or using full-colour images with alpha transparency and having them completely broken on IE6, due to the relatively graceful way these images degrade on IE6. You should test the results in IE6 and decide for yourself, on an image-by-image basis.
Download pngnq and pngquant command-line tools for Win32 now