From: Joe Van Dyk Date: 2005-08-05T03:46:16+09:00 Subject: Fwd: [Rails] Fwd: RMagick problem On 8/4/05, rails@lists.rubyonrails.org wrote: > Hi ! > > Joe Van Dyk said the following on 2005-08-03 22:30: > > On 8/3/05, Joe Van Dyk wrote: > > # Resizes a Magick image to an exact size, keeping the same aspect ratio > > def resize_image_to_exact_size(width, height) > > new_aspect_ratio = width.to_f / height.to_f > > old_aspect_ratio = @magick_image.columns.to_f / @magick_image.rows.to_f > > > > if old_aspect_ratio < new_aspect_ratio > > # Image too tall, geometry string should restrict height > > geometry_string = "#{width}" > > else > > # Image too wide or just right, geometry string should > > # restrict width > > geometry_string = "x#{height}" > > end > > There's no need to do that. RMagick's documentation says about geometry > strings: > > "By default, the width and height are maximum values. That is, the image > is expanded or contracted to fit the width and height value while > maintaining the aspect ratio of the image." > > http://studio.imagemagick.org/RMagick/doc/imusage.html#geometry > > Hope that helps ! > Fran�ois If you look again, you'll notice I have two resize methods. One resize method that just resizes an image, keeping the same aspect ratio. And then the resize_to_exact_size method that resizes an image to an exact size. See http://jerrymahan.com/contents/show/front . You'll notice that those thumbnails on the right are all the exact same size (same height and width). But the original images all had differently aspect ratios. To make sure that all the thumbnails are the exact same size, I had to do some additional calculations. (or so it appeared to me)