Create square image thumbnail using ImageMagick and Ruby on Rails

Here’s a quick example of why scripting languages (and Ruby) are really cool. I had an image upload facility of a Rails app that I wanted to generate square thumbnails for. After a quick google and with the help of a couple of clever people I had the solution in a matter of minutes.

def create_thumbnail(temp, target)
    system("convert #{temp} -thumbnail x400 -resize '400x<' -resize 50% -gravity center -crop 200x200+0+0 +repage #{target}")
  end

Perfect!

References

Teaching Image Magick whos boss (Justin Blanton)

Outsourcing the performance-intensive functions (David Heinemeier Hansson)


About this entry