ImagePalette Module

The ImagePalette module contains a class of the same name to represent the color palette of palette mapped images.

Note

The ImagePalette class has several methods, but they are all marked as “experimental.” Read that as you will. The [source] link is there for a reason.

class PIL.ImagePalette.ImagePalette(mode='RGB', palette=None, size=0)[source]

Color palette for palette mapped images

Parameters
  • mode – The mode to use for the palette. See: Modes. Defaults to “RGB”

  • palette – An optional palette. If given, it must be a bytearray, an array or a list of ints between 0-255. The list must consist of all channels for one color followed by the next color (e.g. RGBRGBRGB). Defaults to an empty palette.

  • size – An optional palette size. If given, an error is raised if palette is not of equal length.

getcolor(color, image=None)[source]

Given an rgb tuple, allocate palette entry.

Warning

This method is experimental.

getdata()[source]

Get palette contents in format suitable for the low-level im.putpalette primitive.

Warning

This method is experimental.

save(fp)[source]

Save palette to text file.

Warning

This method is experimental.

tobytes()[source]

Convert palette to bytes.

Warning

This method is experimental.

tostring()

Convert palette to bytes.

Warning

This method is experimental.