Reputation: 71101
Using CarrierWave in Rails 3.0 how would you go about making the code resize images that have a width larger than 500 pixels to be 500 pixels wide and adjust the height appropriately - keeping the same initial ratio of width to height.
Upvotes: 30
Views: 16230
Reputation: 4937
process :resize_to_limit => [500, 0]
This will process the image to be no wider than 500px while retaining the proper aspect ratio and allowing any height.
Upvotes: 30
Reputation: 2448
If you want to limit the width only, use:
process :resize_to_limit => [500, -1]
and use:
process :resize_to_limit => [-1, 500]
to limit height only.
Upvotes: 1
Reputation: 3400
I know this is an old question, but I needed something similar.
I wanted images to be resized if they were larger than a given size, but not scaled up if they were smaller.
resize_to_limit(width, height)
Resize the image to fit within the specified dimensions while retaining the original aspect ratio. Will only resize the image if it is larger than the specified dimensions. The resulting image may be shorter or narrower than specified in the smaller dimension but will not be larger than the specified values.
Details: http://carrierwave.rubyforge.org/rdoc/classes/CarrierWave/MiniMagick.html#M000051
Upvotes: 4