How do I Create Mirror Image Using Python?

Published February 05, 2022

I will show you how to mirror an image horizontally using Python in this post. We will create an application that mirrors the image horizontally using the PIL and transpose () function modules.

The steps below describe how to create a horizontal Mirror image application.

Step 1: Import the required modules

from PIL import Image

Step 2: Select  the image to be mirrored.  To do this,we are going to use the Image.open() to select  the image to be mirrored.

upright_image = Image.open("C:/Users/Kevoh/Pictures/ilovepython.png")

Step 3: Transform the selected image   using the method  Image.FLIP_TOP_BOTTOM.

mirrored_img = upright_image.transpose(method=Image.FLIP_TOP_BOTTOM)

Step 4: Now Save the mirrored image in the application directory.

mirrored_img.save("python.png")

Step 5: Run your application

 

Python Mirror Image

 

 

Python Mirror image

 

Complete code for Create Mirror Image in Python

from PIL import Image

upright_image = Image.open("C:/Users/Kevoh/Pictures/ilovepython.png")

mirrored_img = upright_image.transpose(method=Image.FLIP_TOP_BOTTOM)

mirrored_img.save("python.png")

upright_image.close()

mirrored_img.close()

 

 

Download Source code

 

Article Contributed By :
https://www.rrtutors.com/site_assets/profile/assets/img/avataaars.svg

237 Views