PIL mode

The mode of an image tells you what sort of color data it contains.

Find out your image mode like this:

print(img.mode)

Example modes:

RGB: each pixel is a set of three numbers:
red (R), green (G), and blue (B).

(Read about color pixel data here)

RGBA: each pixel is a set of four numbers. “A” means “alpha” which is opacity (opposite of transparency). This type of image allows fun things like transparent backgrounds, ghostly overlays, and watermarks.

L: each pixel is just one number. L means “lightness.” This type of image is a grayscale image – each number represents a shade of gray.

P:  (Palette) – each pixel is assigned one number, and each number represents a color; it’s basically a numbered color dictionary. If you download an image like this and try to treat it as an RGB image, it won’t work properly.

You can read about modes here:
pillow.readthedocs.io/en/stable/handbook/concepts.html

You can convert one mode to another. Here’s how you can make a grayscale image from an RGB image:

gray_img = img.convert('L')

Read about Image.convert() here