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

N

Noah

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
 
C

Cousin Stanley

| ....
| im.save ('target_out.png', 'png')
| ....

Noah ....

Try the image type in all-caps ....

im.save( 'targe_out.png' , 'PNG' )

Also, you might try the Image save method
with just the filename and omit the type argument ....

im.save( 'target_out.png' )

Unless you specify the format, the library
uses the filename extension to discover
which file storage format to use.
 
N

Noah

Cousin Stanley said:
| ....
| im.save ('target out.png', 'png')
| ....
Noah ....
Try the image type in all-caps ....
im.save( 'targe out.png' , 'PNG' )
Also, you might try the Image save method
with just the filename and omit the type argument ....
im.save( 'target out.png' )
Unless you specify the format, the library
uses the filename extension to discover
which file storage format to use.

But my problem is with getdata() and putdata().
The PIL raises the exception even when saving or loading is not involved.
For example, the following script raises the exception
"TypeError: unrecognized image mode.

import Image
width = 10
height = 10
im = Image.new ("RGB", (width, height))
im.putdata (im.getdata())

Yours,
Noah
 
D

david.g.morgenthaler

On 9 Feb 2004 12:23:33 -0800, (e-mail address removed) (Noah) wrote:

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top