it not work with png created a thumb png but haven't data , like null data :D with jpg , jpeg still working without error why ?
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,$pathtoTh开发者_如何转开发umb, 70);
break;
case 'gif':
imagegif($thumb,$pathtoThumb, 70);
break;
case 'png':
imagepng($thumb,$pathtoThumb, 70);
break;
}
//destroy tmp
imagedestroy($thumb);
}
It isn't working because imagepng()
third argument must be between 0 and 9. It indicates the compression level of the png image (0 being no compression). 70 is not a valid value.
imagepng($thumb, $pathtoThumb, 9);
Also, imagegif()
only accepts two arguments. Technically, your call should be:
imagegif($thumb, $pathtoThumb);
精彩评论