How to Add Image on Another Image in Python?

By Hardik Savani October 30, 2023 Category : Python

Hi Artisan,

This article will provide an example of python add image to image. This post will give you a simple example of overlay an image on another image python. I would like to share with you how to add image into image in python. This post will give you a simple example of python add image on another image example.

Sometimes, we need to add image on an image and save it or share it with the customer, then I will give you a simple example of adding image on an image with python. we will use PIL library to add image on image. i will share with you two simple examples, one will simply add image on the image, and in another example, we will add image with a custom font family. so let's see both examples one by one.

Example 1:

You need to take the "sample.png" and "logo.png" images and put it in your root folder.

main.py

# Importing the PIL library
from PIL import Image, ImageDraw, ImageFilter
    
# Open an Image from Path
image1 = Image.open('sample.png')
image2 = Image.open('logo.png')
   
newImage = image1.copy()
newImage.paste(image2)
newImage.save('sample3.png', quality=95)

Output:

I hope it can help you...

Tags :
Shares