This appears to do the trick:
from PIL import Image
bottom = Image.open("a.png")
top = Image.open("b.png")
r, g, b, a = top.split()
top = Image.merge("RGB", (r, g, b))
mask = Image.merge("L", (a,))
bottom.paste(top, (0, 0), mask)
bottom.save("over.png")
More Related Contents:
- How to merge a transparent png image with another image using PIL
- Change the colors within certain range to another color using OpenCV
- Convert image from PIL to openCV format
- Resampling a numpy array representing an image
- PIL Convert PNG or GIF with Transparency to JPG without
- How to read a raw image using PIL?
- How do you composite an image onto another image with PIL in Python?
- Python: Remove Exif info from images
- create an image with border of certain width in python
- Detecting thresholds in HSV color space (from RGB) using Python / PIL
- Automatically cropping an image with python/PIL
- Resize image in Python without losing EXIF data
- Change specific RGB color pixels to another color, in image file
- Image Cropping using Python
- Convert opencv image format to PIL image format?
- Efficiently Using Multiple Numpy Slices for Random Image Cropping
- Python Image Library fails with message “decoder JPEG not available” – PIL
- Image segmentation based on edge pixel map [closed]
- TypeError: __array__() takes 1 positional argument but 2 were given (Image classification Keras)
- Is it possible to create encoded base64 URL from Image object?
- Detect text area in an image using python and opencv
- Get HOG image features from OpenCV + Python?
- How to properly use cv2.findContours() on opencv version 4.4.0.?
- Getting the bounding box of the recognized words using python-tesseract
- Is Laplacian of Gaussian for blob detection or for edge detection?
- OpenCV – Saving images to a particular folder of choice
- Pytorch RuntimeError: The size of tensor a (4) must match the size of tensor b (3) at non-singleton dimension 0
- Automatic White Balancing with Grayworld assumption
- Determine if an image exists within a larger image, and if so, find it, using Python
- Find a 3×3 sliding window over an image