简体   繁体   English

如何在ImageMagick和Paperclip中调整大小和裁剪?

[英]How to resize and crop in ImageMagick and Paperclip?

The output image size should be 800x200 or smaller. 输出图像尺寸应为800x200或更小。 How to achieve the following? 如何实现以下目标?

  1. If the source image is smaller in both dimensions, do not modify. 如果源图像在两个维度上都较小,请不要进行修改。
  2. If the source image is larger in both dimensions, then first resize to the larger side keeping aspect ratio. 如果源图像在两个维度上都较大,则首先将其调整为较大的一面,并保持宽高比。 Then crop. 然后播种。 So, 1000x500 is resized to 800x400, then cropped (around the center) to 800x200. 因此,将1000x500的大小调整为800x400,然后裁剪(围绕中心)为800x200。
  3. If the source image is larger in one dimension, then crop to 800x200. 如果源图像在一维较大,则裁剪为800x200。

Working in Rails with Paperclip. 使用回形针在Rails中工作。

Not sure if this handles #1 in the question, but it does #2 and #3. 不知道这是否处理问题中的#1,但确实处理#2和#3。

has_attached_file :picture, 
                  :styles => { :medium => "800x200#" }

Thanks to colli8marko for this! 感谢colli8marko!

Simple cropping with Paperclip 使用回形针轻松裁剪

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM