Home> php教程> php手册> body text

一款php按比例生成缩略图代码

WBOY
Release: 2016-06-13 09:48:32
Original
795 people have browsed it

一款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;
}
?>

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!