Stopping auto-rotation of images in Django-imagekit Thumbnail
Asked Answered
C

3

11

I've got a thumbnail filter that always ends up rotating the image 90 degrees to the left when the image is taller than it is wide (I've checked, and the original image is straight, while the cached image is rotated). The relevant code looks like this:

profile_image = models.ImageField(upload_to='profile_images', default='profile_images/icon.png')
profile_icon = ImageSpecField(source='profile_image',
                              processors=[processors.Thumbnail(width=72, height=72, crop=True)],
                              format='JPEG',
                              options={'quality': 60})

How do I stop the auto-rotation?

Cinderella answered 29/6, 2013 at 23:19 Comment(0)
P
11

Glad you figured this out, but ImageKit may be able to help you out some still. Check out the Transpose processor (imagekit.processors.Transpose). By default, it will use the metadata in the image, and rotate by that amount! Just be sure to list this processor first as subsequent processors will strip the metadata from the image.

Pia answered 30/6, 2013 at 21:24 Comment(1)
imagekit documentationAltocumulus
A
9

To elaborate on matthewwithanm's helpful pointer, the OP's code would be tweaked to look like this:

profile_image = models.ImageField(upload_to='profile_images', default='profile_images/icon.png')
profile_icon = ImageSpecField(source='profile_image',
                              processors=[
                                  processors.Transpose(),
                                  processors.Thumbnail(width=72, height=72, crop=True)
                              ],
                              format='JPEG',
                              options={'quality': 60})

ie, add a call to processors.Transpose() with no arguments.

I had this problem with an original portrait-format image downloaded from Flickr. That image (taken on an iPhone) is in portrait format, and by default imagekit rotates it, in this particular case, 90 degrees anti-clockwise.

Abert answered 6/6, 2016 at 14:44 Comment(0)
C
2

Okay, it turns out that it's a problem with the images being uploaded, not anything with Django. Pictures that are taken on an iPhone can have phone orientation metadata that causes the browser to think the photo's natural orientation is sideways. But, if I open that photo in Preview, rotate it left and then back to normal, and then save it again, there are no problems.

Feed image shows rotated in certain browsers

Surprise!

Cinderella answered 30/6, 2013 at 18:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.