Skip to content

Commit

Permalink
Merge pull request #6819 from radarhere/png_exif
Browse files Browse the repository at this point in the history
Resolves #6804
  • Loading branch information
hugovk committed Dec 23, 2022
2 parents e0eca1f + 88f15eb commit 54eb835
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
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

0 comments on commit 54eb835

Please sign in to comment.