Python PIL – Get image mode

In this post we will be creating a Python script that will retrieve the mode of an existing image, 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 below where we utilise the PIL library to get the image mode and print it to output. The mode of an image represents the type and depth of a pixel in the image. Some example modes are ‘L’ which represents 8-bit pixels resulting in a black and white image or ‘RGB’ which represents 3×8-bit pixels which results in a true colour image.

from PIL import Image

img=Image.open("image1.png")
print(img.mode)

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

Leave a Reply