Using PIL with CGI scripts
Luis Roco Arriagada
luisroco at hotmail.com
Fri Jun 11 18:31:48 EDT 1999
Mark:
Sorry for bothering you again, but I can't figure out how can I do this
work.
I can`t write the image to the disk because all of the images are inside a
single file where they are compressed using pickle. What I'm trying to do is
to get some images from this file according to a word search perform by the
user of the web site. This part is already done, so the images are extracted
from the file but they are in a PIL format, ie they are an Image type, and
for that i cannot display them in a web page using the HTML tag <IMG SRC = >
because this tag only accepts a file name as input.
I try to use cStringIO to emulate a file, but I don't know how I must use
this variable with the HTML tag.
This part of the code is something like this:
from cStringIO import StringIO
print "Content-type: text/html"
print
print "<HEAD><TITLE>WEBIMAGE</TITLE></HEAD>"
print "<BODY BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\" LINK=\"#0000FF\"
VLINK=\"#000080\" ALINK=\"#FF0000\">"
print "<center><H1>WEBIMAGE</h1>"
print "<p>Version 0.01</p>"
print "<hr>"
.
.
.
temp = StringIO()
im.save(temp,"JPEG") #im is an Image variable
temp.seek(0)
print "<p><IMG SRC='%s'>"%temp
print "</center>"
print "</body>"
Hope you can help me and thanks in advance
Luis Roco
>From: "Mark Nottingham" <mnot at pobox.com>
>To: <luisroco at hotmail.com>,<python-list at cwi.nl>
>Subject: Re: Using PIL with CGI scripts
>Date: Wed, 9 Jun 1999 08:27:23 +1000
>
>See the StringIO module (actually, cStringIO).
>
>One thing to keep in mind - unless the image is *really* dynamic (i.e., it
>changes EVERY time someone accesses it), you're much better off if you
>write
>it to disk.
>
>See genpix.py at http://www.mnot.net/python/ for an example of this (it's
>a
>command line utility that HTMLifys a directory of images, but it does use
>cStringIO in this manner).
>
>Cheers,
>
>
>----- Original Message -----
>From: <luisroco at hotmail.com>
>To: <python-list at cwi.nl>
>Sent: Wednesday, June 09, 1999 7:10
>Subject: Using PIL with CGI scripts
>
>
> > Hi all
> >
> > How can a CGI scripts outputs graphics images through Python code using
>the Python Imaging Library package?
> >
> > I just want to produce some images which has been processed using PIL
>and
>show them in a web site
> >
> >
>
______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com
More information about the Python-list
mailing list