From 31d36e6b70e1e835bcc6d70f363cda49d3bc9e98 Mon Sep 17 00:00:00 2001 From: Aleksandr Karpinskii Date: Mon, 16 Sep 2024 11:04:00 +0200 Subject: [PATCH] Use current frame for transparency detection --- Tests/test_file_webp.py | 2 +- src/PIL/WebPImagePlugin.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Tests/test_file_webp.py b/Tests/test_file_webp.py index 719831db9fb..e7c88727966 100644 --- a/Tests/test_file_webp.py +++ b/Tests/test_file_webp.py @@ -208,7 +208,7 @@ def test_invalid_background( def test_background_from_gif(self, tmp_path: Path) -> None: out_webp = tmp_path / "temp.webp" - + # Save L mode GIF with background with Image.open("Tests/images/no_palette_with_background.gif") as im: im.save(out_webp, save_all=True) diff --git a/src/PIL/WebPImagePlugin.py b/src/PIL/WebPImagePlugin.py index ab545563f7f..1a714d7ea34 100644 --- a/src/PIL/WebPImagePlugin.py +++ b/src/PIL/WebPImagePlugin.py @@ -243,7 +243,9 @@ def _save_all(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None: # Make sure image mode is supported frame = ims if frame.mode not in ("RGBX", "RGBA", "RGB"): - frame = frame.convert("RGBA" if im.has_transparency_data else "RGB") + frame = frame.convert( + "RGBA" if frame.has_transparency_data else "RGB" + ) # Append the frame to the animation encoder enc.add(