Skip to content

Commit

Permalink
If previous disposal was 2, do not fill identical pixels
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Feb 9, 2024
1 parent 6782a07 commit e6a5211
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Tests/test_file_gif.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,9 @@ def test_dispose2_palette(tmp_path: Path) -> None:
# Center remains red every frame
assert rgb_img.getpixel((50, 50)) == circle

# Check that frame transparency wasn't added unnecessarily
assert img._frame_transparency is None


def test_dispose2_diff(tmp_path: Path) -> None:
out = str(tmp_path / "temp.gif")
Expand Down
6 changes: 5 additions & 1 deletion src/PIL/GifImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,11 @@ def _write_multiple_frames(im, fp, palette):
background_im = Image.new("P", im_frame.size, background)
background_im.putpalette(im_frames[0]["im"].palette)
delta, bbox = _getbbox(background_im, im_frame)
if encoderinfo.get("optimize") and im_frame.mode != "1":
if (
encoderinfo.get("optimize")
and im_frames[-1]["encoderinfo"].get("disposal") != 2
and im_frame.mode != "1"
):
if "transparency" not in encoderinfo:
try:
encoderinfo["transparency"] = (
Expand Down

0 comments on commit e6a5211

Please sign in to comment.