We will mix the same two images blended in another section. Just to try out something different, in the composite image, we will focus on the flying birds instead of the bridge.
We will use the same set of input images as used in the Blending section.
1 import Image 2 3 img1 = Image.open( "C:\\images\\BRIDGE2.png ") 4 img1 = img1.convert('RGBA') 5 6 img2 = Image.open( "C:\\images\\BIRDS2.png ") 7 img2 = img2.convert('RGBA') 8 9 r, g, b, alpha = img2.split() 10 alpha = alpha.point(lambda i: i>0 and 204) 11 12 img = Image.composite(img2, img1, alpha) 13 img.show()
The code until line 7 is identical to the one illustrated in the blending example. Note that the two input images need not have the same
mode
. On line 10, theImage.point
method is called. Thelambda
function operates on thealpha
band data. The code on lines 9 and 10 is similar to that illustrated in the section Creating Transparent Images. Please refer to that section for further...