Python PIL – Flip image horizontally

In this post we will be creating a Python script that will flip an existing image horizontally, to do this we will be using the Python Imaging Library also known as PIL enabling us to image processing capabilities.

See the sample of Python code where we utilise the PIL library to horizontally flip an image and save it as a new file. To help us achieve this we utilize the ‘img.transpose()’ method returns a flipped or rotated version of the original image.

from PIL import Image'image.png')

img = img.transpose(Image.FLIP_LEFT_RIGHT)'flipped_image.png')

See below our image before the horizontal flip.

Image before border

See below our image flipped horizontally.

Take a look at some of our other content around the Python programming language by clicking here.

Leave a Reply