Skip to content

Commit

Permalink
Merge pull request python-pillow#7284 from radarhere/gif
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk authored Jul 13, 2023
2 parents 5b3c204 + a682cea commit 7a2510c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
15 changes: 15 additions & 0 deletions Tests/test_file_gif.py
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,21 @@ def test_transparent_optimize(tmp_path):
assert reloaded.info["transparency"] == reloaded.getpixel((252, 0))


def test_removed_transparency(tmp_path):
out = str(tmp_path / "temp.gif")
im = Image.new("RGB", (256, 1))

for x in range(256):
im.putpixel((x, 0), (x, 0, 0))

im.info["transparency"] = (255, 255, 255)
with pytest.warns(UserWarning):
im.save(out)

with Image.open(out) as reloaded:
assert "transparency" not in reloaded.info


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

Expand Down
6 changes: 1 addition & 5 deletions src/PIL/GifImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,11 +683,7 @@ def get_interlace(im):
def _write_local_header(fp, im, offset, flags):
transparent_color_exists = False
try:
if "transparency" in im.encoderinfo:
transparency = im.encoderinfo["transparency"]
else:
transparency = im.info["transparency"]
transparency = int(transparency)
transparency = int(im.encoderinfo["transparency"])
except (KeyError, ValueError):
pass
else:
Expand Down

0 comments on commit 7a2510c

Please sign in to comment.