8 my $color = $cgi->param('color');
10 defined $color or $color = '';
12 # Imager allows a number of different color specs, but keep this
13 # simple, only accept simple RRGGBB hex colors
16 # note that you need to perform validation here as well as in
17 # the form script, since the user can view image and manipulate the
18 # URL (or even fetch the URL using LWP and modify the request in any way
20 # Since we're producing an image, we don't have a mechanism to
21 # report errors (unless we choose to draw text on an image), so
22 # just product a default image.
23 if (!defined $color || $color !~ /^[0-9a-f]{6}$/i) {
27 my $im = Imager->new(xsize=>40, ysize=>40);
28 $im->box(filled=>1, color=>$color);
30 # this will force the flushing of the headers, otherwise the server (and
31 # your web browser) may see the image data before the content type.
34 print "Content-Type: image/jpeg\n\n";
36 # use binmode to prevent LF expanding to CRLF on windows
39 # we have to supply the type of output since we haven't supplied a
41 $im->write(fd=>fileno(STDOUT), type=>'jpeg')
42 or die "Cannot write to stdout: ", $im->errstr;
46 samp-image.cgi - demonstrates interaction of HTML generation with image generation
50 /cgi-bin/samp-image.cgi?color=RRGGBB
54 This is the image generation program that samp-form.cgi uses to
57 See samp-form.cgi for more detail.
65 Tony Cook <tony@develop-help.com>