function Imageresizer ($url, $width, $height) { Header (' Content-type:image/jpeg '); List ($width _orig, $height _orig) = getimagesize ($url); $ratio _orig = $width _orig/$height _orig; if ($width/$height > $ratio _orig) { $width = $height * $ratio _orig; } else { $height = $width/$ratio _orig; } This resamples the image $image _p = Imagecreatetruecolor ($width, $height); $image = Imagecreatefromjpeg ($url); Imagecopyresampled ($image _p, $image, 0, 0, 0, 0, $width, $height, $width _orig, $height _orig); Output the image Imagejpeg ($image _p, NULL, 100); } Works with both POST and GET $method = $_server[' Request_method '); if ($method = = ' GET ') { Imageresize ($_get[' url '], $_get[' W '), $_get[' H ']); } elseif ($method = = ' POST ') { Imageresize ($_post[' url '], $_post[' W '), $_post[' H ']); } Makes the process simpler function LoadImage ($url, $width, $height) { Echo ' Image.php?url= ', UrlEncode ($url), ' &w= ', $width, ' &h= ', $height; } ?> |