Skip to content

Commit

Permalink
Merge pull request #1 from radarhere/comment_use_gif89a
Browse files Browse the repository at this point in the history
Simplified version check
  • Loading branch information
raygard committed May 20, 2022
2 parents b3d29e9 + 138bd28 commit 882c04b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
6 changes: 5 additions & 1 deletion Tests/test_file_gif.py
Expand Up @@ -794,6 +794,9 @@ def test_comment(tmp_path):
with Image.open(out) as reread:
assert reread.info["comment"] == im.info["comment"].encode()

# Test that GIF89a is used for comments
assert reread.info["version"] == b"GIF89a"


def test_comment_over_255(tmp_path):
out = str(tmp_path / "temp.gif")
Expand All @@ -805,7 +808,8 @@ def test_comment_over_255(tmp_path):
im.save(out)
with Image.open(out) as reread:
assert reread.info["comment"] == comment
# Test that GIF89a is used for long comment

# Test that GIF89a is used for comments
assert reread.info["version"] == b"GIF89a"


Expand Down
21 changes: 10 additions & 11 deletions src/PIL/GifImagePlugin.py
Expand Up @@ -912,17 +912,16 @@ def _get_global_header(im, info):
# https://www.matthewflickinger.com/lab/whatsinagif/bits_and_bytes.asp

version = b"87a"
for extensionKey in ["transparency", "duration", "loop", "comment"]:
if info and extensionKey in info:
if (extensionKey == "duration" and info[extensionKey] == 0) or (
extensionKey == "comment" and len(info[extensionKey]) == 0
):
continue
version = b"89a"
break
else:
if im.info.get("version") == b"89a":
version = b"89a"
if im.info.get("version") == b"89a" or (
info
and (
"transparency" in info
or "loop" in info
or info.get("duration")
or info.get("comment")
)
):
version = b"89a"

background = _get_background(im, info.get("background"))

Expand Down

0 comments on commit 882c04b

Please sign in to comment.