Pngnq is a tool for quantizing PNG images in RGBA format.

Pngnq is an adaptation by Stuart Coyle of Greg Roelf's pnqquant using Anthony Dekker's neuquant algorithm.

Version 1.0 includes improvements made by porneL:

The neuquant algorithm uses a neural network to optimise the color map selection. This is fast and quite accurate, giving good results on many types of images.

Why another quantizer?

Pngnq exists because I needed a lot (several thousand) of png images in RGBA format to be quantized. After some searching, the only tool I could find that worked for RGBA was pngquant. I tried pngquant but found that the median cut algorithm that it uses, with or without dithering, gave inferior looking results to the neuquant algorithm. You can see the difference demonstrated on the neuquant page.

Pngnq was written to fulfill the specific needs of the small project I was working on, and as such does not have all the functionality one could want. It is developing though, I have recently (June 2006) come back to it to add functionality and make it more useful in various situations. It will stay as a command line quantization tool rather than evolve into a full compression process as I'd rather keep the program as performing one specific function. If optimal compression is needed one can use something like pngcrush after quantization.

I use Greg Roelf's png reading and writing code unchanged for the most part. The pngnq source code includes neuquant32, which is an extension of Anthony Dekker's neuquant. This has been modified to allow it to handle 4 channels of pixel data and to vary the number of colors quantized to. Thanks go to these people for developing such useful code and making it open source.

Comparisons with other quantizers.


The quantizer is fairly slow compared to median cut or octree methods. It is most certainly faster than Spatial Quantization techniques. It is limited mostly to off-line uses rather than real time image delivery. Even so, I am sure Moore's Law will make that statement false at some short time in the future. I've not run any comprehensive speed comparisons with other algorithms.

The speed of the algorithm can be increased by increasing the sample factor ( -s option ). The sample factor determines what fraction of pixels are examined by the algorithm.


Pngnq seems to work best when quantizing to a fairly large number of colors (>=64). This mainly a result of the visible edges due to the lack of dithering. The amount of compression of images gained is determined largely by the level of quantization. Using a tool like pngcrush to further process these images results in slightly smaller images than with methods that dither the image. This is probably due to the lack of high frequency data in the non-dithered images.

To quantize and compress an image, for example image.png, with the compressed output as smallimage.png, I do this:

pngnq -n 256 image.png && pngcrush image-nq8.png smallimage.png

This usually results in a greater than 50% compression with a small loss of detail.


I have run tests on the measured difference between quantized and unquantized images using pngnq, pngquant and scolorq. The error measure used is the Euclidian distance in RGBA space between pixels in the quantized and unquantized images. These have shown that the neuquant algorithm performs better than the median cut for most images, I suspect though that each reach close to the . Since reading Puzicha et. al. and running some tests, I have decided that this may not be the best measure of percieved difference in images. A better test of “percieved” image distance is in development.

I've run some comparisons here: Sample quantized images.

I have tested pngnq with these test images. No errors occur except in the deliberately corrupt test images, in which case the image loading correctly reports the corrupt image and the quantizer carries on as normal.

Things that pngnq needs work on:

I want to change the error measure to use CIE u'v' color space and see if results are visually better. Or perhaps add a perception filter model.

Limited image input formats. I am not doing much checking on the image pixel depth etc.


There seem to be few image editing programs that correctly deal with paletted RGBA png images. This is a pity since the alpha channel is so useful on the web, when browsers support it correctly. The only other quantization program I have found that does this is pngquant.

Future projects:



I can be contacted via the my sourceforge page.

Bug reports and feature requests should be directed at the appropriate tracker page.

I also will be keeping an eye on the forum for anyone requiring help and advice.


Pngnq is now hosted on, for all binaries go to pngnq downloads

For the current source code see the svn repository.