Hi folks,
What I'm trying to do is write a CGI script that will later be referenced by a javascript sniglet to load a random image from an inventory of images in a set directory. The random selection part is working just fine, but what is driving me crazy is the part where we send the images to the browser is misbehaving. What further infuriates me is I know I got this to work before so I know I'm probably missing something fairly obvious. Here is the offending sniglet of code:

use strict; use CGI qw/ :all /; use Image::Info; use GD; | | much handwaving for parts that already work fine. | my $imgStream; if ( $type eq 'PNG' ) { $imgStream = GD::Image->newFromPng($image); } else { $imgStream = GD::Image->newFromJpeg($image); } exec $0 if not $imgStream; print header(-type=>$mime); my $png_data = $imgStream->png; binmode STDOUT; print $png_data; close STDOUT; exit(0);

What I'm seeing at the browser is that oh-so-useful Error 500 error. Checking the server error logs I see:

[Tue Aug 7 14:21:59 2007] [error] [client 68.37.143.39] Premature end + of script headers: /home/bcdcweb/public_html/cgi-bin/sendRandomImage +.pl
If I play around with the script a little run it as a command line script the right data is being generated for the image and can be loaded by Eye Of Gnome just fine. It just doesn't seem to work as a CGI.

What am I missing here???


Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

In reply to Using GD in a CGI script to randomly select images fails... by blue_cowdawg

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.