Hello,

I want to do some batch conversions of uncompressed, raw tif images to 
optimally compressed PNG images. The documentation in Python Imaging Library 
Overview gets me pretty far; I think the conversion is pretty straightforward:

>>> import Image
>>> infile = r'c:\images\test.txt' # this is a text file of input tif image 
>>> file and path names
>>> inf = file(infile,'r')
>>> for fn in inf:
>>>     fn = fn.strip() # get rid of the \n
>>>     print fn
>>>     newfn, ft = fn.rsplit('.')
>>>     newfn = newfn + ".png"
>>>     im = Image.open(fn)
>>>     print fn
>>>     print im.format, im.size, im.mode
>>>     print "New: ",newfn,"\n"
>>>     outim = im.transpose(Image.ROTATE_180)
>>>     outim.save(newfn,"PNG") #works, but just gets a PNG encoded image
>>> inf.close()

My question is how to specify the PNG optimize parameter? The documentation for 
the save method says

            Im.save(outfile,format,options)

The PNG section of the documentation says "optimize" can be specified for the 
save method. It appears that this is the value of a keyword argument. However, 
if I try im.save(outfile,format,"optimize"), the code fails with a wrong number 
of arguments message.

In the save method in Image.py, the keyword parameters passed get put into 
self.encoderinfo which is interrogated in the _save method in 
PngImagePlugin.py. So "optimize" is a key in a dictionary data structure, but a 
key to what and I'm lost at that point.

Thanks.

Brandon Nuttall
_______________________________________________
Image-SIG maillist  -  Image-SIG@python.org
http://mail.python.org/mailman/listinfo/image-sig

Reply via email to