Repository: scrapy/scrapy

Issue:
Webp images distort in image pipelines
<!--

Thanks for taking an interest in Scrapy!

If you have a question that starts with "How to...", please see the Scrapy Community page: https://scrapy.org/community/.
The GitHub issue tracker's purpose is to deal with bug reports and feature requests for the project itself.

Keep in mind that by filing an issue, you are expected to comply with Scrapy's Code of Conduct, including treating everyone with respect: https://github.com/scrapy/scrapy/blob/master/CODE_OF_CONDUCT.md

The following is a suggested template to structure your issue, you can find more guidelines at https://doc.scrapy.org/en/latest/contributing.html#reporting-bugs

-->

### Description

When a .webp image enters the [convert_image](https://github.com/scrapy/scrapy/blob/2.5/scrapy/pipelines/images.py#L147) routine, it gets distorted adding a black background.

### Steps to Reproduce

1. Get a [webp](https://www.atticadps.gr/images/w544/4/png/files/products/3605521816511/10.webp) image
2. Run a the pipeline
3. ![image](https://user-images.githubusercontent.com/4542013/208651539-1c99ea4c-a1d5-4a15-ab83-cfbe445f9c07.jpeg)


**Expected behavior:** An image without the blacked background

**Actual behavior:** A distorted image

**Reproduces how often:** Everytime for .webp images

### Versions

Please paste here the output of executing `scrapy version --verbose` in the command line.
```
2022-12-20 13:03:32 [scrapy.utils.log] INFO: Scrapy 2.5.1 started (bot: banners)
2022-12-20 13:03:32 [scrapy.utils.log] INFO: Versions: lxml 4.9.1.0, libxml2 2.9.14, cssselect 1.2.0, parsel 1.7.0, w3lib 2.1.0, Twisted 22.10.0, Python 3.9.1 (default, Jun  7 2022, 16:18:41) - [GCC 9.4.0], pyOpenSSL 22.0.0 (OpenSSL 3.0.7 1 Nov 2022), cryptography 38.0.4, Platform Linux-5.14.0-1054-oem-x86_64-with-glibc2.31
2022-12-20 13:03:32 [scrapy.utils.log] DEBUG: Using reactor: twisted.internet.epollreactor.EPollReactor
Scrapy       : 2.5.1
lxml         : 4.9.1.0
libxml2      : 2.9.14
cssselect    : 1.2.0
parsel       : 1.7.0
w3lib        : 2.1.0
Twisted      : 22.10.0
Python       : 3.9.1 (default, Jun  7 2022, 16:18:41) - [GCC 9.4.0]
pyOpenSSL    : 22.0.0 (OpenSSL 3.0.7 1 Nov 2022)
cryptography : 38.0.4
Platform     : Linux-5.14.0-1054-oem-x86_64-with-glibc2.31
```

### Additional context

Any additional information, configuration, data or output from commands that might be necessary to reproduce or understand the issue. Please try not to include screenshots of code or the command line, paste the contents as text instead. You can use [GitHub Flavored Markdown](https://help.github.com/en/articles/creating-and-highlighting-code-blocks) to make the text look better.



Discussion:

Resolving patch:
diff --git a/scrapy/pipelines/images.py b/scrapy/pipelines/images.py
--- a/scrapy/pipelines/images.py
+++ b/scrapy/pipelines/images.py
@@ -171,7 +171,7 @@ def convert_image(self, image, size=None, response_body=None):
                           'method called without response_body argument.',
                           category=ScrapyDeprecationWarning, stacklevel=2)
 
-        if image.format == 'PNG' and image.mode == 'RGBA':
+        if image.format in ('PNG', 'WEBP') and image.mode == 'RGBA':
             background = self._Image.new('RGBA', image.size, (255, 255, 255))
             background.paste(image, image)
             image = background.convert('RGB')


Test patch: