# Attachment\_fu and portrait vs. landscape pictures

**URL:** <https://www.ruby-forum.com/t/attachment-fu-and-portrait-vs-landscape-pictures/103749>\
**Category:** Rails\
**Created:** [May 9, 2007, 10:07pm UTC](https://www.ruby-forum.com/t/attachment-fu-and-portrait-vs-landscape-pictures/103749 "2007-05-09T22:07:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![HSWade\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/e19adc/32.png) [@HSWade\_M](https://www.ruby-forum.com/u/HSWade_M)\
**Post date:** [May 9, 2007, 10:07pm UTC](https://www.ruby-forum.com/t/attachment-fu-and-portrait-vs-landscape-pictures/103749/1 "2007-05-09T22:07:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![HSWade\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/e19adc/32.png) [@HSWade\_M](https://www.ruby-forum.com/u/HSWade_M)\
**Post date:** [May 10, 2007, 1:45am UTC](https://www.ruby-forum.com/t/attachment-fu-and-portrait-vs-landscape-pictures/103749/2 "2007-05-10T01:45:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![HSWade\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/e19adc/32.png) [@HSWade\_M](https://www.ruby-forum.com/u/HSWade_M)\
**Post date:** [May 10, 2007, 2:33am UTC](https://www.ruby-forum.com/t/attachment-fu-and-portrait-vs-landscape-pictures/103749/3 "2007-05-10T02:33:12Z")

</div>

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
