Paperclip的简单裁剪功能

38
我想使用Paperclip在上传时裁剪图像,从而从原始图片中心获得方形缩略图。我在文档中找到了一个似乎可以完全满足我的要求的方法: transformation_to(dst, crop = false) 问题是我无法确定在哪里使用此方法。如果能够简单地将某些内容作为参数传递,那就太好了:
  has_attached_file :picture, 
                    :styles => { :medium => "600x600>", :thumb => "这里填写内容" }
1个回答

70

只需要将参数中的 > 替换为 #:

has_attached_file :picture, :styles => { :thumb => "200x200#" }

4

是针对 Paperclip 的。Paperclip 将其用作标记来居中和裁剪图像。您可以查看 https://github.com/thoughtbot/paperclip/blob/master/lib/paperclip/thumbnail.rb 获取更多信息。

- Puhlze
1
Paperclip文档关于调整大小和裁剪选项在此处:https://github.com/thoughtbot/paperclip/wiki/Thumbnail-Generation#resizing-options - lgx

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接