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.
-
possible duplicate of [Carrierwave - Resizing images to fixed width](http://stackoverflow.com/questions/8570181/carrierwave-resizing-images-to-fixed-width) – Mohammed Azharuddin Shaikh Dec 25 '12 at 05:26
-
its not a duplicate - this is about keeping aspect ratio with one dimension fixed. – sevenseacat Mar 12 '14 at 08:20
4 Answers
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.

- 4,807
- 7
- 42
- 65
-
6Using this with carrierwave 0.10.0 and mini_magic 3.6.0 resulted in images scaled down to 1x1 pixels. Using `[500, nil]` as arguments worked for me instead. – efatsi Sep 02 '14 at 15:43
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

- 3,370
- 3
- 29
- 41
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.

- 2,389
- 4
- 20
- 25