如何裁剪然后使用回形针调整大小 [英] How to crop and then resize with Paperclip

查看:115
本文介绍了如何裁剪然后使用回形针调整大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张照片附件,正在使用回形针保存。但是,我想先对照片进行处理,然后再进行裁切,然后再调整为最终尺寸,以进行保存:例如
我有一张900x900的照片,我想先对500x500进行中心裁剪,然后将裁剪后的照片缩小为缩略图尺寸100x100。

I have a photo attachment which I'm saving using Paperclip. However, I'd like to process the photo first before saving by cropping it down and then resizing to the final size: e.g. I have a 900x900 photo, I want to first do a central crop to 500x500, and then resize the cropped photo down to a thumbnail size of 100x100.

这样一来,缩略图就不会只是900x900的缩小版本,因为它可能太小而无法在照片中分辨出来。通过裁切,我们减少了照片中可以忽略的一大部分,并且仍然具有有意义的缩小缩略图。

The purpose of this is so that the thumbnail image wouldn't simply be a scaled down version of the 900x900 since it might be too small to even make out anything in the photo. By cropping it, we reduce a huge part of photo that can be left out and still have a meaningful scaled down thumbnail.

我知道回形针可以裁切或调整大小,

I know paperclip can do either crop or resize, but is there a way to combine both?

编辑:为澄清起见,我并不是要创建一个裁剪器工具,用户可以在其中进行交互并裁剪图像。对于上载的每张照片,我要统一进行裁剪,然后调整大小。

To clarify, I'm not trying to create a cropper tool where the user can interact and crop the image. For every photo that is uploaded, I want to uniformly perform a crop followed by a resize.

谢谢

推荐答案

可能有更好的方法,但是,如果您使用ImageMagick,则此方法可以正常工作。

There's probably a better way of doing this, but if you're using ImageMagick this way works fine.

以下将首先在图片的中心以500x500的比例裁剪,然后将其他所有东西都扔掉,然后将新图片的尺寸调整为100x100。

The following will first crop in the center of the image at 500x500, then throw everything else away, then resize that new image back down to 100x100.

has_attached_file :image,  
  :styles => { :thumb => "" },
  :convert_options => { 
    :thumb => "-gravity Center -crop 500x500+0+0 +repage -resize 100x100^" },
  :default_style => :thumb

这篇关于如何裁剪然后使用回形针调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆