#!/usr/bin/perl use strict; use CGI; #use GD; my $query = new CGI; if ($query->param('generateimage')) { generateImage(); } else { # We weren't asked for the image, # so let's return a simple web page # that contains the image my $gderror; eval 'use GD'; if ($@ ne undef) { $gderror = "

The following error occured when trying to load GD.pm

\n$@\n"; } print $query->header; print <

GD Library Test

Remote image Local image

If Local image is the same as (or similar to) the Remote image, both the GD Library and GD.pm module are installed on your server.

If you do not see the Local image, either GD Library or GD.pm module are not available. Click here for more info.

If you do not see the Remote image, either our web site is not available at the moment or you have Internet connectivity problems. Anyway, make sure you see the Local image (red square inside of black square). $gderror
EOM ; } sub generateImage { eval 'use GD'; return if $@ ne undef; # We MUST do this on Windows or the # image will be garbled, and it # doesn't hurt on Unix/Linux/etc binmode STDOUT; # Output the right content type # for a PNG-format image print $query->header("image/gif"); # Draw an image with a red rectangle # in the middle my $image = new GD::Image(100, 100); my $black = $image->colorAllocate( 0, 0, 0); my $red = $image->colorAllocate( 255, 0, 0); $image->filledRectangle( 25, 25, 75, 75, $red); # Output the image to the browser print $image->gif; }