return image in mod python

A

Abandoned

Hi i have a problem.

def showimage(req):
from PIL import Image
im=Image.open("c:\image-2.jpg")
im.thumbnail((800,600), Image.ANTIALIAS)
req.sendfile(im)



give me some error.
How can i return this image witdhout save ?
 
D

Diez B. Roggisch

Abandoned said:
Hi i have a problem.

def showimage(req):
from PIL import Image
im=Image.open("c:\image-2.jpg")
im.thumbnail((800,600), Image.ANTIALIAS)
req.sendfile(im)



give me some error.

Really? I don't see any error. So there can't be one.

Diez
 
A

Abandoned

Really? I don't see any error. So there can't be one.

Diez

It gives me this error:
req.sendfile(im)

TypeError: argument 1 must be string, not instance

Sendfile uses as:
req.sendfile("C:/img.jpg")
But i don't know how can i return when i use PIL before return ?
 
D

Diez B. Roggisch

Abandoned said:
It gives me this error:
req.sendfile(im)

TypeError: argument 1 must be string, not instance

Sendfile uses as:
req.sendfile("C:/img.jpg")
But i don't know how can i return when i use PIL before return ?

Then don't use sendfile. I don't know mod_python, but I'm pretty sure you
can output what you want somehow to the output stream. So, do that.

Or go down the easy road, create a temp-file to store the image and send
that.

Diez
 
A

Abandoned

Then don't use sendfile. I don't know mod_python, but I'm pretty sure you
can output what you want somehow to the output stream. So, do that.

Or go down the easy road, create a temp-file to store the image and send
that.

Diez- Hide quoted text -

- Show quoted text -

Thank you very much.
Yes if i save this i show with sendfile but i must show this witdhout
save.
 
P

Peter Otten

Abandoned said:
Hi i have a problem.

def showimage(req):
from PIL import Image
im=Image.open("c:\image-2.jpg")
im.thumbnail((800,600), Image.ANTIALIAS)
req.sendfile(im)



give me some error.
How can i return this image witdhout save ?

image = Image.open(...)
image.thumbnail(...)
req.content_type = "image/jpeg"
image.save(req, "jpeg")

Peter
 

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

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top