【问题标题】:Disable auto rotate in paperclip在回形针中禁用自动旋转
【发布时间】:2015-09-09 23:16:53
【问题描述】:

我在我的项目中使用 Paperclip,但我的一些用户抱怨它错误地旋转了一些图像。

由于某些原因,我什至无法想象我发现某些文件的 exif 方向属性错误。我在看,我看到回形针默认使用 -auto-orient 调用 ImageMagick。我看到了the Thumbnail processor has an option to turn auto-orient on or off

但我找不到将其传递给处理器的方法。

这是我的代码:

  has_attached_file :photo,
    styles: { :square => "400x400#" }

现在有人怎么做吗?

谢谢!

【问题讨论】:

    标签: ruby-on-rails paperclip image-rotation


    【解决方案1】:

    最后我创建了一个新的处理器,它从回形针默认缩略图处理器扩展来发送正确的选项。

    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]
    

    【讨论】:

      【解决方案2】:

      虽然添加您自己的处理器是一个有效的选项,但这是您将选项传递给处理器的方式:

      • 在您的 styles 哈希中,将您的维度字符串替换为另一个哈希
      • 将您的旧维度放入键 geometry 到此哈希中
      • 其他键/值对是传递给处理器的选项
      • 你当然也可以通过auto_orient: false

      将此应用于您的模型代码:

      has_attached_file :photo,
          styles: { square: { geometry: "400x400#", auto_orient: false } }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-08-28
        • 1970-01-01
        • 2019-07-18
        • 1970-01-01
        相关资源
        最近更新 更多