function imageresize($goods_pic){
$newwidth = 50;
$newheight = 50;
$filename = 'images/' . $goods_pic;
$newname = 'images/small_images/' . $goods_pic;
if(!empty($goods_pic) && file_exists($filename)){
list($width, $height) = getimagesize($filename);
$thumb = imagecreatetruecolor($newwidth, $newheight);
$suffix = strrchr($filename,'.');
switch($suffix){
case '.gif':
$source = imagecreatefromgif($filename);
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagegif($thumb,$newname);
break;
case '.png':
$source = imagecreatefrompng($filename);
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagepng($thumb,$newname);
break;
case '.jpg':
$source = imagecreatefromjpeg($filename);
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagejpeg($thumb,$newname);
break;
case '.bmp':
$source = imagecreatefromwbmp($filename);
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagewbmp($thumb,$newname);
break;
}
imagedestroy($thumb);
}
}
php使用imagecopyresized压缩图片
最新推荐文章于 2025-05-31 07:30:00 发布