mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 18:06:18 +03:00
Handle removing orientation from alternate types of EXIF data
This commit is contained in:
parent
b057f5f40f
commit
917a598615
BIN
Tests/images/exif_imagemagick_orientation.png
Normal file
BIN
Tests/images/exif_imagemagick_orientation.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 175 KiB |
|
@ -335,6 +335,28 @@ def test_exif_transpose():
|
||||||
) as orientation_im:
|
) as orientation_im:
|
||||||
check(orientation_im)
|
check(orientation_im)
|
||||||
|
|
||||||
|
# Orientation from "XML:com.adobe.xmp" info key
|
||||||
|
with Image.open("Tests/images/xmp_tags_orientation.png") as im:
|
||||||
|
assert im.getexif()[0x0112] == 3
|
||||||
|
|
||||||
|
transposed_im = ImageOps.exif_transpose(im)
|
||||||
|
assert 0x0112 not in transposed_im.getexif()
|
||||||
|
|
||||||
|
# Orientation from "Raw profile type exif" info key
|
||||||
|
# This test image has been manually hexedited from exif_imagemagick.png
|
||||||
|
# to have a different orientation
|
||||||
|
with Image.open("Tests/images/exif_imagemagick_orientation.png") as im:
|
||||||
|
assert im.getexif()[0x0112] == 3
|
||||||
|
|
||||||
|
transposed_im = ImageOps.exif_transpose(im)
|
||||||
|
assert 0x0112 not in transposed_im.getexif()
|
||||||
|
|
||||||
|
# Orientation set directly on Image.Exif
|
||||||
|
im = hopper()
|
||||||
|
im.getexif()[0x0112] = 3
|
||||||
|
transposed_im = ImageOps.exif_transpose(im)
|
||||||
|
assert 0x0112 not in transposed_im.getexif()
|
||||||
|
|
||||||
|
|
||||||
def test_autocontrast_cutoff():
|
def test_autocontrast_cutoff():
|
||||||
# Test the cutoff argument of autocontrast
|
# Test the cutoff argument of autocontrast
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
import functools
|
import functools
|
||||||
import operator
|
import operator
|
||||||
|
import re
|
||||||
|
|
||||||
from . import Image, ImageDraw
|
from . import Image, ImageDraw
|
||||||
|
|
||||||
|
@ -588,7 +589,19 @@ def exif_transpose(image):
|
||||||
if method is not None:
|
if method is not None:
|
||||||
transposed_image = image.transpose(method)
|
transposed_image = image.transpose(method)
|
||||||
transposed_exif = transposed_image.getexif()
|
transposed_exif = transposed_image.getexif()
|
||||||
|
if 0x0112 in transposed_exif:
|
||||||
del transposed_exif[0x0112]
|
del transposed_exif[0x0112]
|
||||||
|
if "exif" in transposed_image.info:
|
||||||
transposed_image.info["exif"] = transposed_exif.tobytes()
|
transposed_image.info["exif"] = transposed_exif.tobytes()
|
||||||
|
elif "Raw profile type exif" in transposed_image.info:
|
||||||
|
transposed_image.info[
|
||||||
|
"Raw profile type exif"
|
||||||
|
] = transposed_exif.tobytes().hex()
|
||||||
|
elif "XML:com.adobe.xmp" in transposed_image.info:
|
||||||
|
transposed_image.info["XML:com.adobe.xmp"] = re.sub(
|
||||||
|
r'tiff:Orientation="([0-9])"',
|
||||||
|
"",
|
||||||
|
transposed_image.info["XML:com.adobe.xmp"],
|
||||||
|
)
|
||||||
return transposed_image
|
return transposed_image
|
||||||
return image.copy()
|
return image.copy()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user