[Image-SIG] Quantization of PNG images

Jesper Larsen jesper.webmail at gmail.com
Mon May 18 10:15:30 CEST 2009

Hi image-sig,
I am producing some png images for a web application. Some of the
images are cached and reused for other requests. I am using matplotlib
to produce the images. Unfortunately the images are quite large (up to
~300 kb). I therefore tried using the Linux utilities pngcrush and
pngnq for compressing the images. pngnq gave by far the best results
(~300 kb -> ~90 kb in 0.4-0.5 seconds on my laptop; combining the two
tools did not yield further improvements). It reduces the color depth
to 8 bits (from 24) without any apparent image quality problems using
color quantization (http://en.wikipedia.org/wiki/Color_quantization).

Is it possible to do this in PIL directly or will I have to code it
myself? At present I am considering just calling pngnq from my Python
code but I would rather not do that.

Another thing is that for performance reasons I might want later to
reuse the colormap (since the image colors are pretty much the same).
Neither pngnq nor pngquant (which pngnq is based on) supports this

Best regards,

(Thanks to Jouni K. Seppänen on the matplotlib mailing list for
suggesting looking at PIL for this)

More information about the Image-SIG mailing list