Image resizing not working with png images
Posted
by user304828
on Stack Overflow
See other posts from Stack Overflow
or by user304828
Published on 2010-06-07T03:26:24Z
Indexed on
2010/06/07
4:02 UTC
Read the original article
Hit count: 313
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,$pathtoThumb, 70);
break;
case 'gif':
imagegif($thumb,$pathtoThumb, 70);
break;
case 'png':
imagepng($thumb,$pathtoThumb, 70);
break;
}
//destroy tmp
imagedestroy($thumb);
}
© Stack Overflow or respective owner