Multiple GIF comments in a frame are separated

If more than one comment is in a GIF frame, separate them with \r\n in the info dict.
This commit is contained in:
Ray Gardner 2022-05-13 11:38:39 -06:00
parent c4325c805e
commit 44c6467400
3 changed files with 15 additions and 4 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -813,6 +813,12 @@ def test_zero_comment_subblocks():
assert_image_equal_tofile(im, TEST_GIF)
def test_read_multiple_comments():
with Image.open("Tests/images/multiple_comments.gif") as im:
# Multiple comments in a frame are separated not concatenated
assert im.info["comment"] == b"Test comment 1\r\nTest comment 2"
def test_version(tmp_path):
out = str(tmp_path / "temp.gif")

View File

@ -228,12 +228,17 @@ class GifImageFile(ImageFile.ImageFile):
#
# comment extension
#
# Collect one comment block
comment = b""
while block:
if "comment" in info:
info["comment"] += block
else:
info["comment"] = block
comment += block
block = self.data()
# If multiple comments in frame, separate in info with \r\n
if "comment" in info:
info["comment"] += b"\r\n" + comment
else:
info["comment"] = comment
s = None
continue
elif s[0] == 255: