Optimising PNG images for the web

Stoyan Stefanov has recently written an interesting series of articles on optimising image files for the web. In his latest article he shows how to use pngcrush to safely shrink your files, one file at a time:

$ pngcrush -rem alla -brute -reduce src.png dest.png

This evening I found myself wanting to repeat that command for all the PNG files in my current directory, and then (having reviewed the new images) overwrite the originals. Rather than do it by hand I did what all pragmatic programmers do these days, and wrote a script. Here it is in action:

$ pngcrushall 
Crushing test4012.png ... ok
Crushing test9200a.png ... ok
Crushing test9200b.png ... ok
Overwrite original files? (y/N) y
Overwriting test4012.png ... ok
Overwriting test9200a.png ... ok
Overwriting test9200b.png ... ok

You can get it from github -- download pngcrushall.

Obviously you'll need to install pngcrush too. On a Mac this is pretty easy with homebrew:

$ brew install pngcrush

I love feedback and questions — please feel free to get in touch on Mastodon or Twitter, or leave a comment.