Restore original encoderinfo after saving

This commit is contained in:
Andrew Murray 2025-05-03 00:52:35 +10:00
parent 07df26aa5d
commit 0e292a80c8
2 changed files with 6 additions and 5 deletions

View File

@ -315,6 +315,9 @@ def test_save_xmp() -> None:
im2.encoderinfo = {"xmp": b"Second frame"}
im_reloaded = roundtrip(im, xmp=b"First frame", save_all=True, append_images=[im2])
# Test that encoderinfo is unchanged
assert im2.encoderinfo == {"xmp": b"Second frame"}
assert im_reloaded.info["xmp"] == b"First frame"
im_reloaded.seek(1)

View File

@ -2551,7 +2551,8 @@ class Image:
self.load()
save_all = params.pop("save_all", None)
self.encoderinfo = {**getattr(self, "encoderinfo", {}), **params}
encoderinfo = getattr(self, "encoderinfo", {})
self.encoderinfo = {**encoderinfo, **params}
self.encoderconfig: tuple[Any, ...] = ()
if format.upper() not in SAVE:
@ -2589,10 +2590,7 @@ class Image:
pass
raise
finally:
try:
del self.encoderinfo
except AttributeError:
pass
self.encoderinfo = encoderinfo
if open_fp:
fp.close()