Using PIL with CGI scripts
mnot at pobox.com
Sat Jun 12 03:13:08 CEST 1999
what you have to do is call the script twice. For instance, if you decide
that you need to display foo.jpg (which you've got in a pickle), you first
need to output html like this:
replacing /path/to/this/script/scriptname with the URL of the script
generating the request.
The browser will get this, and when it gets to the IMG tag, it will re-call
your script, this time with foo.jpg as an argument. Your script needs to be
able to take that request and return the proper HTTP headers, along with the
image data itself as the body. For instance (assuming that img is your
tmp = StringIO()
image = tmp.read()
%s''' % (len(image), image)
----- Original Message -----
From: Luis Roco Arriagada <luisroco at hotmail.com>
To: <mnot at pobox.com>; <python-list at cwi.nl>
Sent: Saturday, June 12, 1999 8:31
Subject: Re: Using PIL with CGI scripts
> Sorry for bothering you again, but I can't figure out how can I do this
> 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
> to get some images from this file according to a word search perform by
> user of the web site. This part is already done, so the images are
> 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 "<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
> 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.,
> >changes EVERY time someone accesses it), you're much better off if you
> >it to disk.
> >See genpix.py at http://www.mnot.net/python/ for an example of this
> >command line utility that HTMLifys a directory of images, but it does use
> >cStringIO in this manner).
> >----- 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
> >the Python Imaging Library package?
> > >
> > > I just want to produce some images which has been processed using PIL
> >show them in a web site
> > >
> > >
> Get Your Private, Free Email at http://www.hotmail.com
More information about the Python-list