HazelI use the Quicksilver “Capture Region” tool alot on my Macbook to save images for use here & on VizWorld.com, and it does a great job of saving PNG’s on my Desktop.  However, I’ve recently noticed that the images could be made alot smaller (and then be alot easier on Bandwidth once I upload them to my website) if I optimized them first.  Of course, that’s easy to do automatically with WordPress’s “Optimize Image” plugin, but sometimes (often, actually) a JPG would be smaller than a PNG.

Well, Quicksilver saves these images on my Desktop.  I setup Hazel to monitor my desktop for PNG files, and told it to run the following script:


#!/bin/tcsh
echo Converting "$1" to "${1:r}.jpg"
/opt/local/bin/optipng -o7 "$1"
/opt/local/bin/convert "$1" "${1:r}.jpg"
/opt/local/bin/jhead -purejpg "${1:r}.jpg"
if ( (-Z "$1") > (-Z "${1:r}.jpg") ) then
echo "$1" is Bigger.
rm "$1"
else
echo "${1:r}".jpg is Bigger
rm "${1:r}.jpg"
endif

So this optimizes the PNG, then converts it to JPG and optimizes that.  Finally, it compares the resulting filesizes and deletes the larger.  It takes a few seconds to run, but now I can save the screenshot, and by the time I have the post ready for it in WordPress, I can just pick the only file remaining and rest assured that it’s the smallest.

PS: If you want to try this, then you’ll need to install MacPorts and then install ImageMagick (which takes a long time), OptiPNG, and jhead.