Compress png files on Debian with optipng

Valic —  December 14, 2012 — Leave a comment

PNG “Portable Network Graphics”  is a image format designed to replace limitations of GIF image format in terms of data compression and color precision. The sizes of  PNGs image files can vary based on several factors like color depth , precompression filter, etc.

Optipng is a Linux command line script that performs multiple optimizations on PNG image files including size compression, integrity checks and more.
I will show you how to use and install Optipng on Debian Linux.

Step1. Install Optipng on Debian:

apt-get install optipng

Step2. Now you can compress a PNG image using the following command:

optipng -o 7 image.png

You can choose between 7 levels of compression from 0 to 7. The 7 level is very slow.

Now I will show you how to compress all images on your server:
First search all PNG images and put them into a list.

find /home/www/ -path -prune -o -name "*.png" > pngfiles.list

Now compress all images from the list

for images in `cat pngfiles.list`; do optipng -o7 -quiet -preserve "$images"; done

-quiet - is quiet mode
-preserve - preserve file attributes if possible


Posts Twitter Facebook

Editor in Chief at Debian-Tutorials, Linux enthusiast.

No Comments

Be the first to start the conversation.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.