Repository: python-pillow/Pillow

Issue:
Saving animated GIF as WebP raises "Background color" error
### What did you do?
  convert a animate gif format to animate webP format

### What did you expect to happen?
convert success

### What actually happened?
osError happen
```
Traceback (most recent call last):
  File "/Users/jeevi/Documents/WWW/study/python/pillow_img/img/img.py", line 197, in <module>
    im.save(bts, "webP", save_all=True, quality=75,  optimize=True)
  File "/Users/jeevi/Documents/WWW/study/python/pillow_img/python/lib/python3.7/site-packages/PIL/Image.py", line 2240, in save
    save_handler(self, fp, filename)
  File "/Users/jeevi/Documents/WWW/study/python/pillow_img/python/lib/python3.7/site-packages/PIL/WebPImagePlugin.py", line 227, in _save_all
    % str(background)
OSError: Background color is not an RGBA tuple clamped to (0-255): 255

```
### What are your OS, Python and Pillow versions?

* OS:  macos Monterey version 12.2.1
* Python: 3.7.11
* Pillow: 8.4.0

<!--
Please include **code** that reproduces the issue and whenever possible, an **image** that demonstrates the issue. Please upload images to GitHub, not to third-party file hosting sites. If necessary, add the image to a zip or tar archive.

The best reproductions are self-contained scripts with minimal dependencies. If you are using a framework such as Plone, Django, or Buildout, try to replicate the issue just using Pillow.
-->

use picture
![YD_cnt_11_019HNWhSb3SJ](https://user-images.githubusercontent.com/12953391/159218154-53eecdce-f685-4af4-960e-e2985edb44e4.gif)

```python
 file = "./YD_cnt_11_019HNWhSb3SJ.gif"
    t = time.time()
    with Image.open(file) as im:
        print("info:", im.info)
        bts = BytesIO()
        im.save(bts, "webP", save_all=True, quality=75,  optimize=True)
        print("长度:{} \n".format(len(bts.getvalue())))
        with open("YD_cnt_11_019HNWhSb3SJ.gif.webP", "wb") as f:
            f.write(bts.getvalue())
        t2 = time.time()
        cost = int(round(t2 * 1000)) - int(round(t * 1000))
        print("耗时:{}ms\n".format(cost))
```
print info: `{'version': b'GIF89a', 'background': 255, 'duration': 160, 'extension': (b'NETSCAPE2.0', 803), 'loop': 0}`

i found load gif the background value is 255   and palette is no   

webP plugin code can not support 
https://github.com/python-pillow/Pillow/blob/15dc2914692c9c19270b4fd55fa6226a94b17647/src/PIL/WebPImagePlugin.py#L183-L194

error line
https://github.com/python-pillow/Pillow/blob/15dc2914692c9c19270b4fd55fa6226a94b17647/src/PIL/WebPImagePlugin.py#L220-L229

imagemagick get background is white
```
 Rendering intent: Perceptual
  Gamma: 0.454545
  Chromaticity:
    red primary: (0.64,0.33)
    green primary: (0.3,0.6)
    blue primary: (0.15,0.06)
    white point: (0.3127,0.329)
  Matte color: grey74
  Background color: white
  Border color: srgb(223,223,223)
  Transparent color: none
  Interlace: None
  Intensity: Undefined
  Compose: Over
  Page geometry: 440x261+0+0
  Dispose: None
  Delay: 16x100
  Iterations: 0
  Scene: 18 of 19
  Compression: LZW
  Orientation: Undefined
  Properties:
    date:create: 2022-03-18T09:24:11+00:00
    date:modify: 2022-03-18T09:24:02+00:00
    signature: 34c9a1dea7efa1fa2e31c58a9483d118b808f13774f8e2619dcad80c1cec2119
  Artifacts:
    verbose: true
  Tainted: False
  Filesize: 951740B
  Number pixels: 114840
  Pixels per second: 61879P
  User time: 1.830u
  Elapsed time: 0:02.855
  Version: ImageMagick 7.1.0-4 Q16 x86_64 2021-07-18 https://imagemagick.org
```

use pillow i open gif and save gif is success 

**i think webP plugin can't compatibility background scene**


Discussion:

Resolving patch:
diff --git a/src/PIL/WebPImagePlugin.py b/src/PIL/WebPImagePlugin.py
--- a/src/PIL/WebPImagePlugin.py
+++ b/src/PIL/WebPImagePlugin.py
@@ -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", 0))
     loop = im.encoderinfo.get("loop", 0)


Test patch:
diff --git a/Tests/images/no_palette_with_background.gif b/Tests/images/no_palette_with_background.gif
new file mode 100644
Binary files /dev/null and b/Tests/images/no_palette_with_background.gif differ
diff --git a/Tests/test_file_webp.py b/Tests/test_file_webp.py
--- a/Tests/test_file_webp.py
+++ b/Tests/test_file_webp.py
@@ -187,6 +187,12 @@ def test_file_pointer_could_be_reused(self):
 
     @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))