<?php
$img_name = $_GET['pic'];
$max_width = $_GET['wd'];
$max_height = $_GET['ht'];
$size = getimagesize($img_name);
$typenum = $size[2];
$width_ratio = ($size[0]/$max_width);
$height_ratio = ($size[1]/$max_height);
if ($width_ratio >= $height_ratio){
    $ratio = $width_ratio;
}
if ($height_ratio >= $width_ratio){
    $ratio = $height_ratio;
}
    
$new_width = $size[0]/$ratio;
$new_height = $size[1]/$ratio;
if ($typenum == 1){
  header ("Content-type: image/gif");
    

$src_img = imagecreatefromgif($img_name); 
$thumb = imagecreatetruecolor($new_width,$new_height);
imagecopyresampled($thumb,$src_img,0,0,0,0,$new_width,$new_height,$size[0],$size[1]);
imagegif($thumb);

}
if ($typenum == 2){
   header ("Content-type: image/jpeg");
    

$src_img = imagecreatefromjpeg($img_name); 
$thumb = imagecreatetruecolor($new_width,$new_height);
imagecopyresampled($thumb,$src_img,0,0,0,0,$new_width,$new_height,$size[0],$size[1]);
imagejpeg($thumb);
}

if ($typenum == 3){
    header ("Content-type: image/png");

$src_img = imagecreatefrompng($img_name); 
$thumb = imagecreatetruecolor($new_width,$new_height);
imagecopyresampled($thumb,$src_img,0,0,0,0,$new_width,$new_height,$size[0],$size[1]);
imagepng($thumb);
}



imagedestroy($thumb);
imagedestroy($src_img);
?>