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

martent opened this Issue Sep 24, 2012 · 5 comments


None yet

4 participants

martent commented Sep 24, 2012


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.


  • 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#" }

Test image (or an unaltered (not re-saved) image in portrait orientation from most other digital cameras):

Info about the image file:

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

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


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

$ identify -format "%[exif:*orientation*]" quadrat.jpg
$ identify -format "%wx%h" quadrat.jpg

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


Paperclip executes the following ImageMagick convert command:

-auto-orient -resize "x500" -crop "500x500+83+0" +repage
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 commented Dec 7, 2012

@jyurek Confirmed. Thanks!

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 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.


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

This may be related to #1048 .

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