=$height_ratio) { $ratio = $width_ratio; } else { $ratio = $height_ratio; } $new_width = ($size[0] / $ratio); $new_height = ($size[1] / $ratio); if ($type==1) { header("Content-Type: image/gif"); $src_img = imagecreatefromgif($img_name); } if ($type==2) { header("Content-Type: image/jpeg"); $src_img = imagecreatefromjpeg($img_name); } if ($type==3) { header("Content-Type: image/png"); $src_img = imagecreatefrompng($img_name); } // Create a new image from file or URL //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-1),($new_height-1),$size[0],$size[1]); //Output image to browser or file if ($type == 1)imagegif($thumb); if ($type == 2)imagejpeg($thumb); if ($type == 3)imagepng($thumb); imagedestroy($src_img); imagedestroy($thumb); ?>