I'm struggling a touch with pasting one image with a transparent background on another, also with a transparent background, with the right alpha/colour blending.
Here are some example images, red.png and blue.png:
I want to paste blue.png on top of red.png, and achieve this effect:
That image was made by combining the two images in Photoshop, simply as two layers.
The closest I can get using the Python Imaging Library is:
with this code:
from PIL import Image
blue = Image.open("blue.png")
red = Image.open("red.png")
red.paste(blue, (0,0), blue)
red.save("result.png")
Do you see how the alpha and the colour is off where the two circles overlap? In the expected result image, the red and blue blends together in a purplish way, but there's an unwanted alpha halo in the actual result image.
How can I achieve my ideal result in PIL?
The closest I got was to use the alpha_composite function found here. Works really rather well!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With