.getbands()
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:
In this example, the .getbands()
method returns the band names of the example image:
from PIL import Image# Opening the image fileimg = Image.open("samandgos.jpg")# Getting the band namesbands = img.getbands()print(bands)
The above code produces the following output:
('R', 'G', 'B', 'A')
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Python:Pillow on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Course
Learn Python 3
Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.With CertificateBeginner Friendly23 hours