How do you scale down an image until one side reaches it’s goal dimension with Carrierwave and rmagick?
Example:
Goal dimensions: 600×400
Picture being uploaded: 700×450
I want this image to be scaled down until the height reaches 400 pixels keeping the original aspect ratio.
That would result in a image with the following dimensions: 622×400
You might take a look at
resize_to_limit. From the carrierwave docs:So you could do something like this in your uploader:
If you don’t mind to crop the image, you could go for
resize_to_fitinstead, and use the gravity value that you desire:Edit:
You can read the documentation for these processors for more options on resizing
For a
resize_to_minimplementation that would only enforce minimum dimensions for your width and height, you can takeresize_to_limitas base and just modify the geometry setting toMinimumGeometryto create a custom processor: