Skip to content


Shrinking your PNGs as much as possible

PNG is a lossless picture compression format which beats GIF (and probably TIFF, too) in almost every aspect.
However, a strange (well, I find it strange at least) thing with this format is that you’ll get various size reductions depending on the software you use to perform the PNG compression. Thus, naturally, some pieces of software were created specifically to shrink PNG files as much as possible. It seems that the main ones are PNGOUT and OptiPNG. The former is partially freeware (its command line version is freeware with license restrictions, its GUI version is commercial), while the later is free, as in open source and gratis. Usually, PNGOUT provides better results than OptiPNG, but this is not always the case.
So… let’s use both! We’ll do that on Windows, but I suppose it wouldn’t be too hard to do the same on Linux (both programs provide Linux versions). Note that running this will really take a long time. Most particularly, you might want to change OptiPNG flags to just -o7 (4x fewer tries and probably just as good) or maybe -o5 (22.5x fewer tries but maybe not as good). I chose the most extreme settings because I considered the case where you want to finalize the pictures before placing them on a website (so compression time doesn’t really matter compared to the slightest size improvement).

  • get the executables (here are the links again: PNGOUTOptiPNG)
  • optional but will allow a simpler use: add them to your PATH (System properties -> Environment variables -> System variables then edit Path to add the folder where you placed those executables)
  • create a batch file (create a text file with a .bat extension) with the following content:
    for %%i in (*.png) do pngout "%%i" /y
    for %%i in (*.png) do optipng -zc1-9 -zm1-9 -zs0-3 -f0-5 "%%i"

    (or you can just download it)

  • now to optimize all PNGs in a folder, you can just place that batch file in the folder and run it. It will overwrite current PNG files (except if it doesn’t manage to compress them better than they already are) with their optimized versions.

If you just want to run the commands straight from the command line instead of saving them as a batch first, replace the “double %” by “single %”.

A final note: I noticed that PNGOUT seems to provide impressive result on PNGs with few colors. It notably managed to reduce the Wiki4Games logo from 5941 bytes to 3496 (-42%), by optimizing it in 256 colors.

Some (incomplete) test results:
I ran the thing on 6 PNG pictures. In 3 cases PNGOUT did better than OptiPNG, in 3 cases OptiPNG did better, and notably on a picture it did a lot better: 309,927 bytes vs 423,146 (original picture was 431,161 bytes) (on the other pictures the difference was quite small, barely a few percents).
I also ran it on the 31 PNG pictures I currently have in http://img.patheticcockroach.com/01/. The combination of PNGOUT + OptiPNG managed to optimize 30 pictures out of those 31. Note that I didn’t analyze intermediate results (after PNGOUT but before OptiPNG), all I have is the global result: 11 pictures were reduced only by PNGOUT, the 19 other pictures were maybe reduced by PNGOUT but also further reduced by OptiPNG. In total, over 29 of those pictures (for 2 of them I didn’t keep the unoptimized copy) including the one that couldn’t be optimized, the size gained by optimization was 21.4% (original size: 1,281,746 bytes; optimized size: 1,007,154 bytes).
In conclusion, to get the best possible size, it seems really useful to run both programs.

Posted in software, web development.


0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.

Sorry about the CAPTCHA that requires JS. If you really don't want to enable JS and still want to comment, you can send me your comment via e-mail and I'll post it for you.

Please solve the CAPTCHA below in order to fight spamWordPress CAPTCHA