mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-26 09:14:27 +03:00
Allow string comment when saving GIF
This commit is contained in:
parent
94ec95c571
commit
e8bb2dd93e
|
@ -565,14 +565,18 @@ class TestFileGif(PillowTestCase):
|
|||
im.info["comment"], b"File written by Adobe Photoshop\xa8 4.0"
|
||||
)
|
||||
|
||||
out = self.tempfile("temp.gif")
|
||||
im = Image.new("L", (100, 100), "#000")
|
||||
im.info["comment"] = b"Test comment text"
|
||||
im.save(out)
|
||||
out = self.tempfile("temp.gif")
|
||||
im = Image.new("L", (100, 100), "#000")
|
||||
im.info["comment"] = b"Test comment text"
|
||||
im.save(out)
|
||||
with Image.open(out) as reread:
|
||||
|
||||
self.assertEqual(reread.info["comment"], im.info["comment"])
|
||||
|
||||
im.info["comment"] = "Test comment text"
|
||||
im.save(out)
|
||||
with Image.open(out) as reread:
|
||||
self.assertEqual(reread.info["comment"], im.info["comment"].encode())
|
||||
|
||||
def test_comment_over_255(self):
|
||||
out = self.tempfile("temp.gif")
|
||||
im = Image.new("L", (100, 100), "#000")
|
||||
|
|
|
@ -569,8 +569,11 @@ def _write_local_header(fp, im, offset, flags):
|
|||
|
||||
if "comment" in im.encoderinfo and 1 <= len(im.encoderinfo["comment"]):
|
||||
fp.write(b"!" + o8(254)) # extension intro
|
||||
for i in range(0, len(im.encoderinfo["comment"]), 255):
|
||||
subblock = im.encoderinfo["comment"][i : i + 255]
|
||||
comment = im.encoderinfo["comment"]
|
||||
if isinstance(comment, str):
|
||||
comment = comment.encode()
|
||||
for i in range(0, len(comment), 255):
|
||||
subblock = comment[i : i + 255]
|
||||
fp.write(o8(len(subblock)) + subblock)
|
||||
fp.write(o8(0))
|
||||
if "loop" in im.encoderinfo:
|
||||
|
|
Loading…
Reference in New Issue
Block a user