How do I serve an image from a python script?

haaserd haaserd at yahoo.com
Fri Jun 8 19:00:55 EDT 2001


Works!  Thank you, thank you.

Roger Haase

piet at cs.uu.nl wrote:

> >>>>> haaserd <haaserd at yahoo.com> (h) writes:
>
> h> Hi,
> h> I am trying to serve an image from a Python script using Apache under
> h> Windows.  My simple HTML statement:
>
> h>     <img src="ShowPict.py?fn=xxx"  alt="a picture">
>
> h> ...and my simple script:
>
> h> #!c:/Python20/python.exe
> h> import sys
>
> h> def pix():
> h>     n = 'c:/My Pictures/Sample.jpg'
> h>     p = open(n,'rb')
> h>     apix = p.read()
> h>     p.close()
> h>     sys.stdout.write("content-type: image/jpeg\n\n")
> import os, msvcrt
> msvcrt.setmode(sys.stdout.fileno(),os.O_BINARY)
> h>     sys.stdout.write(apix)
> h>     sys.stdout.flush()
>
> h> if __name__ == '__main__':
> h>     pix()
> --
> Piet van Oostrum <piet at cs.uu.nl>
> URL: http://www.cs.uu.nl/~piet [PGP]
> Private email: P.van.Oostrum at hccnet.nl




More information about the Python-list mailing list