[Solved]-Stopping auto-rotation of images in Django-imagekit Thumbnail


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.


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.Thumbnail(width=72, height=72, crop=True)
                              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.


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


Leave a comment