Memory Based File Objects

michael michael.bierenfeld at web.de
Tue Feb 22 05:06:52 EST 2005


Hi there,

I am using the Python Image package to do some Image conversion. I
have a "pgm" Image and this must be converted to a "1" Bits / Sample
Tiff Image. There for I am using Image.save ("lala.tiff"). *hm* A Tiff
Image opt. consists of several pages so I am thinking about using the
pytiff package as well. The existing code is like that

parser = ImageFile.Parser ()
parser.feed (imagecontent)
image = parser.close ()            # Now we have the Image

image = image.convert ("1")        # reduce to 1 Bits per sample
image.save ("lala.tif")            # Store as Tiff

After everey File has been processed I am using the "tiffcp" command
to append all the files to a single tiff-file containing each image as
a separate page.

eg. "tiffcp fileone.tiff filetwo.tiff filethree.tiff allinone.tiff"

Performance is an issue here and therefore I am evaluating the pytiff
package. Cause this package can reduce to "1" Bits per Sample and
append to tifffiles.

So the code would be like this

image.save (fileobject, format="tif")
tifffile = pytiff.TiffFileReader (fileobject)

# do some stuff

allinone = pytiff.TiffFileWriter ("allinone.tiff")
allinone.append (fifffile)

Of course I dont wanna write the "in between" File to disk with
image.save () I do wann to to use a memory file object. The Image
Documentation says that file object just has to implement seek, tell
and write. Does anybody have an example how to do that or maybe a
snipplet for an "In Memory" File Object with an unknown size.

Kind Regards

Michael



More information about the Python-list mailing list