mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-14 09:14:45 +03:00
Unittests for exif preservation in formats jpeg, tiff and webp added
This commit is contained in:
parent
825a54ca31
commit
5e212e2956
|
@ -442,6 +442,17 @@ class TestFileJpeg:
|
||||||
info = im._getexif()
|
info = im._getexif()
|
||||||
assert info[305] == "Adobe Photoshop CS Macintosh"
|
assert info[305] == "Adobe Photoshop CS Macintosh"
|
||||||
|
|
||||||
|
def test_exif_keep(self, tmp_path):
|
||||||
|
with Image.open("Tests/images/pil_sample_rgb.jpg") as im:
|
||||||
|
f = str(tmp_path / "temp.jpg")
|
||||||
|
im.save(f)
|
||||||
|
|
||||||
|
with Image.open(f) as new_im:
|
||||||
|
orig_info = im._getexif()
|
||||||
|
new_info = new_im._getexif()
|
||||||
|
|
||||||
|
assert orig_info == new_info
|
||||||
|
|
||||||
def test_get_child_images(self):
|
def test_get_child_images(self):
|
||||||
with Image.open("Tests/images/flower.jpg") as im:
|
with Image.open("Tests/images/flower.jpg") as im:
|
||||||
ims = im.get_child_images()
|
ims = im.get_child_images()
|
||||||
|
|
|
@ -530,6 +530,18 @@ class TestFileTiff:
|
||||||
exif = im.getexif()
|
exif = im.getexif()
|
||||||
assert exif[256] == 100
|
assert exif[256] == 100
|
||||||
|
|
||||||
|
def test_exif_keep(self, tmp_path):
|
||||||
|
with Image.open("Tests/images/ifd_tag_type.tiff") as orig_im:
|
||||||
|
orig_exif = orig_im.getexif()
|
||||||
|
assert orig_exif[271] == "FLIR"
|
||||||
|
|
||||||
|
f = str(tmp_path / "temp.tif")
|
||||||
|
orig_im.save(f)
|
||||||
|
|
||||||
|
with Image.open(f) as new_im:
|
||||||
|
new_exif = new_im.getexif()
|
||||||
|
assert orig_exif[271] == new_exif[271]
|
||||||
|
|
||||||
def test_reload_exif_after_seek(self):
|
def test_reload_exif_after_seek(self):
|
||||||
with Image.open("Tests/images/multipage.tiff") as im:
|
with Image.open("Tests/images/multipage.tiff") as im:
|
||||||
exif = im.getexif()
|
exif = im.getexif()
|
||||||
|
|
|
@ -119,6 +119,18 @@ class TestFileWebp:
|
||||||
reloaded.seek(1)
|
reloaded.seek(1)
|
||||||
assert_image_similar(im2, reloaded, 1)
|
assert_image_similar(im2, reloaded, 1)
|
||||||
|
|
||||||
|
def test_exif_keep(self, tmp_path):
|
||||||
|
with Image.open("Tests/images/flower.webp") as orig_im:
|
||||||
|
orig_exif = orig_im.getexif()
|
||||||
|
f = str(tmp_path / "exif_img.webp")
|
||||||
|
orig_im.save(f)
|
||||||
|
|
||||||
|
with Image.open(f) as new_im:
|
||||||
|
new_exif = new_im.getexif()
|
||||||
|
|
||||||
|
assert orig_exif[271] == "Canon"
|
||||||
|
assert orig_exif[271] == new_exif[271]
|
||||||
|
|
||||||
def test_icc_profile(self, tmp_path):
|
def test_icc_profile(self, tmp_path):
|
||||||
self._roundtrip(tmp_path, self.rgb_mode, 12.5, {"icc_profile": None})
|
self._roundtrip(tmp_path, self.rgb_mode, 12.5, {"icc_profile": None})
|
||||||
if _webp.HAVE_WEBPANIM:
|
if _webp.HAVE_WEBPANIM:
|
||||||
|
|
|
@ -1602,7 +1602,7 @@ def _save(im, fp, filename):
|
||||||
if "tiffinfo" in encoderinfo:
|
if "tiffinfo" in encoderinfo:
|
||||||
info = encoderinfo["tiffinfo"]
|
info = encoderinfo["tiffinfo"]
|
||||||
else:
|
else:
|
||||||
info = encoderinfo.get("exif", im.info.get("exif", b""))
|
info = encoderinfo.get("exif", im.info.get("exif", im.getexif()))
|
||||||
if isinstance(info, bytes):
|
if isinstance(info, bytes):
|
||||||
exif = Image.Exif()
|
exif = Image.Exif()
|
||||||
exif.load(info)
|
exif.load(info)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user