Fixed size cropping on an image with the exif orientation flag set to 8 #1028

Closed
martent opened this Issue Sep 24, 2012 · 5 comments

Projects

None yet

4 participants

@martent
martent commented Sep 24, 2012

Problem

Using the trailing #in a Paperclip style is supposed to generate a thumbnail centrally cropped with the specified width and height. However, for a jpeg image in portrait orientation with the exif orientation flag set to 8, the image gets scaled to the given height and not cropped as expected.

Versions

  • Paperclip 3.2.0 or latest
  • ImageMagick 6.7.7-6 2012-08-12 Q16 (latest homebrew)

Test case

Paperclip styles configuration in a Rails model:

class User < ActiveRecord::Base
  has_attached_file :avatar, styles: { quadrat: "500x500#" }
end

Test image (or an unaltered (not re-saved) image in portrait orientation from most other digital cameras):
https://www.dropbox.com/s/y5aklmz3ghk3cuw/portrait_with_orientation-8.jpg

Info about the image file:

$ identify -format "%[exif:*orientation*]" portrait_with_orientation-8.jpg
exif:Orientation=8
$ identify -format "%wx%h" portrait_with_orientation-8.jpg
4000x3000

The exif:Orientation=8 tells an image viewer/processor to rotated the image 90 degrees before display or process it.

Result

The Paperclip styles:configuration in the Rails code above generates the following image:

$ identify -format "%[exif:*orientation*]" quadrat.jpg
exif:Orientation=1
$ identify -format "%wx%h" quadrat.jpg
292x500

The image is expected to be 500x500 and not 292x500.

Note

Paperclip executes the following ImageMagick convert command:

-auto-orient -resize "x500" -crop "500x500+83+0" +repage
@jyurek
Member
jyurek commented Nov 16, 2012

This should be fixed in master now, if you'd like to give it a whirl and let me now if you see any problems.

@jyurek jyurek closed this Nov 16, 2012
@martent
martent commented Dec 7, 2012

@jyurek Confirmed. Thanks!

@dheza
dheza commented Dec 11, 2012

Hello Guys,

I'm trying to rotate a image -90 using paperclip, but until now I'm not able, Please, someone can help me?

@jyurek
Member
jyurek commented Jan 8, 2013

@dheza I'm not sure off the top of my head, but you should make a new issue for this and not piggyback on.

@quark-zju

I'm using paperclip 3.4.0 but still have this issue.

Command :: identify -format '%wx%h,%[exif:orientation]' '/tmp/1e7411673536da67589bb52b8de73b4f3a8eb39920130424-28627-ppote5.jpg[0]'
Command :: identify -format %m '/tmp/1e7411673536da67589bb52b8de73b4f3a8eb39920130424-28627-ppote5.jpg[0]'
Command :: identify -format %m '/tmp/1e7411673536da67589bb52b8de73b4f3a8eb39920130424-28627-ppote5.jpg[0]'
Command :: convert '/tmp/1e7411673536da67589bb52b8de73b4f3a8eb39920130424-28627-ppote5.jpg[0]' -auto-orient -resize "x560" -crop "400x560+186+0" +repage '/tmp/1e7411673536da67589bb52b8de73b4f3a8eb39920130424-28627-ppote520130424-28627-twcfmg'
Command :: file -b --mime '/tmp/1e7411673536da67589bb52b8de73b4f3a8eb39920130424-28627-ppote520130424-28627-twcfmg'
Command :: identify -format '%wx%h,%[exif:orientation]' '/tmp/1e7411673536da67589bb52b8de73b4f3a8eb39920130424-28627-ppote5.jpg[0]'
Command :: identify -format %m '/tmp/1e7411673536da67589bb52b8de73b4f3a8eb39920130424-28627-ppote5.jpg[0]'
Command :: identify -format %m '/tmp/1e7411673536da67589bb52b8de73b4f3a8eb39920130424-28627-ppote5.jpg[0]'
Command :: convert '/tmp/1e7411673536da67589bb52b8de73b4f3a8eb39920130424-28627-ppote5.jpg[0]' -auto-orient -resize "x56" -crop "40x56+18+0" +repage '/tmp/1e7411673536da67589bb52b8de73b4f3a8eb39920130424-28627-ppote520130424-28627-10nbn2s'
Command :: file -b --mime '/tmp/1e7411673536da67589bb52b8de73b4f3a8eb39920130424-28627-ppote520130424-28627-10nbn2s'
identify -format '%wx%h,%[exif:orientation]' 1e7411673536da67589bb52b8de73b4f3a8eb399.jpg
50x69,8

This may be related to #1048 .

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