]> git.imager.perl.org - imager.git/blame - samples/samp-image.cgi
bump $Imager::Font::FT2::VERSION
[imager.git] / samples / samp-image.cgi
CommitLineData
dd3124b1
TC
1#!/usr/bin/perl -w
2use strict;
3use CGI;
4use Imager;
5
6my $cgi = CGI->new;
7
8my $color = $cgi->param('color');
9
10defined $color or $color = '';
11
12# Imager allows a number of different color specs, but keep this
13# simple, only accept simple RRGGBB hex colors
14my %errors;
15
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
19# they like.
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.
23if (!defined $color || $color !~ /^[0-9a-f]{6}$/i) {
24 $color = '000000';
25}
26
27my $im = Imager->new(xsize=>40, ysize=>40);
28$im->box(filled=>1, color=>$color);
29
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.
32++$|;
33
34print "Content-Type: image/jpeg\n\n";
35
36# use binmode to prevent LF expanding to CRLF on windows
37binmode STDOUT;
38
39# we have to supply the type of output since we haven't supplied a
40# filename
41$im->write(fd=>fileno(STDOUT), type=>'jpeg')
42 or die "Cannot write to stdout: ", $im->errstr;
43
44=head1 NAME
45
46samp-image.cgi - demonstrates interaction of HTML generation with image generation
47
48=head1 SYNOPSIS
49
50 /cgi-bin/samp-image.cgi?color=RRGGBB
51
52=head1 DESCRIPTION
53
54This is the image generation program that samp-form.cgi uses to
55generate the image.
56
57See samp-form.cgi for more detail.
58
59=head1 REVISION
60
61$Revision$
62
63=head1 AUTHOR
64
65Tony Cook <tony@develop-help.com>
66
67=cut