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

Noah noah at noah.org
Mon Feb 9 15:23:33 EST 2004


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