If previous disposal was 2, do not fill identical pixels

This commit is contained in:
Andrew Murray 2024-02-09 19:47:09 +11:00
parent 6782a07b8e
commit e6a521130e
2 changed files with 8 additions and 1 deletions

View File

@ -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")

View File

@ -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"] = (