Optimize PNG on Windows 7
Four years ago I wrote about how to optimise PNGs for the Web and I included a little registry hack to make it easy to optimise a whole folder of PNGs on Windows XP. Here’s some updated instructions that will work on Windows 7.
To follow these instructions, you’ll need full Administrator privileges and may need to turn off UAC. I assume you’re already familiar with RegEdit and have no qualms rooting around in it :-) Disclaimer as always: Backup your registry before messing in here!
- First, grab a copy of the PNGCrush Win executable and copy it to your Windows folder.
- Open Regedit and navigate to the following key: HKEY_CLASSES_ROOT\Directory\shell.
- Right click “shell” and select “New -> Key” and name the new key “PNGcrush”.
- With “PNGcrush” selected, double click the “Default” icon in the right hand window pane and enter a new value in the popup. This will be the name of the function as it appears on the context-sensitive menu in Windows explorer when you right click a folder. Mine is simply called “PNG Crush”.
- Click OK, then right click the “crush” entry again in the left hand pane.
- Select “New -> Key” again and name the new key “command”.
- With “command” selected, double click the Default icon and enter
this command into the popup box:
cmd.exe /s /k "@pushd %1 && pngcrush.exe -fix -rem allb -rem gAMA -e .new *.png && del *.png && ren *.new *.png && exit"
- That’s it! Now in Windows Explorer you can right-click any folder that contains PNGs, select “PNG Crush” and all the PNGs will be optimised.
Two notes about this technique:
- It won’t do any format, bit depth or masking conversions, so if you need to create 8-bit Alpha PNGs for example, you’ll need to use a tool such as TinyPNG.
- It won’t necessarily make the smallest possible file out of your PNG, as it’s designed for speed, rather than maximum compression.