A PIL Question

R

Ray

Hello,

I'm using latest PIL version with Python 2.4.1. (for solving a level in
Python Challenge actually...). Anyway, I'm trying to draw a picture. My
question is, why is it that putdata() won't work? Even this won't run:

import Image

im = Image.open("something.jpg")
seq = im.getdata()

image = Image.Image()
image.putdata(seq)

image.show()

I always get:

Traceback (most recent call last):
File "Script1.py", line 31, in ?
image.putdata(seq)
File "D:\Development\Python24\Lib\site-packages\PIL\Image.py", line
1120, in putdata
self.im.putdata(data, scale, offset)
AttributeError: 'NoneType' object has no attribute 'putdata'

Anybody has any idea why this is the case?

Thanks,
Ray
 
M

Max Erickson

image = Image.Image()
Anybody has any idea why this is the case?

Image.Image() isn't the way to get a new image object in PIL. Try
Image.new(), which needs at least mode and size arguments. You can get
those from your original image...

Then do im2.show() and everything should be ok.


max
 
T

Terry Hancock

import Image

im = Image.open("something.jpg")
seq = im.getdata()

image = Image.Image()
image.putdata(seq)

image.show()

I always get:

Traceback (most recent call last):
File "Script1.py", line 31, in ?
image.putdata(seq)
File "D:\Development\Python24\Lib\site-packages\PIL\Image.py", line
1120, in putdata
self.im.putdata(data, scale, offset)
AttributeError: 'NoneType' object has no attribute 'putdata'

Anybody has any idea why this is the case?

Well, obviously you didn't get an image back from Image.Image().
In fact, I suspect you would've at least have to have given it a size
or something. It clearly returned None, and you're trying to call
a method that None doesn't have, like it says.

Definitely check the PIL manual for what Image.Image() is
supposed to return, and what it requires to have valid output.
 

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,773
Messages
2,569,594
Members
45,114
Latest member
GlucoPremiumReview
Top