From dff7dcc9f6db241097e51477be06b5620cf65c45 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 8 Sep 2023 08:23:35 +1000 Subject: [PATCH] Ensure TIFF has transposed on load before checking orientation --- Tests/test_file_libtiff.py | 10 +++++++++- src/PIL/ImageOps.py | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Tests/test_file_libtiff.py b/Tests/test_file_libtiff.py index ac78b086965..69499ff6ba8 100644 --- a/Tests/test_file_libtiff.py +++ b/Tests/test_file_libtiff.py @@ -8,7 +8,7 @@ import pytest -from PIL import Image, ImageFilter, TiffImagePlugin, TiffTags, features +from PIL import Image, ImageFilter, ImageOps, TiffImagePlugin, TiffTags, features from PIL.TiffImagePlugin import SAMPLEFORMAT, STRIPOFFSETS, SUBIFD from .helper import ( @@ -1039,6 +1039,14 @@ def test_orientation(self): assert_image_similar(base_im, im, 0.7) + def test_exif_transpose(self): + with Image.open("Tests/images/g4_orientation_1.tif") as base_im: + for i in range(2, 9): + with Image.open("Tests/images/g4_orientation_" + str(i) + ".tif") as im: + im = ImageOps.exif_transpose(im) + + assert_image_similar(base_im, im, 0.7) + @pytest.mark.valgrind_known_error(reason="Backtrace in Python Core") def test_sampleformat_not_corrupted(self): # Assert that a TIFF image with SampleFormat=UINT tag is not corrupted diff --git a/src/PIL/ImageOps.py b/src/PIL/ImageOps.py index 17702778c13..1231ad6ebda 100644 --- a/src/PIL/ImageOps.py +++ b/src/PIL/ImageOps.py @@ -588,6 +588,7 @@ def exif_transpose(image, *, in_place=False): with the transposition applied. If there is no transposition, a copy of the image will be returned. """ + image.load() image_exif = image.getexif() orientation = image_exif.get(ExifTags.Base.Orientation) method = {