help me with function resize , not working with png
- by user304828
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);
}