Allow "exif" to also accept bytestring

This commit is contained in:
Andrew Murray 2021-07-04 13:32:41 +10:00
parent c0f619384c
commit 9707d33ed9
2 changed files with 17 additions and 1 deletions

View File

@ -444,10 +444,17 @@ class TestFileTiff:
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:

View File

@ -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()