I need to blend an image over another image using Pythons PIL Library.
As you can see in the image below, my two source images are A and B.
When I do:
imageA.paste(imageB, (0, 0), imageB)
I get C as a result, but the part at the top of the gray background is now transparent. Image D is what I get when I put B over A in Photoshop and is what I need to achieve with PIL.
What am I doing wrong? How can I compose B over A in PIL to get D instead of C?
2
Answers
I can’t comment for now (rep constraint).
But I think what you really need, according to your need, is to do this instead:
Basically, that is, make B the background image to get the desired results, because that’s what I see in D.
EDIT:
Looking around more, I found this:
https://stackoverflow.com/a/15919897/4029893
I think you should definitely use the
alpha_composite
method, since paste doesn’t work as expected for background images with transparency.use RGBA for transparency mask