webdechunkpng – remove non-essential “chunks” from PNGs

Some friends of mine had a problem, they had to go through dozens/a few hundreds of PNGs re-saving them removing all non-essential "chunks", where a “chunk” is a part of a PNG's internal structure containing information, compareable to the tags of TIFFs. However, some of those chunks, put there by programs like Photoshop & Co, did not agree with some browsers and messed up the way the final website was to be rendered – those chunks had to go.

Their "solution" was to start a virtual machine with Windows, and run a GUI-programm that lets you select and remove those chunks, taking a few minutes and a lot of concentration for each single PNG… I am not joking.

It took me not even half an hour writing and testing the following shell-script, that automatically and efficiently does the same thing making use of the netpbm software suite.

The idea is to convert each PNG into another format and back, losing everything but essential image data in the process – it worked perfectly, earning me a whole day of my friends' eternal gratitude.

PS: The script keeps the alpha-channel.