Category: Web Stuff
Author/Contact Info dws
Description: A short CGI script for generating a single pixel GIF of a desired color. Useful, for example, when generating HTML that embeds color-coded, image-based bar charts. Ordinarily, using color in this way requires existing GIFs for all colors used. This script removes the need to make all of those GIFs by hand, allowing one to experiment freely.

# pixel.cgi -- Generate a single-pixel GIF of a given color.
# Usage:
#  <img src="pixel.cgi/CC9966.gif" width=25 height=25>
# Dave W. Smith <>

my($rgb) = $ENV{PATH_INFO} =~ m|/([0-9A-Za-z]{6})(?:\.gif)?$|i;
$rgb ||= '888888';

my $gif = pack("H*",
               '47494638396101000100B30000' . $rgb .

print "Content-type: image/gif\r\n";
print "Content-length: ", length($gif), "\r\n";
print "\r\n";
print $gif;