Skip to content

Commit 8af2d76

Browse files
committed
Pass palette mode to putpalette
1 parent 822ec3d commit 8af2d76

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

Tests/test_file_gif.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from collections.abc import Generator
55
from io import BytesIO
66
from pathlib import Path
7+
from typing import Any
78

89
import pytest
910

@@ -1431,7 +1432,8 @@ def test_saving_rgba(tmp_path: Path) -> None:
14311432
assert reloaded_rgba.load()[0, 0][3] == 0
14321433

14331434

1434-
def test_optimizing_p_rgba(tmp_path: Path) -> None:
1435+
@pytest.mark.parametrize("params", ({}, {"disposal": 2, "optimize": False}))
1436+
def test_p_rgba(tmp_path: Path, params: dict[str, Any]) -> None:
14351437
out = str(tmp_path / "temp.gif")
14361438

14371439
im1 = Image.new("P", (100, 100))
@@ -1443,7 +1445,7 @@ def test_optimizing_p_rgba(tmp_path: Path) -> None:
14431445
im2 = Image.new("P", (100, 100))
14441446
im2.putpalette(data, "RGBA")
14451447

1446-
im1.save(out, save_all=True, append_images=[im2])
1448+
im1.save(out, save_all=True, append_images=[im2], **params)
14471449

14481450
with Image.open(out) as reloaded:
14491451
assert reloaded.n_frames == 2

src/PIL/GifImagePlugin.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,8 +695,9 @@ def _write_multiple_frames(
695695
)
696696
background = _get_background(im_frame, color)
697697
background_im = Image.new("P", im_frame.size, background)
698-
assert im_frames[0].im.palette is not None
699-
background_im.putpalette(im_frames[0].im.palette)
698+
first_palette = im_frames[0].im.palette
699+
assert first_palette is not None
700+
background_im.putpalette(first_palette, first_palette.mode)
700701
bbox = _getbbox(background_im, im_frame)[1]
701702
elif encoderinfo.get("optimize") and im_frame.mode != "1":
702703
if "transparency" not in encoderinfo:

0 commit comments

Comments
 (0)