Previous section To contents Next section

12.18 Image.PNM

DESCRIPTION
This submodule keeps the PNM encode/decode capabilities of the Image module.

PNM is a common image storage format on unix systems, and is a very simple format.

This format doesn't use any color palette.

The format is divided into seven subformats;

P1(PBM) - ascii bitmap (only two colors)
P2(PGM) - ascii greymap (only grey levels)
P3(PPM) - ascii truecolor
P4(PBM) - binary bitmap
P5(PGM) - binary greymap
P6(PPM) - binary truecolor

Simple encoding:
encode,
encode_binary,
encode_ascii

Simple decoding:
decode

Advanced encoding:
encode_P1,
encode_P2,
encode_P3,
encode_P4,
encode_P5,
encode_P6

SEE ALSO
Image, Image.Image and Image.GIF

METHOD
Image.PNM.decode

SYNTAX
object decode(string data)

DESCRIPTION
Decodes PNM (PBM/PGM/PPM) data and creates an image object.

RETURNS
the decoded image as an image object

NOTE
This function may throw errors upon illegal PNM data.

SEE ALSO
encode

METHOD
Image.PNM.encode,
Image.PNM.encode_P1,
Image.PNM.encode_P5,
Image.PNM.encode_ascii,
Image.PNM.encode_P6,
Image.PNM.encode_P2,
Image.PNM.encode_binary,
Image.PNM.encode_P3,
Image.PNM.encode_P4

SYNTAX
string encode(object image)
string encode_binary(object image)
string encode_ascii(object image)
string encode_P1(object image)
string encode_P2(object image)
string encode_P3(object image)
string encode_P4(object image)
string encode_P5(object image)
string encode_P6(object image)

DESCRIPTION
Make a complete PNM file from an image.

encode_binary() and encode_ascii() uses the most optimized encoding for this image (bitmap, grey or truecolor) - P4, P5 or P6 respective P1, P2 or P3.

encode_P1/encode_P4 assumes the image is black and white. Use Image.Image->threshold() or something like Image.Colortable( ({({0,0,0}),({255,255,255})}) )->floyd_steinberg()->map(my_image) to get a black and white image.

encode_P2/encode_P5 assumes the image is greyscale. Use Image.Image->grey() to get a greyscale image.

RETURNS
the encoded image as a string

NOTE
encode() is equal to encode_binary(), but may change in a future release.

SEE ALSO
decode

Previous section To contents Next section