Skip to content

Instantly share code, notes, and snippets.

@tanraya
Created November 12, 2013 20:44
Show Gist options
  • Save tanraya/7438337 to your computer and use it in GitHub Desktop.
Save tanraya/7438337 to your computer and use it in GitHub Desktop.
Carrierwave auto orient image explained
module CarrierWave
module MiniMagick
# Rotates the image based on the EXIF Orientation
# According to http://jpegclub.org/exif_orientation.html
def auto_orient
manipulate! do |image|
case image['EXIF:Orientation'].to_i
when 2
image.flop
when 3
image.rotate(180)
when 4
image.flip
when 5
image.transpose
when 6
image.rotate(90)
when 7
image.transverse
when 8
image.rotate(270)
end
image
end
end
end
end
@tanraya
Copy link
Author

tanraya commented Nov 12, 2013

This is the same as

module CarrierWave
  module MiniMagick
    # Rotates the image based on the EXIF Orientation
    def auto_orient
      manipulate! do |image|
        image.tap(&:auto_orient)
      end
    end
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment