Hi everyone!
This is my first posting on here. I just wasn't able to find the right terms to feed a search engine with. Sorry if my answer is too stupid or something.
Suppose there's a CGI script that shall output a PNG graphic, like this:
#!/usr/bin/perl
use strict;
use GD;
my $infile = "/opt/apache/icons/apache_pb.png";
my $data;
open (my $in_fh, $infile) or die;
while (<$in_fh>){
$data .= $_;
}
close $in_fh;
my $image = GD::Image->newFromPngData($data, 1);
print "content-type: image/png\n\n";
print $image->png;
In reality, I'm going to draw a few annotations onto the PNG, using the GD library.
What I'd like to accomplish is that the script should bring its own data, without having to do a read operation, the path to the file needing to be configured, and needing to catch open errors in a more graceful way than I did in my example.
How would I encapsulate my data in the script?
Thanks in advance everyone!
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.