[Image-SIG] PIL problem

Thomas Clive Richards thomi at thomi.imail.net.nz
Sat Aug 14 06:41:40 CEST 2004


I'm trying to make a quick script which generates thumbnails for a website. 
However, I can't get the thumbnail() method to work with PNG files.

I'm using python2.2 (and I can't upgrade unfortunately - that's what is being 
used on the webserver).

Here's a quick outline of the problem:

>>> import Image
>>> im = Image.open("/tmp/pics/title.png")
>>> im.thumbnail((128,128))
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib/python2.2/site-packages/PIL/Image.py", line 1264, in 
  File "/usr/lib/python2.2/site-packages/PIL/ImageFile.py", line 192, in load
    raise IOError(error + " when reading image file")
IOError: unknown error when reading image file

At this point however, If I repeat the thumbnail() cal, there are no errors. 
The following block continues from where the above block left off:

>>> im.thumbnail((128,128))
>>> im.save('/home/thomi/test_thumb.png','PNG')

The saved image seems to be valid (the GIMP will open it), but the contents 
are garbled, and look NOTHING like the original.

This script works fine with GIF, BMP and JPG formats.

Does anyone know of an easy fix for this?



Thomi Richards,
thomi at once.net.nz

More information about the Image-SIG mailing list