调整图像大小不会与PNG图像
问题描述:
它不是PNG 创造了一个拇指png格式的工作,但还没有数据,如空数据的工作:d 以JPG,JPEG仍然没有错误 为什么工作?调整图像大小不会与PNG图像
function thumbnail($pathtoFile,$thumWidth,$pathtoThumb) {
//infor of image
$infor = pathinfo($pathtoFile);
// Setting the resize parameters
list($width, $height) = getimagesize($pathtoFile);
$modwidth = $thumWidth;
$modheight = floor($height * ($modwidth/$width));
// Resizing the Image
$thumb = imagecreatetruecolor($modwidth, $modheight);
switch(strtolower($infor['extension'])) {
case 'jpeg':
case 'jpg':
$image = imagecreatefromjpeg($pathtoFile);
break;
case 'gif':
$image = imagecreatefromgif($pathtoFile);
break;
case 'png':
$image = imagecreatefrompng($pathtoFile);
break;
}
imagecopyresampled($thumb, $image, 0, 0, 0, 0, $modwidth,
$modheight, $width, $height);
switch(strtolower($infor['extension'])) {
case 'jpeg':
case 'jpg':
imagejpeg($thumb,$pathtoThumb, 70);
break;
case 'gif':
imagegif($thumb,$pathtoThumb, 70);
break;
case 'png':
imagepng($thumb,$pathtoThumb, 70);
break;
}
//destroy tmp
imagedestroy($thumb);
}
答
它不工作,因为imagepng()
第三个参数必须在0到9之间并且它指示的PNG图像的压缩级别(0是没有压缩)。 70不是有效的值。
imagepng($thumb, $pathtoThumb, 9);
此外,imagegif()
只接受两个参数。从技术上讲,你的电话应该是:
imagegif($thumb, $pathtoThumb);
非常感谢你^^ – Chameron 2010-06-07 09:15:52
@ user304828:那请记住我的答案是接受(复选标记旁边接听)。 – 2010-06-07 15:39:05