Overview:
- An alpha channel of an image represents its transparency.
- Pillow the Python Image Processing Library provides alpha compositing of images through the Image class method alpha_composite().
- When the value of alpha channel of one image is 0 - and of another image is 1, the alpha_composite() will display only the second image since its pixels are opaque.
- When the value of alpha channel of one image is 1 - and of another image is 0, the alpha_composite() will display only the first image as the pixels of the first image are opaque.
- When alpha channels of both the images are opaque, both the pixels are to be displayed - Transparency levels are determined by the color of the pixel's' from both the images equally.
Example:
from PIL import Image # Function to change the image size newWidth = int(widthRatio*image.size[0]) newImage = image.resize((newWidth, newHeight)) # Take two images # Make the sizes of images uniform # Make sure the images have alpha channels # Display the images # Do an alpha composite of image4 over image3 # Display the alpha composited image |