mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-06-13 17:43:29 +03:00
Allow exif_transpose to work on Image instances as well as ImageFile
This commit is contained in:
parent
38fb9b1030
commit
8f0db65cd7
|
@ -240,14 +240,18 @@ class TestImageOps(PillowTestCase):
|
||||||
for i in range(2, 9):
|
for i in range(2, 9):
|
||||||
im = Image.open("Tests/images/hopper_orientation_"+str(i)+ext)
|
im = Image.open("Tests/images/hopper_orientation_"+str(i)+ext)
|
||||||
orientations.append(im)
|
orientations.append(im)
|
||||||
for im in orientations:
|
for i, orientation_im in enumerate(orientations):
|
||||||
if im is base_im:
|
for im in [
|
||||||
|
orientation_im, # ImageFile
|
||||||
|
orientation_im.copy() # Image
|
||||||
|
]:
|
||||||
|
if i == 0:
|
||||||
self.assertNotIn("exif", im.info)
|
self.assertNotIn("exif", im.info)
|
||||||
else:
|
else:
|
||||||
original_exif = im.info["exif"]
|
original_exif = im.info["exif"]
|
||||||
transposed_im = ImageOps.exif_transpose(im)
|
transposed_im = ImageOps.exif_transpose(im)
|
||||||
self.assert_image_similar(base_im, transposed_im, 17)
|
self.assert_image_similar(base_im, transposed_im, 17)
|
||||||
if im is base_im:
|
if i == 0:
|
||||||
self.assertNotIn("exif", im.info)
|
self.assertNotIn("exif", im.info)
|
||||||
else:
|
else:
|
||||||
self.assertNotEqual(transposed_im.info["exif"], original_exif)
|
self.assertNotEqual(transposed_im.info["exif"], original_exif)
|
||||||
|
|
|
@ -532,9 +532,9 @@ def exif_transpose(image):
|
||||||
:param image: The image to transpose.
|
:param image: The image to transpose.
|
||||||
:return: An image.
|
:return: An image.
|
||||||
"""
|
"""
|
||||||
if isinstance(image, ImageFile.ImageFile):
|
if "exif" in image.info:
|
||||||
exif = image.getexif()
|
exif = ImageFile.Exif()
|
||||||
if exif:
|
exif.load(image.info["exif"])
|
||||||
orientation = exif.get(0x0112)
|
orientation = exif.get(0x0112)
|
||||||
method = {
|
method = {
|
||||||
2: Image.FLIP_LEFT_RIGHT,
|
2: Image.FLIP_LEFT_RIGHT,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user