Convert PNG to WebP and Preserve Transparency

WebP supports alpha transparency. A reliable check compares the alpha data before and after conversion, including partially transparent pixels around soft edges.

Worked example

Encode a lossless WebP locally

cwebp -lossless approved.png -o approved.webp

Compare alpha with Pillow installed

from PIL import Image

with Image.open("approved.png") as source, Image.open("approved.webp") as result:
    source_alpha = source.convert("RGBA").getchannel("A")
    result_alpha = result.convert("RGBA").getchannel("A")
    assert source_alpha.size == result_alpha.size
    assert source_alpha.getextrema()[0] < 255
    assert source_alpha.tobytes() == result_alpha.tobytes()
    print("Alpha preserved")

Steps

  1. Choose the original transparent PNG and preview it over a dark background. Watch for semitransparent borders or shadows.
  2. Convert a copy to WebP. For a lossless local conversion, use the cwebp command below. Check any conversion applied by the publishing system as a separate step.
  3. Compare the decoded alpha channels. Repeat on the copy downloaded from the destination if it changes uploaded files.

What to check

  • Compare both soft shadows and completely transparent areas.
  • Assess file size after confirming the site's processing also preserves transparency.

Open the image converter

References