Search code examples
ruby-on-railscarrierwavermagick

Carrierwave undefined metho auto_orient


I've been trying to use RMagick auto_orient method to fix mobile uploads. Currently they are rotated 90 degrees. My uploader file currently looks like this.

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

This is giving me an error

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

I've tried several solutions, exif image rotation issue using carrierwave and rmagick to upload to s3, https://github.com/minimagick/minimagick/issues/68 but no dice.

Anyone got a clue what I'm doing wrong?


Solution

  • Try adding the following:

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

    As it stands now, the auto_orient process you're referencing doesn't exist in the context, hence the error.

    Edit: according to the imagemagick github link you posted, auto_orient! might be broken. You could then use auto_orient instead in a similar way (it just creates a new image instead of modifying the one passed to the method). Refer to the links you posted for possible solutions using the auto_orient method.