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
img=Image.open('image.png')
img = img.transpose(Image.FLIP_TOP_BOTTOM)
img.save('flipped_image.png')
See below our image before the vertical flip.

See below our image flipped vertically.

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