$nratio) { $x = intval($w * $nh / $h); if ($x < $nw) { $nh = intval($h * $nw / $w); } else { $nw = $x; } } else { $x = intval($h * $nw / $w); if ($x < $nh) { $nw = intval($w * $nh / $h); } else { $nh = $x; } } echo "$oldname was $w x $h,"; echo " $newname is $nw x $nh cropped to $thumbw x $thumbh\n"; // Building the intermediate resized thumbnail $resimage = imagecreatefromjpeg($oldname); $newimage = imagecreatetruecolor($nw, $nh); // use alternate function if not installed imageCopyResampled($newimage, $resimage,0,0,0,0,$nw, $nh, $w, $h); // Making the final cropped thumbnail $viewimage = imagecreatetruecolor($thumbw, $thumbh); imagecopy($viewimage, $newimage, 0, 0, 0, 0, $nw, $nh); // saving imageJpeg($viewimage, $newname, 85); } // List of image for demo: the script on scriptol.com will take them from a directory $ilist = array("river.jpg", "castle.jpg", "coconut.jpg", "bridge.jpg", "ship.jpg"); foreach ($ilist as $iname) { resize_both($iname); } ?>