[英]How to crop & fill with Paperclip (or RMagick)?
I upload a photo, it is a rectangle. 我上传了一张照片,它是一个矩形。 How Can I get it resized and filled to a square ?
我如何才能将其调整大小并填充到正方形?
I mean when the photo is horizontal positioned it should have above and under it, two white fields (for keeping the shape of a square) and when it is vertically, it should have two white fields on the sides of the photo. 我的意思是当照片水平放置时,它应该在其上方和下方,两个白色区域(用于保持正方形的形状),当它是垂直时,它应该在照片的两侧有两个白色区域。
When I used PHP, a have used this http://www.verot.net/php_class_upload_samples.htm 当我使用PHP时,a使用了这个http://www.verot.net/php_class_upload_samples.htm
Have a look at the 看看吧
100x150, keeping ratio, filling top and bottom
100x150,保持比例,填充顶部和底部
example 例
I'm using Paperclip with RoR. 我正在使用Paperclip和RoR。 How is the best way to do that ?
最好的方法是怎样做的?
Here's what I used on a rails 3 app w/ paperclip. 这是我在rails 3 app / paperclip上使用的内容。 I used the following ImageMagick options to make it centered: background, compose, gravity and extent.
我使用以下ImageMagick选项使其居中:背景,构图,重力和范围。 I'm using the mini_magick processor.
我正在使用mini_magick处理器。
has_attached_file :image,
:styles => { :large => ["855x570>", :jpg], :medium => ["432x288>", :jpg], :small => ["276x184>", :jpg], :tiny => ["195x130>", :jpg] },
:processor => "mini_magick",
:convert_options => {
:medium => "-background white -compose Copy -gravity center -extent 432x288",
:small => "-background white -compose Copy -gravity center -extent 276x184",
:tiny => "-background white -compose Copy -gravity center -extent 195x130"
}
You need to define a style. 您需要定义样式。 Here's an example .
这是一个例子 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.