[Image-SIG] Image.point breakage in PIL 1.1.5?

Fredrik Lundh fredrik at pythonware.com
Fri Jan 27 15:53:27 CET 2006


David Rushby wrote:

>I have some code that uses the Image.point() method to filter pixels in
> black-and-white images.
>
> I'm using Python 2.3.5 on Windows 2000, and when I tried to upgrade
> from PIL 1.1.4 to 1.1.5, the code stopped working.  Now it raises an
> error like this:
> ------------------------------------------------------------------------
> Traceback (most recent call last):
>  File "test2.py", line 4, in ?
>    i2 = i1.point(lambda p: (p > 20 and p) or 0)
>  File "C:\dev\python\core\Lib\site-packages\PIL\Image.py", line 1039,
> in point
>    lut = map(lut, range(256)) * self.im.bands
> AttributeError: 'NoneType' object has no attribute 'bands'
> ------------------------------------------------------------------------
>
> If you take the image file at
> http://kinterbasdb.sourceforge.net/other/temp/test2.bmp and apply the
> following code to it, you'll see the error:
> ------------------------------------------------------------------------
> from PIL import Image
> i1 = Image.open('test2.bmp')
> i2 = i1.point(lambda p: (p > 20 and p) or 0)
> ------------------------------------------------------------------------
>
> This works fine with PIL 1.1.4, but not 1.1.5.  Is my code in error, or
> is there a bug in PIL 1.1.5?

it's a bug in PIL (it's fixed in 1.1.6, but I didn't know that it worked in 1.1.4).

here's a workaround:

    from PIL import Image
    i1 = Image.open('test2.bmp')
    i1.load() # <-- use explicit load
    i2 = i1.point(lambda p: (p > 20 and p) or 0)

</F> 





More information about the Image-SIG mailing list