The relevant chapter of the docs is this one and I think it's fairly clear: if for example you want to decode image files in the new .zap
-format, you write a ZapImagePlugin.py
module which must perform a couple things:
- have a
class ZapImageFile(ImageFile.ImageFile):
with string attributes format
and format_description
, and a hook-method def _open(self)
(of which more later);
- at module level,
Image.register_open('zap', ZapImageFile)
and Image.register_extension('ZAP', '.zap')
The specs for the _open
method are very clearly laid out in the chapter -- it must read image data and metadata from open binary file-like object self.fp
, raise SyntaxError
(or another exception) ASAP if it detects that the file's not actually in the right format, set at least self.size
and self.mode
attributes, and in order to allow reading the image, also self.tile
, a list of tile descriptors again in the format specified in that chapter (including the file-offset, which you say you know, and a decoder -- if the raw or bit decoders, documented in the chapter, don't meet your needs, the chapter recommends studying the sources of some of the many supplied decoders, such as JPEG, PNG, etc).