Juicy lil' bytes

How to Maximize PNG Image Compression With OptiPNG

OptiPNG is an open source, lossless PNG file compression application that performs well on compression testing. Here’s how you maximize your compression ratios with it.


OptiPNG is an open source application that is available on SourceForge. Documentation in a pdf format is available here.

On *nix systems, you can build and install it with the standard set of autotools commands:

make && sudo make install

Windows users get an .exe binary in the zip archive on the download page.

PNG Compression with OptiPNG

I have been testing a few lossless PNG compression applications with PNG files that I generated from both Photoshop CS6 and Pixelmator. These included files ranging from 1.2 kB to 1.5 MB that were saved in each application’s default RGB + alpha 8 bit format, as well as in the Photoshop “Save for web” compressed format. Generally speaking, the best compression / time command based upon my testing on a MacBook Pro (2.4 GHz Intel Core i7, 8GB RAM) is:

Near Maximal Compression + Fast

optipng -o2 -strip all <image.png>

This command strips all meta data and compresses the image data. It led to a 18% decrease in the default Pixelmator PNG size and a 95% decrease in the default Photoshop PNG size.

If you want to maximize your compression ratio with a fairly significant time tradeoff at larger file sizes, you can use the -o7 switch.

Maximal Compression + Not So Fast (for Large File Sizes)

optipng -o7 -strip all <image.png>

In the files that I tested, this led to a modest ~1 percentage point gain, though your results may vary depending upon the complexity of your image.

The Photoshop CS6 “Save for web” PNG-8 compression format with 256 colors, bicubic sampling, no metadata, & diffusion dither resulted in a file that had near maximal compression by current standards. On a 100x100 pixel image, I was only able to wring out another 2.4% of the original file size with the latter optipng command.

File Size by OptiPNG Switch

Here are the data for the default 100x100px Photoshop PNG file. image

Learn More About PNG Compression

Want more background? This guide by Cosmin Truţa is a good resource.