Save xmp from info

This commit is contained in:
Andrew Murray 2024-09-04 19:19:39 +10:00
parent c056406f21
commit be34a7da4b
2 changed files with 5 additions and 3 deletions

View File

@ -995,11 +995,13 @@ class TestFileJpeg:
f = str(tmp_path / "temp.jpg") f = str(tmp_path / "temp.jpg")
im = hopper() im = hopper()
im.save(f, xmp=b"XMP test") im.save(f, xmp=b"XMP test")
with Image.open(f) as reloaded: with Image.open(f) as reloaded:
assert reloaded.info["xmp"] == b"XMP test" assert reloaded.info["xmp"] == b"XMP test"
im.save(f, xmp=b"1" * 65504) im.info["xmp"] = b"1" * 65504
im.save(f)
with Image.open(f) as reloaded:
assert reloaded.info["xmp"] == b"1" * 65504
with pytest.raises(ValueError): with pytest.raises(ValueError):
im.save(f, xmp=b"1" * 65505) im.save(f, xmp=b"1" * 65505)

View File

@ -747,7 +747,7 @@ def _save(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None:
extra = info.get("extra", b"") extra = info.get("extra", b"")
MAX_BYTES_IN_MARKER = 65533 MAX_BYTES_IN_MARKER = 65533
xmp = info.get("xmp") xmp = info.get("xmp", im.info.get("xmp"))
if xmp: if xmp:
overhead_len = 29 # b"http://ns.adobe.com/xap/1.0/\x00" overhead_len = 29 # b"http://ns.adobe.com/xap/1.0/\x00"
max_data_bytes_in_marker = MAX_BYTES_IN_MARKER - overhead_len max_data_bytes_in_marker = MAX_BYTES_IN_MARKER - overhead_len