469,329 Members | 1,477 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,329 developers. It's quick & easy.

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

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
Jul 18 '05 #1
3 4930
| ....
| 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.

--
Cousin Stanley
Human Being
Phoenix, Arizona

Jul 18 '05 #2
"Cousin Stanley" <Co***********@hotmail.com> wrote in message news:<c0*************@ID-130333.news.uni-berlin.de>...
| ....
| 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
Jul 18 '05 #3
On 9 Feb 2004 12:23:33 -0800, no**@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


Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

21 posts views Thread by nicholas | last post: by
2 posts views Thread by Nalaka | last post: by
1 post views Thread by =?Utf-8?B?TWFuanJlZSBHYXJn?= | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Purva khokhar | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.