繁体   English   中英

在回形针中禁用自动旋转

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM