Skip to content

Incorrect transparency after converting indexed image to RGB #7288

@nedbat

Description

@nedbat

What did you do?

I use Pillow to convert images on my web site on-demand to .webp format. It works great! Except for one of two images on this page: https://nedbatchelder.com/text/cardcube.html The first image is strangely pixellated. The second looks perfect.

What did you expect to happen?

The webp conversion should produce the same pixels as the original .png files.

What actually happened?

Unfortunate graininess.

What are your OS, Python and Pillow versions?

  • OS: MacOS
  • Python: 3.9.17
  • Pillow: 10.0.0

I tried converting the two .png files into a variety of formats. The .gif and .bmp look identical to the .png. The .webp shows the results I see on my site:

from pathlib import Path
from PIL import Image

for n in [1, 2]:
    for fmt in ["WEBP", "GIF", "BMP"]:
        inpath = Path(f"cardcube_step{n}.png")
        outpath = inpath.with_suffix("." + fmt.lower())
        im = Image.open(inpath)
        im.save(outpath, fmt, lossless=True, quality=80, method=6)

Here are the two .png files:

cardcube_step1
cardcube_step2

Here are the .webp files I get:

webp.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions