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.
On *nix systems, you can build and install it with the standard set of autotools commands:
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
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
Maximal Compression + Not So Fast (for Large File Sizes)
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.
Learn More About PNG Compression
Want more background? This guide by Cosmin Truţa is a good resource.