在回形针中禁用自动旋转
Disable auto rotate in paperclip
我在我的项目中使用 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#" }
现在有人知道怎么做吗?
谢谢!
最后,我创建了一个新的处理器,它从回形针默认缩略图处理器扩展来发送正确的选项。
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
中的旧维度放入此哈希中
- 其他 key/value 对是传递给处理器的选项
- 你当然也可以通过
auto_orient: false
将此应用于您的模型代码:
has_attached_file :photo,
styles: { square: { geometry: "400x400#", auto_orient: false } }
我在我的项目中使用 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#" }
现在有人知道怎么做吗?
谢谢!
最后,我创建了一个新的处理器,它从回形针默认缩略图处理器扩展来发送正确的选项。
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
中的旧维度放入此哈希中 - 其他 key/value 对是传递给处理器的选项
- 你当然也可以通过
auto_orient: false
将此应用于您的模型代码:
has_attached_file :photo,
styles: { square: { geometry: "400x400#", auto_orient: false } }