Skip to content

Commit

Permalink
Merge pull request #6294 from raygard/comments_separate_multiple
Browse files Browse the repository at this point in the history
Separate multiple GIF comment blocks in a frame with newlines
  • Loading branch information
radarhere committed May 22, 2022
2 parents 22d797f + 62d5817 commit e9cb215
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
Binary file added Tests/images/multiple_comments.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions Tests/test_file_gif.py
Expand Up @@ -831,6 +831,12 @@ def test_zero_comment_subblocks():
assert_image_equal_tofile(im, TEST_GIF)


def test_read_multiple_comment_blocks():
with Image.open("Tests/images/multiple_comments.gif") as im:
# Multiple comment blocks in a frame are separated not concatenated
assert im.info["comment"] == b"Test comment 1\nTest comment 2"


def test_version(tmp_path):
out = str(tmp_path / "temp.gif")

Expand Down
14 changes: 10 additions & 4 deletions src/PIL/GifImagePlugin.py
Expand Up @@ -228,12 +228,18 @@ def _seek(self, frame, update_image=True):
#
# comment extension
#
comment = b""

# Collect one comment block
while block:
if "comment" in info:
info["comment"] += block
else:
info["comment"] = block
comment += block
block = self.data()

if "comment" in info:
# If multiple comment blocks in frame, separate with \n
info["comment"] += b"\n" + comment
else:
info["comment"] = comment
s = None
continue
elif s[0] == 255:
Expand Down

0 comments on commit e9cb215

Please sign in to comment.