Forum: Ruby on Rails attachment_fu max height/width

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
7dc6183602c65b027a7ef7dd78c62a36?d=identicon&s=25 Franz M. (xinu)
on 2007-07-28 12:08

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



thanks for your help.
832ed6ace46d61032151f4e1864c057f?d=identicon&s=25 Solid (Guest)
on 2007-07-28 12:28
(Received via mailing list)
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:

On Jul 28, 1:08 pm, "Michael M." <>
7dc6183602c65b027a7ef7dd78c62a36?d=identicon&s=25 Franz M. (xinu)
on 2007-07-28 14:27
thank you Solid!
110c7df9fbc932cfe55c6317aedd04b3?d=identicon&s=25 jawgaping (Guest)
on 2007-08-03 10:34
(Received via mailing list)
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." <>
This topic is locked and can not be replied to.