pygrafix.image.codecs — Managing codecs

This module is used for managing codecs to be used by pygrafix. pygrafix supports a few formats out of the box, but by adding image codecs it’s possible to add more codecs for any format.

exception pygrafix.image.codecs.ImageDecodeException

The error raised when decoding an image fails.

exception pygrafix.image.codecs.ImageEncodeException

The error raised when encoding an image fails.

pygrafix.image.codecs.get_decoders([filename])

Return all decoders that could possibly decode the format described by the extension of filename. If filename is not given it returns all decoders.

pygrafix.image.codecs.get_encoders([filename])

Return all encoders that can encode the format described by the extension of filename. If filename is not given it returns all encoders.

pygrafix.image.codecs.add_decoder(decoder)

Adds decoder to pygrafix. A decoder must support two methods: get_extensions() and decode(file, filename).

get_extensions() must return an iterable of extensions the decoder can decode, for example:

def get_extensions(self):
    return (".bmp", ".png")

decode(file, filename) must attempt to decode the file object file. filename is a hint regarding the containing file type (which can be a full filename or just the extension). If, for any reason, the decoder is not able to decode file it must raise ImageDecodeException. If it succeeds it must return an ImageData object containing the decoded data.

pygrafix.image.codecs.add_encoder(encoder)

Adds encoder to pygrafix. An encoder must support two methods: get_extensions() and encode(imgdata, file, filename).

get_extensions() must return an iterable of extensions the encoder can encode, for example:

def get_extensions(self):
    return (".bmp", ".png")

encode(imgdata, file, filename) must encode the data found in imgdata into the file object file. filename is a hint into which file type the data must be encoded (which can be a string containing the full filename or just the extension). imgdata is passed as an ImageData object.

Project Versions

Previous topic

pygrafix.image — Working with image files

Next topic

pygrafix.resource — Managing resource locations

This Page