Try using blend() instead of paste() - it seems paste() just replaces the original image with what you're pasting in.
try:
from PIL import Image
except ImportError:
import Image
background = Image.open("bg.png")
overlay = Image.open("ol.jpg")
background = background.convert("RGBA")
overlay = overlay.convert("RGBA")
new_img = Image.blend(background, overlay, 0.5)
new_img.save("new.png","PNG")
Answer from egor83 on Stack Overflow Top answer 1 of 5
40
Try using blend() instead of paste() - it seems paste() just replaces the original image with what you're pasting in.
try:
from PIL import Image
except ImportError:
import Image
background = Image.open("bg.png")
overlay = Image.open("ol.jpg")
background = background.convert("RGBA")
overlay = overlay.convert("RGBA")
new_img = Image.blend(background, overlay, 0.5)
new_img.save("new.png","PNG")
2 of 5
16
Maybe too old question, can be done with ease using opencv
cv2.addWeighted(img1, alpha, img2, beta, gamma)
#setting alpha=1, beta=1, gamma=0 gives direct overlay of two images
Documentation link
10:06
OpenCV Python Image Overlay - YouTube
00:59
Overlaying images for easy comparison (in python) - YouTube
Overlaying images for easy comparison (in python)
33:53
PNG Overlay and Image Rotation using OpenCV | CVZone - YouTube
19:38
Adding a Picture Overlay on Video with Python and OpenCV | #108 ...
Plotly
community.plotly.com โบ ๐ plotly python
How to overlay two images with opacity - ๐ Plotly Python - Plotly Community Forum
June 7, 2023 - I have a simple problem, I want to overlay two rgb images (np.arrays with three channels and same size) over each other, with opacity setting for the top so I can see both. fig_visual_check = go.Figure() fig_visual_check = fig_visual_check.add_trace(go.Image(z=images_merged_visual[0], opacity=0.5)) fig_visual_check = fig_visual_check.add_trace(go.Image(z=images_merged_visual[1], opacity=1)) fig_visual_check However, the result is just a black image.
Educative
educative.io โบ answers โบ how-to-superimpose-two-images-using-pil-in-python
How to superimpose two images using PIL in Python
The Image module offers a variety of factory operations, including tools for generating new pictures and loading images from files. Two images can be superimposed on another using the paste() function from the Image module.
Kite
kite.com โบ python โบ answers โบ how-to-overlay-images-in-python
Kite.com
kite.com ยท Inquiries: info@eradomains.com
Moonbooks
moonbooks.org โบ Articles โบ How-to-overlay--superimpose-two-images-using-python-and-pillow-
How to overlay / superimpose two images using python and pillow ?
August 24, 2022 - from PIL import Image import numpy as np img = Image.open("data_mask_1354_2030.png") background = Image.open("background_1354_2030.png") background.paste(img, (0, 0), img) background.save('how_to_superimpose_two_images_01.png',"PNG")
Readthedocs
plantcv.readthedocs.io โบ en โบ latest โบ visualize_ovelay_two_imgs
Overlay Images - PlantCV - Read the Docs
This function overlays one input image on top of the other one, with a desired alpha value indicating the opacity of the 1st image. It is able to handle both RGB and gray scale images. plantcv.visualize.overlay_two_imgs(img1, img2, alpha=0.5)
Python Examples
pythonexamples.org โบ pillow-image-overlay
Image Overlaying in Python with Pillow
In this tutorial, you will learn how to use Image.paste() to over an image over another. The steps to overlay an image over another image with Pillow are ยท Import Image module from Pillow library. Read the two input images using Image.open() function, say base_img and overlay_img.
Pythontic
pythontic.com โบ image-processing โบ pillow โบ blend
Blend two images using an alpha value | Pythontic.com
The blend() method of Pillow library blends two images with an alpha value. The Python example uses two alpha values - 0.2 and 0.4 producing two output images.
Matplotlib
matplotlib.org โบ stable โบ gallery โบ images_contours_and_fields โบ layer_images.html
Layer images with alpha blending โ Matplotlib 3.11.2 documentation
import matplotlib.pyplot as plt import numpy as np def func3(x, y): return (1 - x / 2 + x**5 + y**3) * np.exp(-(x**2 + y**2)) # make these smaller to increase the resolution dx, dy = 0.05, 0.05 x = np.arange(-3.0, 3.0, dx) y = np.arange(-3.0, 3.0, dy) X, Y = np.meshgrid(x, y) # when layering multiple images, the images need to have the same # extent.
Stack Overflow
stackoverflow.com โบ questions โบ 45598317 โบ overlay-multiple-images-in-python
Overlay multiple images in python - Stack Overflow
August 10, 2017 - Currently I am searching the way to do it, ... One approach is to store all your images as a list, and then iterate through each overlapping pair of images and callcv2.addWeighted() on each element in your list, passing in the last aggregate ...
GeeksforGeeks
geeksforgeeks.org โบ python โบ transparent-overlays-with-python-opencv
Transparent overlays with Python OpenCV - GeeksforGeeks
July 23, 2025 - import cv2 import numpy as np # Loading our images # Background/Input image background = cv2.imread('Assets/img1.jpg') # Overlay image overlay_image = cv2.imread('Assets/overlay3.png') # Resize the overlay image to match the bg image dimensions overlay_image = cv2.resize(overlay_image, (1000, 1000)) h, w = overlay_image.shape[:2] # Create a new np array shapes = np.zeros_like(background, np.uint8) # Put the overlay at the bottom-right corner shapes[background.shape[0]-h:, background.shape[1]-w:] = overlay_image # Change this into bool to use it as mask mask = shapes.astype(bool) # We'll create


