Ruby-on-rails 使用 Paperclip 进行简单裁剪

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1017509/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 21:22:54  来源:igfitidea点击:

Simple cropping with Paperclip

ruby-on-railsrubypaperclipcrop

提问by collimarco

I would like to crop images on upload using Paperclip to get square thumbs from the center of the original picture. I find out a method in documentation that seems to do exactly what I want:

我想在上传时使用 Paperclip 裁剪图像以从原始图片的中心获取方形拇指。我在文档中找到了一种方法,它似乎完全符合我的要求:

transformation_to(dst, crop = false)

转换到(dst,作物=假)

The problem is that I can't figure out where to use this method. It would be great to simply pass something as a parameter here:

问题是我不知道在哪里使用这种方法。在这里简单地将一些东西作为参数传递会很棒:

  has_attached_file :picture, 
                    :styles => { :medium => "600x600>", :thumb => "something here" }

回答by collimarco

You only need to use # instead of > as a parameter:

您只需要使用 # 而不是 > 作为参数:

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