CarrierWave + RMagick Square Crop?

坚强是说给别人听的谎言 提交于 2019-12-23 14:18:19

问题


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.


回答1:


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.




回答2:


gbdev, your answer is absolutely correct. But watch out! You must stop/restart your rails server if you're changing the process argument.

E.g. if you currently have:

process :resize_to_fit => [400, 400]

and you want to change to:

process :resize_to_fill => [400, 400]

then you have to bounce your server to see the changes take effect.

Note that this only applies to the key of that argument hash, and not the value. So if you're simply just changing the dimensions e.g. from 800x800 to 400x400, then there's no need to bounce the server.



来源:https://stackoverflow.com/questions/18166492/carrierwave-rmagick-square-crop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!