.getbands()

mariosKontis3257040938's avatar
Published Mar 25, 2025
Contribute to Docs

In the Pillow library, the .getbands() method returns a tuple that contains the name of each band in an image. For example, for a CMYK image, .getbands() will return ('C', 'M', 'Y', 'K').

Syntax

Image.getbands()

Parameters:

The .getbands() method does not take any parameters.

Return Value:

Returns a tuple of strings, where each string represents the name of a color band in the image.

Example

The image to be used for this example is:

Input image to perform the .getbands() operation

In this example, the .getbands() method returns the band names of the example image:

from PIL import Image
# Opening the image file
img = Image.open("samandgos.jpg")
# Getting the band names
bands = img.getbands()
print(bands)

The above code produces the following output:

('R', 'G', 'B', 'A')

All contributors

Contribute to Docs

Learn Python:Pillow on Codecademy