diff --git a/Tests/test_file_jpeg.py b/Tests/test_file_jpeg.py index f9c5fbc0b..c8981ce85 100644 --- a/Tests/test_file_jpeg.py +++ b/Tests/test_file_jpeg.py @@ -995,11 +995,13 @@ class TestFileJpeg: f = str(tmp_path / "temp.jpg") im = hopper() im.save(f, xmp=b"XMP test") - with Image.open(f) as reloaded: 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): im.save(f, xmp=b"1" * 65505) diff --git a/src/PIL/JpegImagePlugin.py b/src/PIL/JpegImagePlugin.py index 0cb50e0bf..723165ec4 100644 --- a/src/PIL/JpegImagePlugin.py +++ b/src/PIL/JpegImagePlugin.py @@ -747,7 +747,7 @@ def _save(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None: extra = info.get("extra", b"") MAX_BYTES_IN_MARKER = 65533 - xmp = info.get("xmp") + xmp = info.get("xmp", im.info.get("xmp")) if xmp: overhead_len = 29 # b"http://ns.adobe.com/xap/1.0/\x00" max_data_bytes_in_marker = MAX_BYTES_IN_MARKER - overhead_len