PyTIFF is a library for using TIFF files and advanced imaging in Python. To install pytiff, download the current tar.gz archive and unpack in a directory of your choice. Then, provided you have the necessary software installed, you can install pytiff with python setup.py install, or type python setup.py --help for more information. The library is documented in pytiff.html. Have fun!
You can determine how an image will be compressed by setting an appropriate value for the 'compression' key in its metadata. Here is an example to convert all images of a TIFF file to G4 compression. (This will, of course, fail if the source images aren't black and white.)
import pytiff class AttrChangeFilter: def __init__(self, image, new_metadata): self.image = image self.new_metadata = new_metadata def __getattr__(self, attr): return getattr(self.image, attr) def get_metadata(self): return self.new_metadata metadata = property(get_metadata, None, None) r = pytiff.TiffReader("infile.tiff") w = pytiff.TiffWriter("outfile.tiff") for p in r: m = dict(p.metadata) m["compression"] = "T6" p = AttrChangeFilter(p, m) w.append(p)
Copyright © 2005 by Oliver M. Haynold
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.Last modified: Wed Feb 23 01:38:38 CST 2005