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

return image in mod python

P: n/a
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 ?
Nov 19 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Abandoned wrote:
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
Nov 19 '07 #2

P: n/a
On Nov 19, 12:36 pm, "Diez B. Roggisch" <de...@nospam.web.dewrote:
Abandoned wrote:
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
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 ?
Nov 19 '07 #3

P: n/a
Abandoned wrote:
On Nov 19, 12:36 pm, "Diez B. Roggisch" <de...@nospam.web.dewrote:
>Abandoned wrote:
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

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
Nov 19 '07 #4

P: n/a
On Nov 19, 5:32 pm, "Diez B. Roggisch" <de...@nospam.web.dewrote:
Abandoned wrote:
On Nov 19, 12:36 pm, "Diez B. Roggisch" <de...@nospam.web.dewrote:
Abandoned wrote:
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
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- 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.
Nov 20 '07 #5

P: n/a
Abandoned wrote:
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
Nov 22 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.