How do I resize an image using carrierwave and minimagick so that it ignores the aspect ratio?, I want a [120,120] image
(The linked answer maintains aspect ratio, I want to ignore aspect ratio!!)
How do I resize an image using carrierwave and minimagick so that it ignores the aspect ratio?, I want a [120,120] image
(The linked answer maintains aspect ratio, I want to ignore aspect ratio!!)
You'll need to write a custom processing method in your uploader:
class MyImageUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
version :square do
process my_resize: [120, 120]
end
def my_resize(width, height)
manipulate! do |img|
img.resize "#{width}x#{height}!"
img
end
end
end
The resize
method uses ImageMagick geometry syntax. So in this case the exclamation mark at the end tells ImageMagick to ignore the aspect ratio.
You can use resize_to_fill: [120, 120]
. That will ignore the aspect ratio so the resulting image would be 120x120
Don't confound with resize_to_fit: [120, 120]
that will keep the aspect ratio, so the resulting image could be 120x90 (depending on aspect ratio).
Hope this helped