By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,235 Members | 1,008 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,235 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
| ....
| 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

P: n/a
"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

P: n/a
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.