display image through cgi python html

Discussion in 'Python' started by Ladislav Andel, Jul 24, 2007.

  1. Hi,
    I'm trying to display image through my cgi script in HTML page
    via <img src="image.cgi">

    Can you give me an example, please?
    What should be in the cgi script to display it?

    Here is what I have in image.cgi but it is incorrect and i'm not able to
    find it on the web.

    #!/usr/bin/python
    print "Content-Type: image/png\n"
    print 'image.png'

    thanks,
    Lada
     
    Ladislav Andel, Jul 24, 2007
    #1
    1. Advertising

  2. On Tue, 24 Jul 2007 11:58:47 +0200, Ladislav Andel wrote:

    > Here is what I have in image.cgi but it is incorrect and i'm not able to
    > find it on the web.
    >
    > #!/usr/bin/python
    > print "Content-Type: image/png\n"
    > print 'image.png'


    You have to print the image, not the name. Read the binary file and print
    it.

    Ciao,
    Marc 'BlackJack' Rintsch
     
    Marc 'BlackJack' Rintsch, Jul 24, 2007
    #2
    1. Advertising

  3. Ladislav Andel

    Steve Holden Guest

    Marc 'BlackJack' Rintsch wrote:
    > On Tue, 24 Jul 2007 11:58:47 +0200, Ladislav Andel wrote:
    >
    >> Here is what I have in image.cgi but it is incorrect and i'm not able to
    >> find it on the web.
    >>
    >> #!/usr/bin/python
    >> print "Content-Type: image/png\n"
    >> print 'image.png'

    >
    > You have to print the image, not the name. Read the binary file and print
    > it.
    >

    As in:

    #!/usr/bin/python
    data = open('image.png', 'rb').read()
    print "Content-Type: image/png\nContent-Length: %d\n" % len(data)
    print data

    regards
    Steve
    --
    Steve Holden +1 571 484 6266 +1 800 494 3119
    Holden Web LLC/Ltd http://www.holdenweb.com
    Skype: holdenweb http://del.icio.us/steve.holden
    --------------- Asciimercial ------------------
    Get on the web: Blog, lens and tag the Internet
    Many services currently offer free registration
    ----------- Thank You for Reading -------------
     
    Steve Holden, Jul 24, 2007
    #3
  4. Thanks for quick reply.
    Yes, that's the hint I needed.

    Lada

    Marc 'BlackJack' Rintsch wrote:
    > On Tue, 24 Jul 2007 11:58:47 +0200, Ladislav Andel wrote:
    >
    >
    >> Here is what I have in image.cgi but it is incorrect and i'm not able to
    >> find it on the web.
    >>
    >> #!/usr/bin/python
    >> print "Content-Type: image/png\n"
    >> print 'image.png'
    >>

    >
    > You have to print the image, not the name. Read the binary file and print
    > it.
    >
    > Ciao,
    > Marc 'BlackJack' Rintsch
    >
     
    Ladislav Andel, Jul 24, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lukasz Indyk
    Replies:
    4
    Views:
    430
    Diez B. Roggisch
    May 17, 2004
  2. Marek Kurowski
    Replies:
    1
    Views:
    1,017
    Mark A. Odell
    Aug 18, 2004
  3. computer_guy
    Replies:
    3
    Views:
    789
    computer_guy
    Jul 20, 2007
  4. Josef 'Jupp' Schugt

    (Ab)using class CGI as non-CGI HTML generator?

    Josef 'Jupp' Schugt, Mar 5, 2005, in forum: Ruby
    Replies:
    3
    Views:
    284
    Lee Braiden
    Mar 6, 2005
  5. joe
    Replies:
    7
    Views:
    180
    Joseph
    May 12, 2004
Loading...

Share This Page