Skip to content

Commit e6a5211

Browse files
committed
If previous disposal was 2, do not fill identical pixels
1 parent 6782a07 commit e6a5211

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

Tests/test_file_gif.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,9 @@ def test_dispose2_palette(tmp_path: Path) -> None:
647647
# Center remains red every frame
648648
assert rgb_img.getpixel((50, 50)) == circle
649649

650+
# Check that frame transparency wasn't added unnecessarily
651+
assert img._frame_transparency is None
652+
650653

651654
def test_dispose2_diff(tmp_path: Path) -> None:
652655
out = str(tmp_path / "temp.gif")

src/PIL/GifImagePlugin.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,11 @@ def _write_multiple_frames(im, fp, palette):
638638
background_im = Image.new("P", im_frame.size, background)
639639
background_im.putpalette(im_frames[0]["im"].palette)
640640
delta, bbox = _getbbox(background_im, im_frame)
641-
if encoderinfo.get("optimize") and im_frame.mode != "1":
641+
if (
642+
encoderinfo.get("optimize")
643+
and im_frames[-1]["encoderinfo"].get("disposal") != 2
644+
and im_frame.mode != "1"
645+
):
642646
if "transparency" not in encoderinfo:
643647
try:
644648
encoderinfo["transparency"] = (

0 commit comments

Comments
 (0)