How to merge a transparent PNG image with another image using PIL? Last Updated : 23 Jul, 2025 Suggest changes Share 8 Likes Like Report This article discusses how to put a transparent PNG image with another image. This is a very common operation on images. It has a lot of different applications. For example, adding a watermark or logo on an image. To do this, we are using the PIL module in Python. In which we use some inbuilt methods and combine the images in such a way that it looks to be pasted. Open Function - It is used to open an image.Convert Function - It returns a converted copy of a given image. It converts the image to its true color with a transparency mask.Paste Function - It is used to paste an image on another image. Syntax: PIL.Image.Image.paste(image_1, image_2, box=None, mask=None)OR image_object.paste(image_2, box=None, mask=None) Parameters: image_1/image_object : It is the image on which other image is to be pasted.image_2: Source image or pixel value (integer or tuple).box: An optional 4-tuple giving the region to paste into. If a 2-tuple is used instead, it’s treated as the upper left corner. If omitted or None, the source is pasted into the upper left corner.mask: a mask that will be used to paste the image. If you pass an image with transparency, then the alpha channel is used as the mask. Approach: Open the front and background image using Image.open() function.Convert both the image to RGBA.Calculate the position where you want to paste the image.Use the paste function to merge the two images.Save the image. Input Data: To input the data, we are using two images: Front Image: A transparent image like a logoBackground image: For background like any wallpaper image Implementation: Python3 # import PIL module from PIL import Image # Front Image filename = 'front.png' # Back Image filename1 = 'back.jpg' # Open Front Image frontImage = Image.open(filename) # Open Background Image background = Image.open(filename1) # Convert image to RGBA frontImage = frontImage.convert("RGBA") # Convert image to RGBA background = background.convert("RGBA") # Calculate width to be at the center width = (background.width - frontImage.width) // 2 # Calculate height to be at the center height = (background.height - frontImage.height) // 2 # Paste the frontImage at (width, height) background.paste(frontImage, (width, height), frontImage) # Save this image background.save("new.png", format="png") Output: Create Quiz A adityapande88 Follow 8 Article Tags : Python Python-pil Explore Python FundamentalsPython Introduction 2 min read Input and Output in Python 4 min read Python Variables 4 min read Python Operators 4 min read Python Keywords 2 min read Python Data Types 8 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 5 min read Python Functions 5 min read Recursion in Python 4 min read Python Lambda Functions 5 min read Python Data StructuresPython String 5 min read Python Lists 4 min read Python Tuples 4 min read Python Dictionary 3 min read Python Sets 6 min read Python Arrays 7 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 5 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 3 min read Python MySQL 9 min read Python Packages 10 min read Python Modules 3 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 3 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 4 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 3 min read StatsModel Library - Tutorial 3 min read Learning Model Building in Scikit-learn 6 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 6 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 7 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 5 min read Build a REST API using Flask - Python 3 min read Building a Simple API with Django REST Framework 3 min read Python PracticePython Quiz 1 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read My Profile ${profileImgHtml} My Profile Edit Profile My Courses Join Community Transactions Logout Like