Easily reduce and optimize PNG images

Making things run fast is essential and reducing images to their minimal is really important.

Here is a little script I made today. For Plurk it has chopped off 80KB on profile views (due to our many images).

In order to use this script you must download OptiPNG. After you have installed OptiPNG, you can fire off this Python script:

import os, sys

def png_optimize(dir):
    findcmd = 'find %s -name "*.png" -print' % dir

    count = 0
    for f in os.popen(findcmd).readlines():
        count += 1
        file = str(f[:-1])
        os.popen('optipng %s' % file)
        print 'optimized %s' % file
    print "Optimized %d .png files" % count

if __name__ == "__main__":
    png_optimize(".")

The script searches after all PNG's in the current working directory and optimizes them. It's quite effective, most of our PNG images were optimized more than 50% (without any quality loss).

Code · Plurk · Tips 16. Aug 2008
© Amir Salihefendic. Powered by Skeletonz.