Your image problem probably has nothing to do with your perl program. It's probably a permissions problem. If you want to have perl display your image, it'd look more like this, but you wouldn't normally do this since having apache (or IIS) pick up perl and an image gets kindof heavy. If you want to print images, consider FCGI or mod_perl or something to keep perl picked up.

open my $file "<", $image_file or die "grr: $!"; # (You shouldn't print the header manually if you use CGI) print "Content-type: image/gif\n\n"; print $_ while <$file>;

Other notes: use strict and use warnings. Not using them will cause you trouble eventually. Also consider using a template package like HTML::Template. Also, don't load CGI if you're not going to use it for something. It's pretty big.

use strict; use warnings; use CGI; use CGI::Carp qw(fatalsToBrowser); my $cgi = CGI->new; print $cgi->header; # use $cgi->header("image/gif") for gifs print $cgi->start_html; print $cgi->table( $cgi->Tr( $cgi->td([ $cgi->img({src=>"blarg"}) )));

-Paul


In reply to Re: Display an image with a CGI program? by jettero
in thread Display an image with a CGI program? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.