Heres my code, I run it using localhost/script.cgi from my browser -
#!C:/Perl/bin/perl -w use strict; use CGI::Carp qw(fatalsToBrowser); use GD; #createanewimage my $im=new GD::Image(100,100); #allocatesomecolors my $white=$im->colorAllocate(255,255,255); my $black=$im->colorAllocate(0,0,0); my $red=$im->colorAllocate(255,0,0); my $blue=$im->colorAllocate(0,0,255); #makethebackgroundtransparentandinterlaced $im->transparent($white); $im->interlaced('true'); #Putablackframearoundthepicture $im->rectangle(0,0,99,99,$black); #Drawablueoval $im->arc(50,50,95,75,0,360,$blue); #Andfillitwithred $im->fill(50,50,$red); #makesurewearewritingtoabinarystream binmode STDOUT; #ConverttheimagetoPNGandprintitonstandardoutput print $im->png;
When I try to run this from my browser, I get an Internal server error, and in my error log I get -
[Sat Mar 15 20:58:45 2003] [error] [client 127.0.0.1] malformed header + from script. Bad header=‰PNG: script.cgi
I can open gen.png fine from the browser using localhost/gen.png. I'm running on Win XP, and I have Apache installed. Maybe Apache is the problem? The script works fine on the command line. ANy ideas?

In reply to Error displaying PNGs 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.