Last week I had a little hack at building a quick ‘n’ dirty extension to get image_optim better integrated into Middleman.

Let’s face it; serving big, bloated images is for chumps, that’s why the image_optim tool is really awesome. However, I wanted a way of getting Middleman to automate running it for me, and better integrate it into the whole middleman --build workflow.


It is already pretty easy to get image_optim to process a bunch of files just by using some bash in a deploy script — you can just have the deploy script run it after it has finished building markup & assets via middleman build.

For example;

image_optim -r $(find ./build -type f -iname '*.png' -o -iname '*.jpg' -o -iname '*.gif')

…but this doesn’t really work too well when you are using other tools like middleman-s3_sync, middleman-s3_redirect, or middleman-cloudfront, which are chained to run after a middleman build — not much point uploading your images before they have been run through image_optim!

So I made (the imaginatively titled) middleman-imageoptim gem! It integrates into the Middleman build process so will just be run as a part of constructing, and then deploying the rest of your site.

Anyway, if big, dirty, sweaty images aren’t your thing and you use Middleman I would love to know what you think!

Go install image_optim, stick the following in your Gemfile;

gem 'middleman-imageoptim', '~> 0.0.4'

…activate the extension (there are lots of options you can play with too — check out the repo);

activate :image_optim

…and let me know what you think!