# Attachment\_fu max height/width

**URL:** <https://www.ruby-forum.com/t/attachment-fu-max-height-width/110623>\
**Category:** Rails\
**Created:** [July 28, 2007, 12:08pm UTC](https://www.ruby-forum.com/t/attachment-fu-max-height-width/110623 "2007-07-28T12:08:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![xinu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/f6c823/32.png) [@xinu](https://www.ruby-forum.com/u/xinu)\
**Post date:** [July 28, 2007, 12:08pm UTC](https://www.ruby-forum.com/t/attachment-fu-max-height-width/110623/1 "2007-07-28T12:08:42Z")

</div>

hi.

I use attachment\_fu for uploading avatars.  
I only want to save the attachment, if the height and the width of the  
image are smaller than 100px.(the system should not resize it) If the  
attachment is larger I want to show a error message.

## Here is my the model.

class Avatar \< ActiveRecord::Base  
belongs\_to :user  
has\_attachment :content\_type =\> :image,  
:storage =\> :file\_system,  
:max\_size =\> 300.kilobytes

validates\_as\_attachment

## end

thanks for your help.  
xinu

---

<div class="post-metadata">

**Author:** ![xinu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/f6c823/32.png) [@xinu](https://www.ruby-forum.com/u/xinu)\
**Post date:** [July 28, 2007, 12:28pm UTC](https://www.ruby-forum.com/t/attachment-fu-max-height-width/110623/2 "2007-07-28T12:28:58Z")

</div>

I think the best way is to resize image without error confirmation.  
Simple add: :resize\_to =\> [50,50]  
to the has\_attachment.  
Or if you really want to check size, then you may use validate method,  
and check for the  
if width \> your\_width\_max and height \> your\_height\_max

Look into this article:  
[http://www.marklunds.com/articles/one/312](http://www.marklunds.com/articles/one/312)

On Jul 28, 1:08 pm, “Michael M.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![xinu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/f6c823/32.png) [@xinu](https://www.ruby-forum.com/u/xinu)\
**Post date:** [July 28, 2007, 2:27pm UTC](https://www.ruby-forum.com/t/attachment-fu-max-height-width/110623/3 "2007-07-28T14:27:36Z")

</div>

thank you Solid!

---

<div class="post-metadata">

**Author:** ![xinu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/f6c823/32.png) [@xinu](https://www.ruby-forum.com/u/xinu)\
**Post date:** [August 3, 2007, 10:34am UTC](https://www.ruby-forum.com/t/attachment-fu-max-height-width/110623/4 "2007-08-03T10:34:30Z")

</div>

Thanks for what, what was the solution… I still don’t see any way to  
find out the dimensions of the original image, nor can I find  
information anywhere about how to get the original dimensions, just  
using “width” doesn’t work.

On Jul 28, 5:27 am, “Michael M.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
