Allow exif_transpose to work on Image instances as well as ImageFile

This commit is contained in:
Andrew Murray 2019-04-01 19:37:25 +11:00
parent 38fb9b1030
commit 8f0db65cd7
2 changed files with 39 additions and 35 deletions

View File

@ -240,14 +240,18 @@ class TestImageOps(PillowTestCase):
for i in range(2, 9):
im = Image.open("Tests/images/hopper_orientation_"+str(i)+ext)
orientations.append(im)
for im in orientations:
if im is base_im:
for i, orientation_im in enumerate(orientations):
for im in [
orientation_im, # ImageFile
orientation_im.copy() # Image
]:
if i == 0:
self.assertNotIn("exif", im.info)
else:
original_exif = im.info["exif"]
transposed_im = ImageOps.exif_transpose(im)
self.assert_image_similar(base_im, transposed_im, 17)
if im is base_im:
if i == 0:
self.assertNotIn("exif", im.info)
else:
self.assertNotEqual(transposed_im.info["exif"], original_exif)

View File

@ -532,9 +532,9 @@ def exif_transpose(image):
:param image: The image to transpose.
:return: An image.
"""
if isinstance(image, ImageFile.ImageFile):
exif = image.getexif()
if exif:
if "exif" in image.info:
exif = ImageFile.Exif()
exif.load(image.info["exif"])
orientation = exif.get(0x0112)
method = {
2: Image.FLIP_LEFT_RIGHT,