[Image-SIG] PIL and multi-page images

Fredrik Lundh fredrik@pythonware.com
Sat, 27 Jul 2002 14:18:54 +0200


Larry Bates wrote:

> I have some multi-page .DCX files coming from network
> fax (Castelle Faxpress) that I would like to convert
> to .TIF and process.
> 
> Can PIL handle multi-page .DCX or .TIF images?  I just
> can't seem to find anything in the documentation that
> tells how to handle these files.

the DCX decoder implements the seek() method, so in theory,
all you have to do is to loop over the image object until you
get an EOFError (or IndexError?) exception:

    page = 0
    try:
        while 1:
            im.seek(page)
            do something with im
            page = page + 1
    except EOFError:
        pass

(note that seek mutates the image; if "do something" involves
e.g. appending the page image to a list, make sure you to do
im.copy() instead of appending the im object itself)
    
(also note that I haven't seen a DCX file in ages.  if you can
create a multipage sample, it would be a welcome addition to
the set of PIL test images...)

creating multipage TIFF files is a bit harder; there's no good
support for that out of the box.  if you're on Linux/Unix, you
can use PIL to split the DCX into sub pages, and use tiffcp
to merge them into a multipage TIFF.

</F>