[Python] Loading a transparent PNG in PIL gives RGB instead of RGBA

Discussão em 'Python' iniciado por Stack, Maio 4, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to use PIL to composite some aerial imagery and running into some trouble. I use PIL to load this image with this little bit of code:

    composite = Image.new('RGBA', (256, 256))
    url = 'http://...'
    resp = requests.get(url)
    content = StringIO(resp.content)
    image = Image.open(content)
    composite.paste(image, (0, 0), image)


    When I make the call to composite.paste(), PIL gives me the error "ValueError: bad transparency mask". When I print image.mode, sure enough it's simply RGB instead of the expected RGBA (which paste() requires).

    Where does the alpha channel on my downloaded PNG go?

    Continue reading...

Compartilhe esta Página