Reputation: 3763
I've been looking up on how to put two picture together, turning the top one to around 50% transparent.
So far, I managed to find this:
from PIL import Image
def merge():
background = Image.open("ib.jpg")
background = background .convert('L') #only foreground color matters
foreground = Image.open("if.jpg")
background.paste(foreground, (0, 0), foreground)
background.show()
But it only outputs a blank image.
Both are same sizes.
ib.jpg:
if.jpg:
desired output:
Any tips for a way to do this either with a RGB or RGBA file? I should be dealing with both types (some, in fact, have alpha layer).
Thanks,
Upvotes: 5
Views: 5342
Reputation: 36635
You have to use blend
function from PIL.Image
:
from PIL import Image
bg = Image.open("1.jpg")
fg = Image.open("2.jpg")
# set alpha to .7
Image.blend(bg, fg, .7).save("out.png")
Upvotes: 8