function resize_image($filename, $tmpname, $xmax, $ymax) <br />{ <br /> $ext = explode(".", $filename); <br /> $ext = $ext[count($ext)-1]; <br /> <br /> if($ext == "jpg" || $ext == "jpeg") <br /> $im = imagecreatefromjpeg($tmpname); <br /> elseif($ext == "png") <br /> $im = imagecreatefrompng($tmpname); <br /> elseif($ext == "gif") <br /> $im = imagecreatefromgif($tmpname); <br /> <br /> $x = imagesx($im); <br /> $y = imagesy($im); <br /> <br /> if($x <= $xmax && $y <= $ymax) <br /> return $im; <br /> <br /> if($x >= $y) { <br /> $newx = $xmax; <br /> $newy = $newx * $y / $x; <br /> } <br /> else { <br /> $newy = $ymax; <br /> $newx = $x / $y * $newy; <br /> } <br /> <br /> $im2 = imagecreatetruecolor($newx, $newy); <br /> imagecopyresized($im2, $im, 0, 0, 0, 0, floor($newx), floor($newy), $x, $y); <br /> return $im2; <br />}
登录后复制