Skip to content

Commit 44c6467

Browse files
committed
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.
1 parent c4325c8 commit 44c6467

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

Tests/images/multiple_comments.gif

1.5 KB
Loading

Tests/test_file_gif.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,12 @@ def test_zero_comment_subblocks():
813813
assert_image_equal_tofile(im, TEST_GIF)
814814

815815

816+
def test_read_multiple_comments():
817+
with Image.open("Tests/images/multiple_comments.gif") as im:
818+
# Multiple comments in a frame are separated not concatenated
819+
assert im.info["comment"] == b"Test comment 1\r\nTest comment 2"
820+
821+
816822
def test_version(tmp_path):
817823
out = str(tmp_path / "temp.gif")
818824

src/PIL/GifImagePlugin.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,12 +228,17 @@ def _seek(self, frame, update_image=True):
228228
#
229229
# comment extension
230230
#
231+
# Collect one comment block
232+
comment = b""
231233
while block:
232-
if "comment" in info:
233-
info["comment"] += block
234-
else:
235-
info["comment"] = block
234+
comment += block
236235
block = self.data()
236+
237+
# If multiple comments in frame, separate in info with \r\n
238+
if "comment" in info:
239+
info["comment"] += b"\r\n" + comment
240+
else:
241+
info["comment"] = comment
237242
s = None
238243
continue
239244
elif s[0] == 255:

0 commit comments

Comments
 (0)