Skip to content

Added writing XMP bytes to JPEG #8286

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Added writing XMP bytes to JPEG
  • Loading branch information
radarhere committed Aug 5, 2024
commit 2722cfd72b6b458f709d71c2ef06e9949cf3bbe2
7 changes: 7 additions & 0 deletions Tests/test_file_jpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,13 @@ def test_getxmp_padded(self) -> None:
else:
assert im.getxmp() == {"xmpmeta": None}

def test_save_xmp(self, tmp_path: Path) -> None:
f = str(tmp_path / "temp.jpg")
hopper().save(f, xmp=b"XMP test")

with Image.open(f) as reloaded:
assert reloaded.info["xmp"] == b"XMP test"

@pytest.mark.timeout(timeout=1)
def test_eof(self) -> None:
# Even though this decoder never says that it is finished
Expand Down
5 changes: 5 additions & 0 deletions src/PIL/JpegImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,11 @@ def validate_qtables(

extra = info.get("extra", b"")

xmp = info.get("xmp")
if xmp:
size = o16(31 + len(xmp))
extra += b"\xFF\xE1" + size + b"http://ns.adobe.com/xap/1.0/\x00" + xmp

MAX_BYTES_IN_MARKER = 65533
icc_profile = info.get("icc_profile")
if icc_profile:
Expand Down
Loading