title: exif image rotation issue using carrierwave and rmagick to upload to s3
body: <p>I've got a photo upload feature in my rails app. The app uploads direct to s3 through carrierwave via rmagick and fog. The issue I am having is when a photo is uploaded via mobile through the "take a photo option" in portrait (note this is with iphone but I believe android has the same issue). Once uploaded the image appears fine on mobile, however when viewed on desktop the image appears rotated 90 degrees.</p>
  
  <p>Through my research it looks to be an issue with exif. This <a href="https://stackoverflow.com/a/1051177/2066855">stackoverflow responder</a> outlines 2 potential solutions. This <a href="https://gist.github.com/jcsrb/1510601" rel="noreferrer">gist</a> also looks promising as well.</p>
  
  <p>So far I have found a few solutions posted but none have worked. Ideally I would like the photo to be saved to s3 as a portrait, then just display the image as is.</p>
  
  <p>Any suggestions are well appreciated. </p>
  
  <p>Below is my code</p>
  
  <h1>app/uploaders/image_uploader.rb</h1>
  
  <pre><code>class ImageUploader &lt; CarrierWave::Uploader::Base
    include CarrierWaveDirect::Uploader
  
    include CarrierWave::RMagick
  
    # Include the Sprockets helpers for Rails 3.1+ asset pipeline compatibility:
    include Sprockets::Helpers::RailsHelper
    include Sprockets::Helpers::IsolatedHelper
  
    include CarrierWave::MimeTypes
    process :fix_exif_rotation
    process :set_content_type
  
  
    version :thumb do
      process resize_to_fill: [200, 200]
    end
  
    def extension_white_list
      %w(jpg jpeg png)
    end
  
  
    def fix_exif_rotation #this is my attempted solution
      manipulate! do |img|
        img = img.auto_orient!
      end
    end
  
  
  end
  </code></pre>
  
  <h1>app/models/s3_image.rb</h1>
  
  <pre><code>class S3Image &lt; ActiveRecord::Base
    attr_accessible :image, :name, :user_id
    mount_uploader :image, ImageUploader
  
    belongs_to :user
  
  
    def image_name
      File.basename(image.path || image.filename) if image
    end
  
  
    class ImageWorker
      include Sidekiq::Worker
  
      def perform(id, key)
        s3_image = S3Image.find(id)
        s3_image.key = key
        s3_image.remote_image_url = s3_image.image.direct_fog_url(with_path: true)
        s3_image.save!
        s3_image.update_column(:image_processed, true)
      end
    end
  end
  </code></pre>
  
  <h1>config/initializers/carrierwave.rb</h1>
  
  <pre><code>CarrierWave.configure do |config|
    config.fog_credentials = {
      provider: "AWS",
      aws_access_key_id: " ... ",
      aws_secret_access_key: " ... "
    }
    config.fog_directory = " ... "
  end
  </code></pre>
  
  <p>btw I used this <a href="http://railscasts.com/episodes/383-uploading-to-amazon-s3" rel="noreferrer">Railscast</a> as a guide for setting up my s3 upload.</p>