Reputation: 205
I have two 320x320 pixels png images and I need to paste one above the other with Python (the parts that are not colored are transparent):
When I do it manually with GIMP (copy+paste), it gives me the desired output:
However, when pasting one above the other with Pillow I get an image of the red circle as if there was no transparency:
from PIL import Image
im1 = Image.open("square.png")
im2 = Image.open("circle.png")
im1.paste(im2)
im1
What am I doing wrong?
Upvotes: 0
Views: 731
Reputation: 3400
from PIL import Image
im1 = Image.open("square.png")
im2 = Image.open("circle.png")
im2 paste on im1
Image.Image.paste(im1,im2,mask=im2)
im1.show()
here you can specify image as mask as im2
or you can use directly as
im1.paste(im2,mask=im2)
Upvotes: 3