Rumah >pembangunan bahagian belakang >tutorial php >一款php按比例生成缩略图代码_PHP教程
一款php按比例生成缩略图代码 本文章里面image就是你要生成的图片地址哦,这是一php按比例生成缩略图代码,只要给你图片他就能生成指定大小的图片哦,并且不变形ekt
一款php教程按比例生成缩略图代码
本文章里面image就是你要生成的图片地址哦,这是一php按比例生成缩略图代码,只要给你图片他就能生成指定大小的图片哦,并且不变形ekt
*/
function resizeimage($image,$width,$height,$scale) {
list($imagewidth, $imageheight, $imagetype) = getimagesize($image);
$imagetype = image_type_to_mime_type($imagetype);
$newimagewidth = ceil($width * $scale);
$newimageheight = ceil($height * $scale);
$newimage = imagecreatetruecolor($newimagewidth,$newimageheight);
switch($imagetype) {
case "image/gif":
$source=imagecreatefromgif($image);
break;
case "image/pjpeg":
case "image/jpeg":
case "image/jpg":
$source=imagecreatefromjpeg($image);
break;
case "image/png":
case "image/x-png":
$source=imagecreatefrompng($image);
break;
}
imagecopyresampled($newimage,$source,0,0,0,0,$newimagewidth,$newimageheight,$width,$height);
switch($imagetype) {
case "image/gif":
imagegif($newimage,$image);
break;
case "image/pjpeg":
case "image/jpeg":
case "image/jpg":
imagejpeg($newimage,$image,90);
break;
case "image/png":
case "image/x-png":
imagepng($newimage,$image);
break;
}
chmod($image, 0777);
return $image;
}
?>