Attachment_fu and portrait vs. landscape pictures

I’m using attachment_fu in some code that allows photo upload. The
attachment_fu Model code generally looks like this:

has_attachment :content_type => :image,
               :storage => :file_system,
               :max_size => 100.kilobytes,
               :resize_to => '146x68>',
               :processor => 'Rmagick'

However, we want to accept uploads in either portrait or landscape
mode, and have them resized appropriately (such as resized to 200x150
if it’s landscape, or 150x200 if it’s portrait). Looking at
attachment_fu, though, it doesn’t look like it will handle that,
resizing to the required dimensions regardless of orientation.

Has anyone done something like this before? Any thoughts? I figure
I can always resize in two directions and then pick the one to
display, but there seems like there’d be a better way to do that.

–Wade

H. Wade M. wrote:

I’m using attachment_fu in some code that allows photo upload. The
attachment_fu Model code generally looks like this:

has_attachment :content_type => :image,
               :storage => :file_system,
               :max_size => 100.kilobytes,
               :resize_to => '146x68>',
               :processor => 'Rmagick'

However, we want to accept uploads in either portrait or landscape
mode, and have them resized appropriately (such as resized to 200x150
if it’s landscape, or 150x200 if it’s portrait). Looking at
attachment_fu, though, it doesn’t look like it will handle that,
resizing to the required dimensions regardless of orientation.

Has anyone done something like this before? Any thoughts? I figure
I can always resize in two directions and then pick the one to
display, but there seems like there’d be a better way to do that.

You didn’t say whether your system was ImageMagick/RMagick based, but if
it is, simply saying :resize_to => “200x200” should work. By default,
ImageMagick maintains the aspect ratio when it resizes.

–Al Evans

On May 9, 2007, at 7:45 PM, Al Evans wrote:

You didn’t say whether your system was ImageMagick/RMagick based,
but if
it is, simply saying :resize_to => “200x200” should work. By default,
ImageMagick maintains the aspect ratio when it resizes.

Thanks for the suggestion, but I should have mentioned that we’re
doing a resize-and-crop via rmagick, which means that we don’t want
to (exactly) preserve the aspect ratio. The image will be resized
and cropped to exactly 200x150 if it’s landscape, and exactly 150x200
if it’s portrait. Which does complicate things.

I’ve got the resize-and-crop working, it’s just trying to figure out
how to do one or the other depending on its orientation.

–Wade