Optimizing PNG Compression

Posted by reto on 06 January, 2008 22:49

While creating some screenshots and saving them with the GIMP, I felt the PNG files were rather big and I was looking for a tool that would do better compression. PNG files usually are saved with lossless compression, not like JPEG files, where you always loose some image information with every percent of higher compression.

As usual googling helped and I quickly found the two very handy command line tools pngcrush and pngnq. pngcrush is an optimizer for PNG files and tries to create optimized PNG files without compromising their quality (e.g. as small as possible but lossless). pngnq on the other hand creates quantized PNG images, which means that the compression is not lossless anymore.

Both tools are available for various platforms such as Linux, Windows and Mac. As usual the  ubuntu-way debian-way is straight forward and as easy as:

$ apt-get install pngnq pngcrush

The screenshots below illustrate the different qualities and file sizes to expect with default settings on all three tools. In some occasions individual tweaking may result in even better results, but the default settings work for me just fine in this case.

Summary on a 957x957 pixel screenshot:
Original (The GIMP, level 9): ~287 kb
Processed by pngcrush: ~284kb
Processed by pngnq: ~82kb

Screenshot saved with GIMP 2.4.2, compression level 9 (default/maximum) ~287kb:
[missing screen]*

Screenshot saved with GIMP and optimized with pngcrush ~284kb:
[missing screen]*

Screenshot saved with GIMP and quantized with pngnq ~82kb:
[missing screen]*

Conclusion: The GIMP has a rather effizient compression on level 9 as pngcrush could not achieve much better results (only about 1% reduced filesize). But you are limited to use lossless compression with the GIMP. So using pngnq may be usefull in some situations. The filesize reduction is usually significant (up to 70% as compared to the output of the GIMP).

* Edit Oct. 2011: sorry, pictures got lost in virtual space or were eaten up by hungry crawlers.

Information and Links

Join the fray by commenting, tracking what others have to say, or linking to it from your blog.


Related Articles
Speed up your Website