回形针调整大小并裁剪为矩形

时间:2022-03-24 00:18:11

So I am expecting a series of photos of different sizes and aspect ratios. I want to be able to shrink/stretch the photo to fit as much as it can in a 200x100 rectangle and then crop the rest that does not fit. I want the crop to happen around the center as well. Is this possible? I am so confused with the imagemagick documentation.

所以我期待一系列不同尺寸和宽高比的照片。我希望能够缩小/拉伸照片以尽可能多地适应200x100矩形,然后裁剪掉不合适的照片。我希望庄稼也能在中心周围发生。这可能吗?我对imagemagick文档很困惑。

Thanks!

2 个解决方案

#1


19  

Paperclip's # option will do exactly what you want: fit the image maximally within the specified dimensions then crop the excess with gravity at the center.

Paperclip的#选项将完全符合您的要求:将图像最大限度地放入指定尺寸内,然后在重心处裁剪多余部分。

Example:

has_attached_file :photo,
                  :styles => {
                    :original => "200x100#"
                  }

Note: If you want to keep the original intact and generate an additional cropped thumb, just change the :original key to something else, like :thumb.

注意:如果您想保持原件不变并生成额外的裁剪拇指,只需将原始键更改为其他内容,例如:thumb。

Reference: http://rdoc.info/github/thoughtbot/paperclip/Paperclip/ClassMethods

#2


1  

are any of these usefull?

这些都有用吗?

Resize an image with Paperclip

使用Paperclip调整图像大小

Simple cropping with Paperclip

使用Paperclip进行简单裁剪

http://mfischer.com/wordpress/2009/02/02/multiple-image-upload-and-crop-with-rails/comment-page-1/

#1


19  

Paperclip's # option will do exactly what you want: fit the image maximally within the specified dimensions then crop the excess with gravity at the center.

Paperclip的#选项将完全符合您的要求:将图像最大限度地放入指定尺寸内,然后在重心处裁剪多余部分。

Example:

has_attached_file :photo,
                  :styles => {
                    :original => "200x100#"
                  }

Note: If you want to keep the original intact and generate an additional cropped thumb, just change the :original key to something else, like :thumb.

注意:如果您想保持原件不变并生成额外的裁剪拇指,只需将原始键更改为其他内容,例如:thumb。

Reference: http://rdoc.info/github/thoughtbot/paperclip/Paperclip/ClassMethods

#2


1  

are any of these usefull?

这些都有用吗?

Resize an image with Paperclip

使用Paperclip调整图像大小

Simple cropping with Paperclip

使用Paperclip进行简单裁剪

http://mfischer.com/wordpress/2009/02/02/multiple-image-upload-and-crop-with-rails/comment-page-1/