# where 'myphoto.jpg' is in the same directory as the script # will output 'myphoto.jpg' but in the below specified resolution # # scripts@pknet.net # http://peterk.org/scripts/ # # set max parameters of image, or retrieve via GET variable. if (!$_GET[max_width]) $max_width =775; else $max_width = $_GET[max_width]; if (!$_GET[max_height]) $max_height = 512; else $max_height = $_GET[max_height]; $_GET[image] = str_replace('../', '', $_GET[image]); // to avoid directory traversal $_GET[image] = str_replace('/', '', $_GET[image]); // to avoid directory traversal $size = GetImageSize($_GET[image]); $width = $size[0]; $height = $size[1]; $x_ratio = $max_width / $width; $y_ratio = $max_height / $height; if ( ($width <= $max_width) && ($height <= $max_height) ) { $tn_width = $width; $tn_height = $height; } else if (($x_ratio * $height) < $max_height) { $tn_height = ceil($x_ratio * $height); $tn_width = $max_width; } else { $tn_width = ceil($y_ratio * $width); $tn_height = $max_height; } $src = ImageCreateFromJpeg($_GET[image]); $dst = ImageCreateTrueColor($tn_width,$tn_height); ImageCopyResized($dst, $src, 0, 0, 0, 0, $tn_width,$tn_height,$width,$height); header("Content-type: image/jpeg"); ImageJpeg($dst, null, -1); ImageDestroy($src); ImageDestroy($dst); ?>