Python PIL – Flip image vertically

In this post we will be creating a Python script that will flip an existing image vertically, 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 vertically flip an image and save it as a new file. To help us achieve this we utilize the ‘img.transpose()’ method which returns a flipped or rotated version of the original image.

from PIL import Image'image.png')

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

See below our image before the vertical flip.

Python PIL Flip image vertically before flip

See below our image flipped vertically.

Python PIL Flip image vertically after flip

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

Leave a Reply