The approach I like to use for similar tasks is to generate a
PPM image file and then pipe the output to
ppmtogif, like this:
$RED = 255;
$GREEN = 0;
$BLUE = 0;
open STDOUT, "| ppmtogif" or die "open: $!";
# "1 1" means that the image is 1x1 pixel.
# "255" means that 255 is the maximum color intensity.
print "P3 1 1 255 $RED $GREEN $BLUE\n";
close STDOUT or die "close: $!";
This may not be as cool, and it has the disadvantage of
requiring
ppmtogif, but it's also
a lot simpler, and it has the tremendous
advantage that it's easy to generate images that
are bigger than one pixel. For example,
the
images for this article
were generated with this technique, as were
these.