CarrierWave + RMagick Square Crop? [英] CarrierWave + RMagick Square Crop?
问题描述
我正在尝试使用Ruby on Rails,CarrierWave和RMagick进行固定的方形图像裁剪。
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
和
version :thumb do
process :resize_to_limit => [200, 200]
end
resize_to_limit显然调整图像大小以适应指定的尺寸同时保留原始宽高比。所以这不对,但resize_to_fit也没有这样做。我正在查看所有可用的实例方法此处。
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.
我希望能够上传任何宽高比和尺寸的图片,它将以200x200的形式出现。
I want to be able to upload a picture of any aspect ratio and dimensions and it will come out at 200x200.
推荐答案
终于搞定了!在尝试了一系列不同的自定义图像处理功能和手动裁剪之后,它实际上就像我希望的那样简单......
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]
从原始图像的直接中心将其裁剪为400x400平方。
Crops it into a 400x400 square from the direct center of the original image.
这篇关于CarrierWave + RMagick Square Crop?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!