Compressing PNG file for the web

When using images on the web, it’s impotent to use the smallest file you can for your needs. This doesn’t mean you should use a image that is smaller then the size you wish to display it at, but to optimize it for the web and not send more then is needed.

With this goal, here is a quick way of optimizing all PNG files in a set of directories using optipng.

for a in `find /var/www/wordpress/ |egrep '*.png$'`
    /usr/bin/optipng $a

Don’t worry if you already have some images that are already optimized, optipng will just skip them.