Do not save EXIF from info

This commit is contained in:
Andrew Murray 2022-12-23 12:10:36 +11:00
parent edcfe09f12
commit 88f15eb9f0
2 changed files with 11 additions and 3 deletions

View File

@ -706,10 +706,18 @@ class TestFilePng:
assert exif[274] == 3
def test_exif_save(self, tmp_path):
with Image.open("Tests/images/exif.png") as im:
# Test exif is not saved from info
test_file = str(tmp_path / "temp.png")
with Image.open("Tests/images/exif.png") as im:
im.save(test_file)
with Image.open(test_file) as reloaded:
assert reloaded._getexif() is None
# Test passing in exif
with Image.open("Tests/images/exif.png") as im:
im.save(test_file, exif=im.getexif())
with Image.open(test_file) as reloaded:
exif = reloaded._getexif()
assert exif[274] == 1
@ -720,7 +728,7 @@ class TestFilePng:
def test_exif_from_jpg(self, tmp_path):
with Image.open("Tests/images/pil_sample_rgb.jpg") as im:
test_file = str(tmp_path / "temp.png")
im.save(test_file)
im.save(test_file, exif=im.getexif())
with Image.open(test_file) as reloaded:
exif = reloaded._getexif()

View File

@ -1383,7 +1383,7 @@ def _save(im, fp, filename, chunk=putchunk, save_all=False):
chunks.remove(cid)
chunk(fp, cid, data)
exif = im.encoderinfo.get("exif", im.info.get("exif"))
exif = im.encoderinfo.get("exif")
if exif:
if isinstance(exif, Image.Exif):
exif = exif.tobytes(8)