#!/usr/bin/perl -w # petemar1_image.cgi use GD; use strict; # create a new image my $im = new GD::Image(214, 214); # allocate some colors my $white = $im->colorAllocate(255,255,255); my $black = $im->colorAllocate(0,0,0); my $red = $im->colorAllocate(255,0,0); my $blue = $im->colorAllocate(0,0,255); my $grey = $im->colorAllocate(128,128,128); my $ltgrey = $im->colorAllocate(192,192,192); my $ultraltgrey = $im->colorAllocate(240,240,240); my $timestamp = localtime(); # for Chris my $sec; my $min; my $hour; my $mday; my $mon; my $year; my $wday; my $yday; my $isdst; # 0 1 2 3 4 5 6 7 8 ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); # this is a counter of the seconds per day my $testNum = (3600 * $hour) + (60 * $min) + $sec; # not 337.5, not 7200, but 169.41176470588235294117647058824 my $red; my $green; my $blue; if ($testNum > 43200) #if it's after 12pm { $red = 255 - (($testNum - 43200) / 169.41176470588235294117647058824); $green = 255 - (($testNum - 43200) / 169.41176470588235294117647058824); $blue = 255 - (($testNum - 43200) / 169.41176470588235294117647058824); } else { $red = $testNum / 169.41176470588235294117647058824; $green = $testNum / 169.41176470588235294117647058824; $blue = $testNum / 169.41176470588235294117647058824; } # "clipping:" keep everything between the values of 0 and 255 if ($red < 0) { $red = 0; } if ($red > 255) { $red = 255; } if ($green < 0) { $green = 0; } if ($green > 255) { $green = 255; } if ($blue < 0) { $blue = 0; } if ($blue > 255) { $blue = 255; } my $timeValue = $im->colorAllocate($red,$green,$blue); my $textColor; if ($red > 128 && $green > 128 && $blue > 128) { $textColor = $im->colorAllocate(0,0,0); } else { $textColor = $im->colorAllocate(255,255,255); } # make the background transparent and interlaced $im->transparent($white); $im->interlaced('true'); # Put a black frame around the picture $im->rectangle(0,0,213,213,$black); # And fill it with a color # $im->fill(50,50,$ultraltgrey); $im->fill(50,50,$timeValue); # BEGIN drawing something wonderful here: # $im->string(gdMediumBoldFont, 6, 160, $testNum, $textColor); # $im->string(gdMediumBoldFont, 6, 180, $red, $textColor); $im->string(gdSmallFont, 6, 180, $timestamp, $textColor); $im->string(gdSmallFont, 6, 194, 'CST', $textColor); # END drawing something wonderful here. # Damnable header! print "Content-Type: image/png\n\n"; # make sure we are writing to a binary stream binmode STDOUT; # Convert the image to PNG and print it on standard output print $im->png;