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

Hello Everybody,
I have a problem getting to display images on my browser window. When i try to invoke a sample script that i have created the image does not get displayed. Can anyone help me out please.

Here's the code that i am using
#!/usr/local/bin/perl5-new -w use strict; use GD::Graph::bars; use CGI qw (param header); my @data = ( ["Jan-01","Feb-01","Mar-01", "Apr-01","May-01","Jun-01","Jul-01","Au +g-01","Sep -01"],[21,25,33,39,49,48,40,45,15]); my $graph = new GD::Graph::bars; $graph->set( x_label => 'Anand', y_label => 'Praveen', title => 'Testing the Graph display', bar_spacing => 10 ) or warn $graph->error; open PNG, ">/kbase/anand/search/sw/cposupport/search/graph2.png"; binmode PNG; print PNG $graph->plot(\@data)->png; close PNG; print header; print "<HTML><BODY BGCOLOR=white>\n"; print "<IMG SRC=\"/kbase/anand/search/sw/cposupport/search/graph2. +png\">"; print "</BODY></HTML>";

Edit: Added <code> tags, and some formatting.

Replies are listed 'Best First'.
Re: Displaying Images
by steves (Curate) on Feb 10, 2003 at 11:37 UTC

    Also, I'd check your open like this:

    open PNG, ">/kbase/anand/search/sw/cposupport/search/graph2.png" or die "Failed to open image file: $!\n";
    Then for next steps:
    1. Find your web server's error log. Since that's where standard error will be going, look at the last entries to see if anything failed.
    2. If nothing failed, try just getting the created image using the URL you're putting in your image tag. It may be that this is not relative to your web server's document root.

      I use apache 1.3.26 as the web server. After some debugging, i could get the image load onto my browser. But the apache error logs come out with binmode() on closed filehandle PNG at /kbase/anand/search/sw/cgi-bin/cposupport/ ccsearch/test.pl line 22. print() on closed filehandle PNG at /kbase/anand/search/sw/cgi-bin/cposupport/cc search/test.pl line 23. Is this just a warning that i can ignore? Please help i am new to Perl

        Did you add error checking to the open call? Sounds like that's failing if uses of PNG are generating errors afterwards. It may be permissions. Remember that your CGI runs as whatever user your Apache httpd.conf has the web server set to (default is nobody).

        But if there are errors like that I'm not seeing how you're getting the image to show unless you created it successfully outside of the web server environment (e.g., running your CGI manually) once along the way.

Re: Displaying Images
by PodMaster (Abbot) on Feb 10, 2003 at 11:23 UTC
    How do you "invoke the script"?

    What server are you using (are you using a server)?

    If you're not using a server, it's not gonna work.

    If you are using a server, is /kbase/anand/search/sw/cposupport/search/graph2.png the correct url? And if it is, do you have permission to read the file?

    What's the error log say?


    MJD says you can't just make shit up and expect the computer to know what you mean, retardo!
    ** The Third rule of perl club is a statement of fact: pod is sexy.