function clipImage($file, $width, $height) { $imSrc = imagecreatefromjpeg($file); $w = imagesx($imSrc); $h = imagesy($imSrc); if($width/$height>$w/$h) { $nh = ($h/$w)*$width; $nw = $width; } else { $nw = ($w/$h)*$height; $nh = $height; } $dx = ($width/2)-($nw/2); $dy = ($height/2)-($nh/2); $imTrg = imageCreateTrueColor($width, $height); imagecopyresized($imTrg, $imSrc, $dx, $dy, 0, 0, $nw, $nh, $w, $h); imagedestroy($imSrc); imagejpeg($imTrg, $file, 95); imagedestroy($imTrg); }