One of the ways to speed up your site and save bandwidth is to optimize your images. You can often halve an image’s size without losing (much) quality. Many photo editors may give you this option, but it’s a slow manual process. What we really need is a way to automate this so that every time we deploy changes we can optimize in one step.
You’ll need 2 tools (and Cygwin if you’re on Windows) to pull this off:
- Download and setup Groovy
- Grab ImageMagick and install it
You can do a LOT with ImageMagick. Here’s a command-line reference for it.
Compressing images the Groovy way
Here is a Groovy script I wrote for that purpose. It would be even cooler to use something like this in a Gant build:
Tweak this to your liking to suit your needs. You can substitute your favorite command-line image editor if you like. Groovy makes it easy!
Run it by typing this on your command-line:
groovy src/groovy/CompressImages images/ 60
What do you think? Useful? Share!