Dominique Rose-Rosette
2006-Jan-11 14:38 UTC
[Rails] File_column : how can I resize/convert/whatever an image according to form-submitted values?
Hi guys,
I want to have a file upload form which would allow the user to ask for
certain transformations of the image before saving it - most importantly, to
resize it.
Now, how can I make an instance of FileColumn enabled model process these
imagemagick instructions?
My model looks looks somewhat like :
class Image < ActiveRecord::Base
attr_accessor :resize_dimension, :resize_to
before_save :resize_image
file_column :path,
:versions => { "thumbnail" => "100x100>" }
private
def resize_image
# stuff that processes the image with the form-provided values
[:resize_dimension] (can be "w" (width) or "h" (height) )
and [:resize_to],
so as to obtain the equivalent of "convert -resize ''250x''
stuff.jpg" or
"convert -resize ''x100'' stuff.jpg"
end
end
What should I put in that resize_image callback function? Would a callback be
the DRY way, to begin with?
Any tips, ideas, previous experiences, anyone?
TIA,
Dominique Rose-Rosette
