Monday, October 30, 2006

Some neat tips on Creating image thumbnails with ImageMagick.

I do this inside Ruby on Rails with RMagick. RMagick is sometimes a bit "interesting" to install, but do perservere, because you can then do some really neat things with it, like:


ox = image.columns
oy = image.rows
if (ox < oy)
nx = 200
ny = (oy * (200.0 / ox)).to_i
else
nx = (ox * (150.0 / oy)).to_i
ny = 150
end
image.sample!(nx,ny)
image.crop_resized!(200,150)


This little code snippet will resize your images to be 200x150, and will recenter them if their aspect ratio is too long.