PNG (short for "Portable Network Graphics") is a raster image format designed to replace limitations of GIF image format in terms of data compression and color precision. The size of a PNG image file can vary significantly based on several factors including color depth, interlacing, precompression filter, compressor used, etc.
In this tutorial, I will describe how to compress a PNG image file losslessly on Linux.
optipng is a Linux command-line utility that performs various optimizations on PNG image files, including size compression, metadata recovery and integrity checks, etc. Using optipng, you can compress png files losslessly.
To install optipng on Ubuntu or Debian:
To install optipng on CentOS or RHEL, first set up Repoforge repository on your system, and then run:
To install optipng on Fedora, simply run:
Once you have installed optipng, you can compress a PNG image file as follows.
optipng -o 7 input.png OptiPNG 0.6.4: Advanced PNG optimizer. Copyright (C) 2001-2010 Cosmin Truta. ** Processing: input.png 1600x1200 pixels, 4x8 bits/pixel, RGB+alpha Reducing image to 3x8 bits/pixel, RGB Input IDAT size = 608523 bytes Input file size = 609539 bytes Trying: zc = 9 zm = 9 zs = 0 f = 0 IDAT size = 523671 zc = 9 zm = 8 zs = 0 f = 0 IDAT size = 523639 zc = 9 zm = 9 zs = 0 f = 4 IDAT size = 523579 Selecting parameters: zc = 9 zm = 9 zs = 0 f = 4 IDAT size = 523579 Output IDAT size = 523579 bytes (84944 bytes decrease) Output file size = 523707 bytes (85832 bytes = 14.08% decrease)
In the above, "-o" option specifies the optimization level (0 to 7). The higher the level is, the more trials optipng will run through.
Subscribe to Xmodulo
Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.