After getting excellent monk advice in another thread concerning the best options for scientific graphing (thanks again for that), I settled on using the external package gnuplot. For patent reasons, it generates images in PNG format instead of GIF, which I think should work fine with all the more recent browsers.

The start of my cgi puts up an h2 header and a scrolling menu where the user selects a dataset file, then clicks a "show me" button and then I want a graph to appear, either in the same window below the menu or in a new window - I don't care which.

I use open3 to launch gnuplot in a mode where it accepts commands and data in stdin, sends errors to stderr, and sends the image to stdout. (Please no warnings about deadlocks with open3, I know all about that.) So my PNG image ends up in a file handle returned by open3, which I'll call $png_image_fh. This all works fine and an examination of the PNG data looks apparantly correct, though we won't know until I can actually display it as an image.

Now, I need to read the data from the $png_image_fh and print it out as a PNG image. Looking around in the perlmonk faq, I found this thread: http://www.perlmonks.com/index.pl?node_id=18565 from which I generated the following code:

my ($image_buf,$chunk); while ( read( $png_image_fh , $chunk , 1024 ) ) { $image_buf .= $chunk; } print "Content-type: image/png\n\n"; # binmode included in case we run on Windoze binmode STDOUT; print $image_buf;
Instead of an image, what I get is the PNG data printed in text mode. Any ideas why this might be? The server is Linux, the browser is IE 6.

Thanks
Bret


In reply to Getting the picture by bret.foreman

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.