marco
marco

Reputation: 13

dynamic image sizes for uploaded images in rails3

in rails, paperclip has a fixed (model-based) definition of image-sizes.

has_attached_file :data,
 :styles => { :large => "800x600>", :icon => "50x50#" }, 
 :path => ":rails_root/public/images/files/:id/:style/:basename.:extension", 
 :url => "/images/files/:id/:style/:basename.:extension", 
 :convert_options => { :all  => "-colorspace RGB" }, 
 :whiny_thumbnails => true

but this example sets the image-dimensions to 2 types (large, icon) in 2 fixed sizes. this is nice for the most issues but not if you like to show a uploaded picture in a different size e.g. 640x480 …

is there a way to have images scaled on the fly - in rails3 ???

Upvotes: 1

Views: 760

Answers (2)

Aaron Hinni
Aaron Hinni

Reputation: 14716

You can look at something like Dragonfly to process your images instead of Paperclip. It puts the sizing in the view instead of the model and utilizes some caching mechanisms to help with performance.

Upvotes: 1

Adrian Serafin
Adrian Serafin

Reputation: 7715

Scale images on the fly could kill your server ;)

If you only want to show picture, maybe you could use width and/or height attributes of html image tag?

Upvotes: 0

Related Questions