Skip to content

Commit

Permalink
Fixed saving L mode GIF with background as WebP
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Mar 21, 2022
1 parent 15dc291 commit 4e60811
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
Binary file added Tests/images/no_palette_with_background.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions Tests/test_file_webp.py
Expand Up @@ -174,6 +174,12 @@ def test_file_pointer_could_be_reused(self):
@skip_unless_feature("webp")
@skip_unless_feature("webp_anim")
def test_background_from_gif(self, tmp_path):
# Save L mode GIF with background
with Image.open("Tests/images/no_palette_with_background.gif") as im:
out_webp = str(tmp_path / "temp.webp")
im.save(out_webp, save_all=True)

# Save P mode GIF with background
with Image.open("Tests/images/chi.gif") as im:
original_value = im.convert("RGB").getpixel((1, 1))

Expand Down
4 changes: 3 additions & 1 deletion src/PIL/WebPImagePlugin.py
Expand Up @@ -190,7 +190,9 @@ def _save_all(im, fp, filename):
palette = im.getpalette()
if palette:
r, g, b = palette[background * 3 : (background + 1) * 3]
background = (r, g, b, 0)
background = (r, g, b, 255)
else:
background = (background, background, background, 255)

duration = im.encoderinfo.get("duration", im.info.get("duration"))
loop = im.encoderinfo.get("loop", 0)
Expand Down

0 comments on commit 4e60811

Please sign in to comment.