Python Imaging Library Handbook |
To use the ImagePalette class and related functions, import the ImagePalette module.
palette = [] for i in range(256): palette.extend((i, i, i)) # grayscale wedge assert len(palette) == 768 im.putpalette(palette)
import ImagePalette palette = ImagePalette.ImagePalette("RGB") palette.putdata(...) im.putpalette(palette)
assert im.mode == "P" lut = im.resize((256, 1)) lut.putdata(range(256)) lut = lut.convert("RGB").getdata() # lut now contains a sequence of (r, g, b) tuples
ImagePalette.ImagePalette(mode="RGB") => palette instance
This constructor creates a new palette, mapping from "P" to the given mode. The palette is initialised to a linear grayscale ramp.