<?
$img_name =    $_GET['pic'];
$max_width    = $_GET['wd']; // maximum x aperture  in pixels
$max_height   = $_GET['ht']; // maximum y aperture in pixels

//use it as so:http://mm214.com/nwolfe/thumbnail.php?pic=images/banner.png&wd=585&ht=123

$size= getimagesize($img_name);
$width_ratio  = ($size[0] / $max_width);
$height_ratio = ($size[1] / $max_height);
 
if($width_ratio >=$height_ratio) 
{
   $ratio = $width_ratio;
}
else
{
   $ratio = $height_ratio;
}
 
$new_width    = ($size[0] / $ratio);
$new_height   = ($size[1] / $ratio);

header("Content-Type: image/png");
// Create a new image from file or URL
$src_img = imagecreatefrompng($img_name);
//imagecreatetruecolor() returns an image identifier representing a black image of size x_size  by y_size.
$thumb = imagecreatetruecolor($new_width,$new_height);
/*imagecopyresampled() copies a rectangular portion of one image to another image,
 smoothly interpolating pixel values so that, in particular,
  reducing the size of an image still retains a great deal of clarity.
  */
imagecopyresampled($thumb, $src_img, 0,0,0,0,($new_width),($new_height),$size[0],$size[1]);
//Output image to browser or file
imagepng($thumb);
imagedestroy($src_img);
imagedestroy($thumb);
?> 
