【问题标题】:Carrierwave undefined metho auto_orientCarrierwave 未定义方法 auto_orient
【发布时间】:2016-01-10 14:13:45
【问题描述】:

我一直在尝试使用 RMagick auto_orient 方法来修复移动上传。目前它们旋转了 90 度。我的上传文件目前看起来像这样。

class AvatarUploader < CarrierWave::Uploader::Base

include CarrierWave::RMagick

storage :fog
def root
  Rails.root.join 'public/'
end
include CarrierWave::MimeTypes
process :set_content_type

def store_dir
  "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end

process :resize_to_fill => [200, 200]

version :thumb do
  process :resize_to_fill => [50, 50]
end

process :auto_orient

def extension_white_list
  %w(jpg jpeg gif png)
end

end

这给了我一个错误

undefined local variable or method auto_orient for AvatarUploader:Class (NameError)

我尝试了几种解决方案, exif image rotation issue using carrierwave and rmagick to upload to s3, https://github.com/minimagick/minimagick/issues/68 但没有骰子。

有人知道我做错了什么吗?

【问题讨论】:

    标签: ruby-on-rails carrierwave rmagick


    【解决方案1】:

    尝试添加以下内容:

    def auto_orient
      manipulate! do |img|
        img.auto_orient!
      end
    end
    

    就目前而言,您引用的 auto_orient 进程在上下文中不存在,因此出现错误。

    编辑:根据您发布的 imagemagick github 链接,auto_orient! 可能已损坏。然后,您可以以类似的方式使用auto_orient(它只是创建一个新图像,而不是修改传递给该方法的图像)。请参阅您发布的链接,了解使用 auto_orient 方法的可能解决方案。

    【讨论】:

    • 谢谢。一直把我的头从墙上撞下来。我以为我已经尝试过你的方法,但我显然犯了一个错误。我正要评论 bang 方法已被删除,但你打败了我 :) 谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-26
    • 1970-01-01
    • 1970-01-01
    • 2011-09-21
    相关资源
    最近更新 更多