5 samp-scale.cgi - sample CGI that takes an uploaded image to make a new image using Imager
9 Copy samp-scale.html to your document tree.
10 Copy samp-scale.cgi to your /cgi-bin
11 Browse to samp-scale.html in your browser
13 Click on "Scale Image"
24 my $filename = $cgi->param('image');
26 my $fh = $cgi->upload('image');
30 my $image = Imager->new;
31 if ($image->read(fh=>$fh)) {
32 # scale it to max 200 x 200
33 my $scaled = $image->scale(xpixels=>200, ypixels=>200, type=>'min');
35 # no line end conversion (or UTF or whatever)
38 # send in the order we provide it
41 # give it back to the user - as a JPEG
42 print "Content-Type: image/jpeg\n\n";
43 $scaled->write(fd=>fileno(STDOUT), type=>'jpeg');
46 # this should only fail in strange circumstances
47 error("Cannot scale image: ", $image->errstr);
51 error("Cannot read image: ".$image->errstr);
55 error("Incorrect form or input tag - check enctype and that the file upload field is type file");
59 error("No image was supplied");
62 # simple error handler, ideally you'd display the form again with
63 # an error in the right place, but this is a sample
67 print "Content-Type: text/plain\n\nError processing form:\n$msg\n";
73 This is a sample CGI program that accepts an image file from the
76 Please read L<Imager::Cookbook/Parsing an image posted via CGI> for
77 cautions and explanations.
81 Tony Cook <tony@imager.perl.org>