The current source code:
#!/usr/bin/perl-w
#Copyright2002TylerKaraszewski
#final_sizeisthewidthofthethumbnail
$final_size=$ARGV[0];
#qualityisthejpegqualityforoutput.intfrom0to100.
$quality=$ARGV[1];
#image_nameisthenameoftheimagetoopen
$image_name=$ARGV[2];
#openstheoriginal,andputsthedatato"$imagedata"
open(START,"$image_name");
while(<START>){$imagedata.=$_}
close(START);
#thisprogramrequirestheGD.pmperlmodule.
useGD;
#createsaGDimagefrom"$imagedata"
$original=GD::Image->new("$imagedata");
#getstheoriginalimageswidthandheight,andstoresthemin"$orig_width"and"$orig_height",respectively
($orig_width,$orig_height)=$original->getBounds();
#determinestheaspectratiooftheoriginalimageandstoresthatvalueasaflotingpointnumberin"$aspect_ratio"
$aspect_ratio=$orig_height/$orig_width;
#storesthewidthandheightofthethumbnailin"$new_width"and"$new_height",respectively
$new_width=$final_size;
$new_height=int($aspect_ratio*$new_width);
#determinethenumberofpixelsintheoriginalperpixelinthethumbnail.
$pixel_ratio=$orig_width/$new_width;
#createsthethumbnailimageinthecorrectsize,andsetsthe(256color)palleteappropraitely.
$thumb2=newGD::Image($new_width,$new_height);
$thumb2->copyResized($original,0,0,0,0,$new_width,$new_height,$orig_width,$orig_height);
#printtheimagewithizechangedbypixelreplication/deletion,forcomparison.
open(THUMB,">thumb2_$image_name");
printTHUMB$thumb2->jpeg($quality);
close(THUMB);
#checktoseewhichagorithmtouse,andstartthecorrectone.
if($pixel_ratio>2){
#offsetisforcenteringtheresizealgorithmonthepixeltobeoperatedon
$offset=$pixel_ratio/2;
#beginstheiterationhorizontallyacrosstheimage(lefttoright).
for(my$i=0;$i<$new_width;$i++){
#for(my$i=0;$i<16;$i++){
#beginstheiterationverticallydowntheimage.
for(my$j=0;$j<$new_height;$j++){
#for(my$j=0;$j<14;$j++){
#determineoriginalpixelvaluestosamplefrom
my$x_value=(($i/$new_width)*$orig_width+$offset);
my$y_value=(($j/$new_height)*$orig_height+$offset);
#Determinethepixelsthatweareusingfromtheoriginalimage
my$start_x=int($x_value-$offset);
my$start_y=int($y_value-$offset);
my$end_x=int($x_value+$offset);
my$end_y=int($y_value+$offset);
my@r;
my@g;
my@b;
my@d;
my$count_x=0;
for(my$k=$start_x;$k<=$end_x;$k++){
my$count_y=0;
for(my$l=$start_y;$l<=$end_y;$l++){
my$temp=$original->getPixel(int($start_x+$count_x),int($start_y+$count_y));
(my$r,my$g,my$b)=$original->rgb($temp);
push@r,$r;
push@g,$g;
push@b,$b;
$count_y++;
}
$count_x++;
}
my$red=0;
foreach$value(@r){$red+=$value/$#r}
$red=int($red);
my$green=0;
foreach$value(@g){$green+=$value/$#g}
$green=int($green);
my$blue=0;
foreach$value(@b){$blue+=$value/$#b}
$blue=int($blue);
#Determeinetheclosestcolorinthepallettetothecolorwefound.
my$pixel=$thumb2->colorClosest($red,$green,$blue);
#Andsetthepixelinthethumbnailtothatcolor.
$thumb2->setPixel($i,$j,$pixel);
}
}
}else{
#beginstheiterationhorizontallyacrosstheimage(lefttoright).
for(my$i=0;$i<$new_width;$i++){
#for(my$i=0;$i<16;$i++){
#beginstheiterationverticallydowntheimage.
for(my$j=0;$j<$new_height;$j++){
#for(my$j=0;$j<14;$j++){
#determineoriginalpixelvaluestosamplefrom
my$x_value=(($i/$new_width)*$orig_width);
my$y_value=(($j/$new_height)*$orig_height);
#DetermineweightedvaluesforXandY
#Note:l,r,t,andbdenoteleft,right,topandbottom
my$weight_l=$x_value-int($x_value);
my$weight_t=$y_value-int($y_value);
my$weight_r=1-$weight_l;
my$weight_b=1-$weight_t;
#Determinethepixelsthatweareusingfromtheoriginalimage
my$start_x=int($x_value);
my$start_y=int($y_value);
#gettheRBGvaluesofthepixelsthatwe'reusingfromtheoriginalimage
#andstoretheminsomevariables.
my$temp1=$original->getPixel($start_x,$start_y);
(my$r_lt,my$g_lt,my$b_lt)=$original->rgb($temp1);
my$temp2=$original->getPixel($start_x+1,$start_y);
(my$r_rt,my$g_rt,my$b_rt)=$original->rgb($temp2);
my$temp3=$original->getPixel($start_x,$start_y+1);
(my$r_lb,my$g_lb,my$b_lb)=$original->rgb($temp3);
my$temp4=$original->getPixel($start_x+1,$start_y+1);
(my$r_rb,my$g_rb,my$b_rb)=$original->rgb($temp4);
#Computefinalvaluesforthenewpixelbasedonthevalueswecollected
my$red=int($weight_l*$weight_t*$r_rb+$weight_r*$weight_t*$r_lb+$weight_l*$weight_b*$r_rt+$weight_r*$weight_b*$r_lt);
my$green=int($weight_l*$weight_t*$g_rb+$weight_r*$weight_t*$g_lb+$weight_l*$weight_b*$g_rt+$weight_r*$weight_b*$g_lt);
my$blue=int($weight_l*$weight_t*$b_rb+$weight_r*$weight_t*$b_lb+$weight_l*$weight_b*$b_rt+$weight_r*$weight_b*$b_lt);
#Determeinetheclosestcolorinthepallettetothecolorwefound.
my$pixel=$thumb2->colorClosest($red,$green,$blue);
#Andsetthepixelinthethumbnailtothatcolor.
$thumb2->setPixel($i,$j,$pixel);
}
}
}
open(THUMB,">thumb_$image_name");
printTHUMB$thumb2->jpeg($quality);
close(THUMB);
print"finished\n";