Prevent TIFF orientation from being applied more than once #7383
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #7381
When a TIFF image is loaded, the orientation is applied.
Pillow/src/PIL/TiffImagePlugin.py
Line 1545 in 52c6d68
Pillow/src/PIL/TiffImagePlugin.py
Lines 1205 to 1218 in 52c6d68
However, there is no change in Pillow's information about the image as a result of this. This is not ideal, because
tag_v2
orientation for an image, it may or may not have been applied already, depending on whether the image has loaded, and that could be confusing.ImageOps.exif_transpose()
afterwards, the orientation is applied a second time.This PR addresses 1 by deleting the
tag_v2
orientation tag, so that it is consistently present if not applied yet, and removed once it has been applied. It address 2 by callingImageOps.exif_transpose(self, in_place=True)
from TiffImagePlugin, which also reduces duplicate code.The issue also calls
exif_transpose()
immediately after opening an image, withoutload()
. So it is necessary to callload()
the image inexif_transpose()
, so that the image's orientation is not initially detected byexif_transpose
, but then quickly changed once the image is loaded to perform a transposition.