=$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); ?>