PIL always raises "unrecognized image mode" exception with putdata()

david.g.morgenthaler at comcast.net david.g.morgenthaler at comcast.net
Sat Feb 14 00:54:33 EST 2004


On 9 Feb 2004 12:23:33 -0800, noah at noah.org (Noah) wrote:

This worked just fine for me...
Win2000, Python 2.3.2,PIL 1.1.4

>How does Image.putdata() work? I am using PIL 1.1.3.
>This simple script throws an exception on putdata():
>
>    import Image
>    width = 10
>    height = 10
>    im = Image.new ("RGB", (width, height))
>    L = list(im.getdata())
>    k = 0
>    for y in range (height):
>            for x in range (width):
>                    L[k] =(127,127,127)
>                    k += 1
>    im.putdata(L, 1.0, 0.0)
>    im.save ('target_out.png', 'png')
>    
>I get this output:
>
>    Traceback (most recent call last):
>      File "test.py", line 13, in ?
>        im.putdata(L, 1.0, 0.0)
>      File "/usr/local/lib/python2.2/site-packages/PIL/Image.py", line 661, 
>          in putdata
>        self.im.putdata(data, scale, offset)
>    TypeError: unrecognized image mode
>
>In fact even the following trivial script fails:
>
>    import Image
>    width = 10
>    height = 10
>    im = Image.new ("RGB", (width, height))
>    im.putdata (im.getdata())
>
>It seems simple enough. What's the trick? Is my PIL too old?
>
>Yours,
>Noah




More information about the Python-list mailing list