Skip to content

Commit

Permalink
Add support to rotate the image according to the exif information
Browse files Browse the repository at this point in the history
The ImageMagick option "-auto-orient" uses the "Orientation" tag
in the exif metadata to rotate the image into the right position
for clients which don't support rotating images on the fly.

This fixes problems with image uploads from misc cameras, for
example the Apple iPhone.
  • Loading branch information
mjonuschat committed Jul 25, 2011
1 parent 523f24d commit d143391
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/dragonfly/image_magick/processor.rb
Expand Up @@ -26,6 +26,10 @@ def resize(temp_object, geometry)
convert(temp_object, "-resize \"#{geometry}\"")
end

def auto_orient(temp_object)
convert(temp_object, "-auto-orient")
end

def crop(temp_object, opts={})
width = opts[:width]
height = opts[:height]
Expand Down
Binary file added samples/beach.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions spec/dragonfly/image_magick/processor_spec.rb
Expand Up @@ -237,6 +237,17 @@
end
end

describe "auto-orient" do
it "should rotate an image according to exif information" do
@image = Dragonfly::TempObject.new(SAMPLES_DIR.join('beach.jpg'))
@image.should have_width(355)
@image.should have_height(280)
image = @processor.auto_orient(@image)
image.should have_width(280)
image.should have_height(355)
end
end

describe "flip" do
it "should flip the image, leaving the same dimensions" do
image = @processor.flip(@image)
Expand Down

0 comments on commit d143391

Please sign in to comment.