[PYTHON IMAGE-SIG] Basic PIL problems

Fredrik Lundh fredrik_lundh@ivab.se
Thu, 6 Mar 1997 11:57:48 +0100


This is all related to palette issues; PIL 0.2b4 lacks some basic
functionality in this domain; something that suddently became critical
when I finally added GIF write support to the library.

Here's the most serious problems:

1. The colour quantization code is not up and running: RGB=>P
   conversion doesn't work, that is.  P=>RGB works fine, on
   the other hand.

2. The ImagePalette module is just a stub; Anthony Baxter (I think)
   submitted a fixed version a while ago; makes it much easier to
   create and work with palettes.  You'll find it in the archive at
   http://www.python.org/sigs/image-sig

3. The file writing code never converts between modes; this is
   intentional.  However, to make life simpler for utilities like
   pilconvert, I need to add some "format" capability mechanism,
   or at least a "force conversion" flag to the save method.

Plan to make a serious attempt to fix all this before 0.2final.

Cheers	/F


> hobbes:$ python pilconvert.py lena.gif lena.tif
> 
> looks ok, but xv cannot display it (tif directory is missing required
> "colormap" field) and:

The Tiff writer simply forgets to write the palette.  I've received
some patches to the tiff plugin that might address this, but haven't
had time to test them yet.

> hobbes:$ python pilconvert.py lena.gif lena.ppm
> cannot convert image (IOError:cannot write mode P as PPM)

See (3).  You can make this work by using the -r switch, which forces
conversion to "RGB".

> Also the 'tostring'/'fromstring' combination still gives
> error messages:
> 
> >>> im2=Image.new(im.mode,im.size)
> >>> im2.fromstring(im.tostring())
> >>> im2.save('lena2.gif')

The problem is that the palette is not copied by that construct, so
the resulting image simply doesn't have a valid palette; something
that really confuses the GIF writer.  See (2) for something that makes
it a bit better.

We do apologize for the inconvenience ;-)

Cheers	/F

_______________
IMAGE-SIG - SIG on Image Processing with Python

send messages to: image-sig@python.org
administrivia to: image-sig-request@python.org
_______________