IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
The ImagePalette Module
Python Imaging Library Handbook

Prev   Next

The ImagePalette Module

To use the ImagePalette class and related functions, import the ImagePalette module.

Examples

Attach a Palette to an Image (Sequence Syntax)
palette = []
for i in range(256):
    palette.extend((i, i, i)) # grayscale wedge

assert len(palette) == 768

im.putpalette(palette)

Attach a Palette to an Image (Not Yet Supported)
import ImagePalette

palette = ImagePalette.ImagePalette("RGB")
palette.putdata(...)

im.putpalette(palette)

Getting the Palette Contents Using Resize/Convert
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

Classes

ImagePalette

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.