Image optimization using Yahoo! Smush.it

Apr 25, 2012

I´ve recently looked more into various quick-wins and minor optimization techniques — and in that search I came across Yahoo!´s Smush.it service for (automatically) optimizing image.

Smush.it is a webservice provided by the Yahoo! Developer Network. Yahoo! describes the service like this:

Smush.it uses optimization techniques specific to image format to remove unnecessary bytes from image files. It is a "lossless" tool, which means it optimizes the images without changing their look or visual quality. After Smush.it runs on a web page it reports how many bytes would be saved by optimizing the page's images and provides a downloadable zip file with the minimized image files.

So, we can use the service as a paste/upload-click-and-download service to process a single image, but what is even more interesting is that it´s actually available via scripting ... and just as great — it will give you a JSON-result when done :)

Using Smush.it programmatically

The Smush.it service can be called using the following URL:

http://www.smushit.com/ysmush.it/ws.php?img=urlencodeed-image-source

Go ahead, try it: http://www.smushit.com/ysmush.it/ws.php?img=http://l.yimg.com/a/i/ydn/ydn-logo.gif

I can´t really remember where I found this tip, but it immediatly gave me an idea — I´ve now setup a few cronjobs for automatically optimizing images on my blog.

  1. First job crawls a few predefined folders and adds images to a database table (if they are not already present).
  2. Second job simply crunch through the table and processes the found images using the URL above. This gives me a JSON-result from which I get an URL to an optimized version of my image, that I simple download and replace the old version with.

Tadahh ... This might not sound like much, but some of my images are being reduced up to 50% of their original size, so I´m a happy camper for now :)

Comments

comments powered by Disqus