#!/usr/local/bin/perl #Please note: before taking advantage of this module, #you must install the GD.pm Perl package. See the #GD.pm documentation for details. use GD; # Create the image. $im = new GD::Image(100,100); # Allocate the background color (black; red, green, and blue # values are all zero). The image is always the first argument. $black = $im->colorAllocate(0,0,0); # Allocate the foreground color (white; red, green, and blue # values are all at maximum). $white = $im->colorAllocate(255, 255, 255); # Now draw a solid white rectangle in the middle of the image. $im->filledRectangle(25, 25, 74, 74, $white); # Almost done: we still have to write the image to a file. # NOTE: no special provision is made here to open the file # in binary mode. If you are using DOS, OS/2, Windows or # Windows NT, consult the documentation of your Perl # interpreter for more information about opening files # in binary mode. # Open the file. open(OUT, ">test.gif") || die "Can't open test.gif\n"; # Write the image to the file in GIF format. $data = $im->gif; print OUT $data; # Close the file. close(OUT); # It is not necessary to explicitly destroy the image. # Perl will clean up the resources automatically. # All went well. exit 0;