Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not use EXIF from info when saving PNG images #6819

Merged
merged 1 commit into from Dec 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions Tests/test_file_png.py
Expand Up @@ -706,10 +706,18 @@ def test_exif(self):
assert exif[274] == 3

def test_exif_save(self, tmp_path):
# Test exif is not saved from info
test_file = str(tmp_path / "temp.png")
with Image.open("Tests/images/exif.png") as im:
test_file = str(tmp_path / "temp.png")
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
Expand All @@ -720,7 +728,7 @@ def test_exif_save(self, tmp_path):
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()
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/PngImagePlugin.py
Expand Up @@ -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)
Expand Down