Skip to content

Commit

Permalink
Allow "exif" to also accept bytestring
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Jul 4, 2021
1 parent c0f6193 commit 9707d33
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Tests/test_file_tiff.py
Expand Up @@ -444,10 +444,17 @@ def check_exif(exif):

im.save(outfile, exif=exif)

outfile2 = str(tmp_path / "temp2.tif")
with Image.open(outfile) as im:
exif = im.getexif()
check_exif(exif)

im.save(outfile2, exif=exif.tobytes())

with Image.open(outfile2) as im:
exif = im.getexif()
check_exif(exif)

def test_exif_frames(self):
# Test that EXIF data can change across frames
with Image.open("Tests/images/g4-multi.tiff") as im:
Expand Down
11 changes: 10 additions & 1 deletion src/PIL/TiffImagePlugin.py
Expand Up @@ -1515,7 +1515,16 @@ def _save(im, fp, filename):
ifd[IMAGELENGTH] = im.size[1]

# write any arbitrary tags passed in as an ImageFileDirectory
info = im.encoderinfo.get("tiffinfo", im.encoderinfo.get("exif", {}))
if "tiffinfo" in im.encoderinfo:
info = im.encoderinfo["tiffinfo"]
elif "exif" in im.encoderinfo:
info = im.encoderinfo["exif"]
if isinstance(info, bytes):
exif = Image.Exif()
exif.load(info)
info = exif
else:
info = {}
logger.debug("Tiffinfo Keys: %s" % list(info))
if isinstance(info, ImageFileDirectory_v1):
info = info.to_v2()
Expand Down

0 comments on commit 9707d33

Please sign in to comment.