How to change opacity of image and merge with another image in Python
<p>I've been looking up on how to put two picture together, turning the top one to around 50% transparent.</p>

<p>So far, I managed to find this:</p>

<pre><code>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()
</code></pre>

<p>But it only outputs a blank image. </p>

<p>Both are same sizes.</p>

<p>ib.jpg:</p>

<p><a href="https://i.stack.imgur.com/KKJ4p.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/KKJ4p.jpg" alt="ib.jpg"></a></p>

<p>if.jpg:</p>

<p><a href="https://i.stack.imgur.com/0e979.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/0e979.jpg" alt="if.jpg"></a></p>

<p>desired output:</p>

<p><a href="https://i.stack.imgur.com/SYOGF.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/SYOGF.jpg" alt="enter image description here"></a></p>

<p>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).</p>

<p>Thanks,</p>