[Python] Pasting transparent image over background using PIL/Pillow

Discussão em 'Python' iniciado por Stack, Março 21, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to make an image partially transparent and then superimpose it over a second image. For example, take this image and set it to 50% transparency and then past it over this image to create this composite image. I've tried to do this with the following code:

    from PIL import Image

    background = Image.open("one.png")
    foreground = Image.open("circle.png")
    foreground.putalpha(120) # Sets the oval to 50% transparency
    background.paste(foreground, (0, 0)) # Paste oval over the background
    background.show()


    However, when I try this it only shows the foreground. Is it possible to adjust transparency using PIL/Pillow this way to achieve the desired composite image?

    Continue reading...

Compartilhe esta Página