mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-10 19:56:47 +03:00
Delete EXIF orientation tag after transposing
This commit is contained in:
parent
c8257b30dd
commit
38fb9b1030
|
@ -1,7 +1,8 @@
|
|||
from .helper import PillowTestCase, hopper
|
||||
|
||||
from PIL import ImageOps
|
||||
from PIL import Image
|
||||
from PIL import ImageFile
|
||||
from PIL import ImageOps
|
||||
|
||||
try:
|
||||
from PIL import _webp
|
||||
|
@ -240,8 +241,20 @@ class TestImageOps(PillowTestCase):
|
|||
im = Image.open("Tests/images/hopper_orientation_"+str(i)+ext)
|
||||
orientations.append(im)
|
||||
for im in orientations:
|
||||
if im is base_im:
|
||||
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:
|
||||
self.assertNotIn("exif", im.info)
|
||||
else:
|
||||
self.assertNotEqual(transposed_im.info["exif"], original_exif)
|
||||
|
||||
exif = ImageFile.Exif()
|
||||
exif.load(transposed_im.info["exif"])
|
||||
self.assertNotIn(0x0112, exif)
|
||||
|
||||
# Repeat the operation, to test that it does not keep transposing
|
||||
transposed_im2 = ImageOps.exif_transpose(transposed_im)
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
# See the README file for information on usage and redistribution.
|
||||
#
|
||||
|
||||
from . import Image
|
||||
from . import Image, ImageFile
|
||||
from ._util import isStringType
|
||||
import operator
|
||||
import functools
|
||||
|
@ -532,8 +532,8 @@ def exif_transpose(image):
|
|||
:param image: The image to transpose.
|
||||
:return: An image.
|
||||
"""
|
||||
if not hasattr(image, '_exif_transposed') and hasattr(image, '_getexif'):
|
||||
exif = image._getexif()
|
||||
if isinstance(image, ImageFile.ImageFile):
|
||||
exif = image.getexif()
|
||||
if exif:
|
||||
orientation = exif.get(0x0112)
|
||||
method = {
|
||||
|
@ -547,6 +547,7 @@ def exif_transpose(image):
|
|||
}.get(orientation)
|
||||
if method is not None:
|
||||
transposed_image = image.transpose(method)
|
||||
transposed_image._exif_transposed = True
|
||||
del exif[0x0112]
|
||||
transposed_image.info["exif"] = exif.tobytes()
|
||||
return transposed_image
|
||||
return image.copy()
|
||||
|
|
Loading…
Reference in New Issue
Block a user