Skip to content
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

Add JPEG comment to info dictionary #4455

Merged
merged 1 commit into from Mar 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions Tests/test_file_jpeg.py
Expand Up @@ -60,6 +60,8 @@ def test_app(self):
)
assert len(im.applist) == 2

assert im.info["comment"] == b"File written by Adobe Photoshop\xa8 4.0\x00"

def test_cmyk(self):
# Test CMYK handling. Thanks to Tim and Charlie for test data,
# Michael for getting me to look one more time.
Expand Down
5 changes: 5 additions & 0 deletions docs/handbook/image-file-formats.rst
Expand Up @@ -298,6 +298,11 @@ The :py:meth:`~PIL.Image.Image.open` method may set the following
**exif**
Raw EXIF data from the image.

**comment**
A comment about the image.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have a "New in version 7.1.0."?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. Done


.. versionadded:: 7.1.0


The :py:meth:`~PIL.Image.Image.save` method supports the following options:

Expand Down
9 changes: 9 additions & 0 deletions docs/releasenotes/7.1.0.rst
Expand Up @@ -18,6 +18,15 @@ been resolved.
im = Image.open("hopper.jpg")
im.save("out.jpg", quality=0)

API Additions
=============

Reading JPEG comments
^^^^^^^^^^^^^^^^^^^^^

When opening a JPEG image, the comment may now be read into
:py:attr:`~PIL.Image.Image.info`.

Other Changes
=============

Expand Down
1 change: 1 addition & 0 deletions src/PIL/JpegImagePlugin.py
Expand Up @@ -176,6 +176,7 @@ def COM(self, marker):
n = i16(self.fp.read(2)) - 2
s = ImageFile._safe_read(self.fp, n)

self.info["comment"] = s
self.app["COM"] = s # compatibility
self.applist.append(("COM", s))

Expand Down