mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-24 17:06:16 +03:00
support round-tripping JPEG comments
This commit is contained in:
parent
5bdf63e1d1
commit
d822d85af6
|
@ -87,6 +87,18 @@ class TestFileJpeg:
|
|||
|
||||
assert im.info["comment"] == b"File written by Adobe Photoshop\xa8 4.0\x00"
|
||||
|
||||
def test_com_write(self):
|
||||
dummy_text = "this is a test comment"
|
||||
with Image.open(TEST_FILE) as im:
|
||||
with BytesIO() as buf:
|
||||
im.save(buf, format="JPEG")
|
||||
with Image.open(buf) as im2:
|
||||
assert im.app['COM'] == im2.app['COM']
|
||||
with BytesIO() as buf:
|
||||
im.save(buf, format="JPEG", comment=dummy_text)
|
||||
with Image.open(buf) as im2:
|
||||
assert im2.app['COM'].decode() == dummy_text
|
||||
|
||||
def test_cmyk(self):
|
||||
# Test CMYK handling. Thanks to Tim and Charlie for test data,
|
||||
# Michael for getting me to look one more time.
|
||||
|
|
|
@ -44,6 +44,7 @@ import warnings
|
|||
from . import Image, ImageFile, TiffImagePlugin
|
||||
from ._binary import i16be as i16
|
||||
from ._binary import i32be as i32
|
||||
from ._binary import o16be as o16
|
||||
from ._binary import o8
|
||||
from ._deprecate import deprecate
|
||||
from .JpegPresets import presets
|
||||
|
@ -713,6 +714,15 @@ def _save(im, fp, filename):
|
|||
|
||||
extra = info.get("extra", b"")
|
||||
|
||||
comment = info.get("comment")
|
||||
if comment is None and isinstance(im, JpegImageFile):
|
||||
comment = im.app.get('COM')
|
||||
if comment:
|
||||
if isinstance(comment, str):
|
||||
comment = comment.encode()
|
||||
size = o16(2 + len(comment))
|
||||
extra += b'\xFF\xFE%s%s' % (size, comment)
|
||||
|
||||
icc_profile = info.get("icc_profile")
|
||||
if icc_profile:
|
||||
ICC_OVERHEAD_LEN = 14
|
||||
|
|
Loading…
Reference in New Issue
Block a user