1

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!!)

raphael_turtle
  • 7,154
  • 10
  • 55
  • 89
  • This does NOT answer my question as I specifically asked for aspect ratio to be ignored and your linked answer maintains aspect ratio. – raphael_turtle Oct 31 '14 at 12:11

2 Answers2

5

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.

kaboom
  • 1,134
  • 8
  • 8
1

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

kevcha
  • 1,002
  • 9
  • 15