#!/usr/bin/perl # author: zhounr@math.ncu.edu.tw # update: 20020806 use CGI; use GD; use Digest::MD5; use POSIX; # default $digit = 5; $type = 0; # change this when add new images $totaltype = 2; $cgi = new CGI; if($cgi->param('digit')) { $digit = $cgi->param('digit'); } if($cgi->param('type')){ if ($cgi->param('type') =~ m/random/i ) { $type = POSIX::floor(rand $totaltype); } elsif ($cgi->param('type') < $totaltype) { $type = $cgi->param('type'); } } $iconpath = "imgs/$type/"; $logfile = "log/" . Digest::MD5::md5_hex($cgi->referer); ($width, $height) = GD::Image->newFromPng( $iconpath . "0.png" )->getBounds(); if($cgi->param('reset')) { $num = $cgi->param('reset'); } else { open (INFILE, "$logfile"); $num = ; close (INFILE); } if(!$cgi->param('nocount')) { open (OUTFILE, ">$logfile"); print OUTFILE ++$num, "\n", $cgi->referer; close (OUTFILE); } $counterImg = new GD::Image($width * $digit, $height); # add this if need transparent # $counterImg->transparent($white); for($i = $digit - 1; $i >= 0; $i--) { $n = $num % 10; $num /= 10; $srcImg = GD::Image->newFromPng( $iconpath . "$n.png" ); $counterImg->copy($srcImg, $width * $i, 0, 0, 0, $width, $height); } if($cgi->param('width') && $cgi->param('height')) { $newwidth = $cgi->param('width'); $newheight = $cgi->param('height'); } elsif ($cgi->param('width')) { $newwidth = $cgi->param('width'); $newheight = $newwidth * $height / ($width * $digit); } elsif ($cgi->param('height')) { $newheight = $cgi->param('height'); $newwidth = $newheight * $width * $digit / $height; } else { $newwidth = $width * $digit; $newheight = $height; } $outImg = new GD::Image($newwidth, $newheight); $outImg->copyResized($counterImg, 0, 0, 0, 0, $newwidth, $newheight, $width * $digit, $height); print CGI::header('image/png'); print $outImg->png;