Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CarrierWave + RMagick Square Crop?

I am trying to make a fixed square image crop with Ruby on Rails, CarrierWave, and RMagick.

I have tried both of the following with no luck...

version :thumb do
  process :resize_to_fit => [200, 200]
end

and

version :thumb do
  process :resize_to_limit => [200, 200]
end

resize_to_limit obviously resizes the image to fit within the specified dimensions while retaining the original aspect ratio. So that's not right, but resize_to_fit doesn't do it either. I am looking at all of the available of the instance methods here.

I want to be able to upload a picture of any aspect ratio and dimensions and it will come out at 200x200.

like image 815
gbdev Avatar asked Dec 02 '22 18:12

gbdev


1 Answers

Finally got this! After trying a bunch of different custom image manipulation functions and manual cropping it's actually as simple as I had hoped for...

process :resize_to_fill => [400, 400]

Crops it into a 400x400 square from the direct center of the original image.

like image 198
gbdev Avatar answered Dec 10 '22 10:12

gbdev