Proposal: Make it so when getting an image's dimensions, EXIF orientation is considered

114 views
Skip to first unread message

Adam Taylor

unread,
Sep 24, 2022, 12:51:54 PM9/24/22
to Django developers (Contributions to Django itself)
Following the advice of David Sanders and Mariusz Felisiak, I'm coming here with my proposal rather than continuing on with the ticket system (see ticket #34035).

I understand the reluctance to make this change. However, things change with web browsers and I believe web frameworks should make changes to stay in line with the web browsers. It used to be less common for web browsers to consider EXIF orientation, but now it's the standard. ImageField being able to save the image dimensions to another field is very useful but for my use case it's broken because it doesn't consider EXIF orientation so there are cases where the dimensions are the opposite of what they should be. I highly doubt I'm alone in this. Maybe there should be a setting that can be passed into ImageField to avoid breaking existing projects. I definitely think this should be part of Django rather than having the developers need to add this logic to each of their Django projects that need it.

Thoughts?

Adam Johnson

unread,
Sep 26, 2022, 5:00:28 AM9/26/22
to django-d...@googlegroups.com
I’m +1 to making this change. Incorrect orientation is frustrating and this is why browsers changed to always consider it (by default).

You're right that the web default is to consider EXIF orientation data, controllable with the image-orientation CSS property: https://developer.mozilla.org/en-US/docs/Web/CSS/image-orientation . (FYI, link to MDN in future, it's a more neutral/universal source than Chrome docs. MDN shows compat in all browsers, and Chrome implements a lot of unique features).

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/c51cfad1-df74-446a-a341-53a007a9ae9fn%40googlegroups.com.

David Sanders

unread,
Sep 26, 2022, 5:21:09 AM9/26/22
to django-d...@googlegroups.com
Coincidence I was also just reading up image-orientation… I didn't realise that it's the default behaviour now to orient.

I guess it's a question of whether/how to be backwards compatible?

David Sanders

unread,
Sep 26, 2022, 5:29:20 AM9/26/22
to django-d...@googlegroups.com
Actually might as well throw out one idea, feel free to discard:

Keep width and height as-is and add 2 additional properties for jpg: `photo_width` and `photo_height` (or named something more suitable)

This way it stays inline with other image viewing/editing software which still reports the width and height as is read from the image with the rotation as separate meta-data. (Eg I did a cursory look with Gimp & Preview on mac)

Adam Johnson

unread,
Sep 27, 2022, 5:13:39 PM9/27/22
to django-d...@googlegroups.com
To have extra properties, we'd need to add extra database fields. It would be somewhat wasteful to add them to all ImageFields when few users will care about the difference.

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.

David Sanders

unread,
Sep 28, 2022, 9:32:23 AM9/28/22
to django-d...@googlegroups.com
Hi Adam,

Sorry to clarify I was referring to `ImageFile` which has 2 `@property` attributes `width` and `height` [1].  My suggestion was that you could add 2 additional `@property` attributes that work with EXIF rotation 🙂  (or something along these lines…)

[1] https://github.com/django/django/blob/0dd29209091280ccf34e07c9468746c396b7778e/django/core/files/images.py#L18-L24

Regards,
David


Adam Taylor

unread,
Oct 29, 2022, 2:06:03 PM10/29/22
to Django developers (Contributions to Django itself)
What about having a setting that is used in the django/core/files/images.py file's get_image_dimensions function? Something like IMAGE_DIMENSIONS_USES_EXIF. It could default to False at first to maintain backwards compatibility and eventually could be True by default. If the setting is set to True then it can use the logic I included in this comment. No need for extra database fields.
Reply all
Reply to author
Forward
0 new messages