[Django] #34035: ImageField doesn't consider EXIF rotation when storing width and height

14 views
Skip to first unread message

Django

unread,
Sep 23, 2022, 9:12:12 PM9/23/22
to django-...@googlegroups.com
#34035: ImageField doesn't consider EXIF rotation when storing width and height
-------------------------------------+-------------------------------------
Reporter: Adam | Owner: nobody
Type: Bug | Status: new
Component: Database | Version: 3.2
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
When providing a `height_field` and `width_field` for an `ImageField`, it
stores the dimensions, but without consideration of EXIF rotation. I have
attached files to test with. The files ending with 5 through 8 all have
their width and height swapped.

--
Ticket URL: <https://code.djangoproject.com/ticket/34035>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Sep 23, 2022, 9:12:33 PM9/23/22
to django-...@googlegroups.com
#34035: ImageField doesn't consider EXIF rotation when storing width and height
-------------------------------------+-------------------------------------
Reporter: Adam | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Adam):

* Attachment "EXIF Rotation 0.jpg" added.

Django

unread,
Sep 23, 2022, 9:12:42 PM9/23/22
to django-...@googlegroups.com
#34035: ImageField doesn't consider EXIF rotation when storing width and height
-------------------------------------+-------------------------------------
Reporter: Adam | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Adam):

* Attachment "EXIF Rotation 1.jpg" added.

Django

unread,
Sep 23, 2022, 9:12:54 PM9/23/22
to django-...@googlegroups.com
#34035: ImageField doesn't consider EXIF rotation when storing width and height
-------------------------------------+-------------------------------------
Reporter: Adam | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Adam):

* Attachment "EXIF Rotation 2.jpg" added.

Django

unread,
Sep 23, 2022, 9:13:04 PM9/23/22
to django-...@googlegroups.com
#34035: ImageField doesn't consider EXIF rotation when storing width and height
-------------------------------------+-------------------------------------
Reporter: Adam | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Adam):

* Attachment "EXIF Rotation 3.jpg" added.

Django

unread,
Sep 23, 2022, 9:13:13 PM9/23/22
to django-...@googlegroups.com
#34035: ImageField doesn't consider EXIF rotation when storing width and height
-------------------------------------+-------------------------------------
Reporter: Adam | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Adam):

* Attachment "EXIF Rotation 4.jpg" added.

Django

unread,
Sep 23, 2022, 9:13:22 PM9/23/22
to django-...@googlegroups.com
#34035: ImageField doesn't consider EXIF rotation when storing width and height
-------------------------------------+-------------------------------------
Reporter: Adam | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Adam):

* Attachment "EXIF Rotation 5.jpg" added.

Django

unread,
Sep 23, 2022, 9:13:31 PM9/23/22
to django-...@googlegroups.com
#34035: ImageField doesn't consider EXIF rotation when storing width and height
-------------------------------------+-------------------------------------
Reporter: Adam | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Adam):

* Attachment "EXIF Rotation 6.jpg" added.

Django

unread,
Sep 23, 2022, 9:13:40 PM9/23/22
to django-...@googlegroups.com
#34035: ImageField doesn't consider EXIF rotation when storing width and height
-------------------------------------+-------------------------------------
Reporter: Adam | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Adam):

* Attachment "EXIF Rotation 7.jpg" added.

Django

unread,
Sep 23, 2022, 9:13:49 PM9/23/22
to django-...@googlegroups.com
#34035: ImageField doesn't consider EXIF rotation when storing width and height
-------------------------------------+-------------------------------------
Reporter: Adam | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Adam):

* Attachment "EXIF Rotation 8.jpg" added.

Django

unread,
Sep 23, 2022, 9:41:09 PM9/23/22
to django-...@googlegroups.com
#34035: ImageField doesn't consider EXIF rotation when storing width and height
-------------------------------------+-------------------------------------
Reporter: Adam | Owner: nobody
Type: Bug | Status: closed

Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* status: new => closed
* resolution: => invalid


Comment:

Django simply uses [https://github.com/python-pillow/Pillow Pillow] to
retrieve the dimensions, so this should be reproduced without Django and
then (if a valid issue) reported there. A quick search revealed
[https://github.com/python-pillow/Pillow/issues/4537 a possibly related
issue].

If my analysis is incorrect, please reopen this ticket with an explanation
of where Django is at fault.

--
Ticket URL: <https://code.djangoproject.com/ticket/34035#comment:1>

Django

unread,
Sep 23, 2022, 11:04:55 PM9/23/22
to django-...@googlegroups.com
#34035: ImageField doesn't consider EXIF rotation when storing width and height
-------------------------------------+-------------------------------------
Reporter: Adam | Owner: nobody
Type: Bug | Status: new

Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Adam):

* status: closed => new
* resolution: invalid =>


Comment:

Here is [https://github.com/python-
pillow/Pillow/issues/4703#issuecomment-645219973 another Pillow issue]
that may be of interest. It seems that Pillow ignoring the EXIF
orientation is by design. Pillow is used in various contexts, not just
web. I think in other cases it may make sense to return the dimensions
without considering the EXIF orientation. But the web defaults to
considering the EXIF orientation (see
[https://chromestatus.com/feature/6313474512650240 this link]). Since
Django is for the web, I think it should consider the EXIF orientation. I
was able to make a quick and dirty fix to django/core/files/images.py. I
added the following right above where it says `return p.image.size`
([https://github.com/django/django/blob/3.2.15/django/core/files/images.py#L77
source]):

{{{
try:
exif = p.image._getexif()
except (AttributeError, ValueError):
pass
else:
if exif is not None and exif[274] > 4:
return (p.image.size[1], p.image.size[0])
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/34035#comment:2>

Django

unread,
Sep 24, 2022, 2:16:37 AM9/24/22
to django-...@googlegroups.com
#34035: ImageField doesn't consider EXIF rotation when storing width and height
-------------------------------------+-------------------------------------
Reporter: Adam | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by David Sanders):

Adam I'd encourage you to start a discussion on the django-developers
mailing list [1] seeing as this is a behaviour change. Your suggestion
seems like it could be a helpful addition but many folks have probably
already encoded exif rotation into their codebases and might get an
unwelcome surprise if Django started doing it… there may be a bunch of
other reasons that folks would rather it not behave this way? 🤔

That being said the triage team might simply accept it :)

[1] https://groups.google.com/g/django-developers

--
Ticket URL: <https://code.djangoproject.com/ticket/34035#comment:3>

Django

unread,
Sep 24, 2022, 5:35:37 AM9/24/22
to django-...@googlegroups.com
#34035: ImageField doesn't consider EXIF rotation when storing width and height
-------------------------------------+-------------------------------------
Reporter: Adam | Owner: nobody
Type: | Status: closed
Cleanup/optimization |

Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | Resolution: wontfix

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed

* type: Bug => Cleanup/optimization
* resolution: => wontfix


Comment:

I agree with David that some discussion is needed because this change is
backward incompatible. You can also subclass `ImageField` if the current
behavior doesn't suit you.

Please [https://docs.djangoproject.com/en/stable/internals/contributing
/triaging-tickets/#closing-tickets follow the triaging guidelines with
regards to wontfix tickets] and take this to DevelopersMailingList to
reach a wider audience and see what other think.

--
Ticket URL: <https://code.djangoproject.com/ticket/34035#comment:4>

Reply all
Reply to author
Forward
0 new messages