[英]Disable auto rotate in paperclip
我在项目中使用Paperclip,但一些用户抱怨说它在错误地旋转某些图像。
由于某些原因,我什至无法想象我发现某些文件具有错误的exif方向属性。 我一直在寻找,并且看到回形针默认使用-auto-orient
调用ImageMagick。 我看到Thumbnail处理器可以选择打开或关闭自动定向 。
但是我找不到将其传递给处理器的方法。
这是我的代码:
has_attached_file :photo,
styles: { :square => "400x400#" }
现在有人吗?
谢谢!
最后,我创建了一个新的处理器,该处理器从回形针默认的Thumbnail处理器扩展到发送正确的选项。
class WithouAutoOrientProcessor < Paperclip::Thumbnail
def initialize(file, options = {}, attachment = nil)
options[:auto_orient] = false
super
end
end
在我添加的模型中
has_attached_file :photo,
styles: { :square => "400x400#" },
processors: [:WithouAutoOrientProcessor]
尽管添加自己的处理器是有效的选项,但是这是将选项传递给处理器的方式:
styles
哈希中,将维度字符串替换为另一个哈希 geometry
到这个散列 auto_orient: false
。 将此应用于模型的代码:
has_attached_file :photo,
styles: { square: { geometry: "400x400#", auto_orient: false } }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.