mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-11 04:07:21 +03:00
Convert RGBA palette to RGBA image when saving WebP
This commit is contained in:
parent
6bbed1add0
commit
ad12caecda
|
@ -234,3 +234,13 @@ class TestFileWebp:
|
|||
|
||||
with Image.open(out_webp) as reloaded:
|
||||
assert reloaded.info["duration"] == 1000
|
||||
|
||||
def test_roundtrip_rgba_palette(self, tmp_path):
|
||||
temp_file = str(tmp_path / "temp.webp")
|
||||
im = Image.new("RGBA", (1, 1)).convert("P")
|
||||
assert im.mode == "P"
|
||||
assert im.palette.mode == "RGBA"
|
||||
im.save(temp_file)
|
||||
|
||||
with Image.open(temp_file) as im:
|
||||
assert im.getpixel((0, 0)) == (0, 0, 0, 0)
|
||||
|
|
|
@ -332,12 +332,7 @@ def _save(im, fp, filename):
|
|||
exact = 1 if im.encoderinfo.get("exact") else 0
|
||||
|
||||
if im.mode not in _VALID_WEBP_LEGACY_MODES:
|
||||
alpha = (
|
||||
"A" in im.mode
|
||||
or "a" in im.mode
|
||||
or (im.mode == "P" and "transparency" in im.info)
|
||||
)
|
||||
im = im.convert("RGBA" if alpha else "RGB")
|
||||
im = im.convert("RGBA" if im.has_transparency_data() else "RGB")
|
||||
|
||||
data = _webp.WebPEncode(
|
||||
im.tobytes(),
|
||||
|
|
Loading…
Reference in New Issue
Block a user