daddyo has asked for the wisdom of the Perl Monks concerning the following question:

i'm sure this is a simple thing but it's not working the way i thought it would ( like life itself ). i want to generate an image in the middle of a page with a cgi script. I thought that the simple scrit should do it:
<html><head> <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1" +> <title>My pics</title> </head> <body background="../images/paperbgnd.jpg"> <img alt = "bupkiss" src = "../next_pic.cgi"> ... where next_pic.cgi: #!/usr/bin/perl print "../images/pic1.png";
... i get bupkiss;
the isp says cgi scripts should execute from 'anywhere'....
scrit perms are 755.

where have I strayed from the path?

Replies are listed 'Best First'.
Re: img src =
by Fletch (Bishop) on Jan 25, 2002 at 21:49 UTC

    You're just printing the location of the image you want. This won't work, as the browser expects the SRC attribute to point to the image data itself. You'd need either

    • some sort of Server Side Include (SSI) processing to be enabled so that it would be expanded in place
    • make the page itself generated by a CGI program which prints the different location
    • have the next_pic.cgi program redirect the browser to the correct image URL
    • have the next_pic.cgi program print the actual content of the image

    #!/usr/bin/perl print "Content/Type: image/png\n\n"; open( PIC, "../images/pic1.png" ) or die "Can't open: $!\n"; print while <PIC>; close( PIC ); exit 0; __END__
Re: img src =
by slayven (Pilgrim) on Jan 25, 2002 at 21:45 UTC
    AFAIK the cgi-script should print the imagedata instead of the imagelocation.
    open(IMG, "../images/pic1.png") or die ($!); print while(<IMG>) close(IMG);

    uhm, or something similar :)
    nevertheless, I may be wrong with this assumption.

    --
    trust in bash
    but tie your camel
Re: img src =
by Masem (Monsignor) on Jan 25, 2002 at 21:38 UTC
    You need to send out the appropriate HTTP header in your image generation CGI script, which should be at minimum:
    #!/usr/bin/perl -w print "Content-Type: image/png\n\n"; print "../images/pic1.png";
    Update ...and as others have pointed out, you need to print the file itself to STDOUT, not just the name of the file.

    -----------------------------------------------------
    Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
    "I can see my house from here!"
    It's not what you know, but knowing how to find it if you don't know that's important

      Thanks much, wise men of Perl
Re: img src =
by Rex(Wrecks) (Curate) on Jan 25, 2002 at 21:56 UTC
    I'm curious why no one has said use CGI ; or even use CGI::Lite

    With either of these, creating pages is easy, and from what I understand CGI::Lite has relativly low overhead.

    "Nothing is sure but death and taxes" I say combine the two and its death to all taxes!