Using PIL(/other?) to display resized images over the web?

Matt Goodall matt at pollenation.net
Wed Oct 8 19:50:54 EDT 2003


Steve Castellotti wrote:

>Hey all--
>
>        I have a simple photo website written in python. I would
>like to be able to use Python Imaging Library (or similar) to read an
>image file from the disk, resize/thumbnail it in memory, and then print
>the modified image to stdout (sending it to the client web browser after
>the proper MIME headings).
>
>        Currently, I have only managed to do this via
>Image.save() to a temporary file and then sending that, but of course that
>is somewhat inefficient. Surely there's an easier way to do this, perhaps
>via file descriptors?
>
The outfile argument to Image.save() can be a string (filename) or a
file object. You can send the image to the browser by saving the
thumbnail to sys.stdout instead of the temporary file name, i.e.

    print 'Content-Type: image/gif'
    print
    im.save(sys.stdout, 'GIF')

Cheers, Matt

-- 
Matt Goodall, Pollenation Internet Ltd
w: http://www.pollenation.net
e: matt at pollenation.net








More information about the Python-list mailing list