Hi
I am trying to resize an uploaded image and save it as png. I always get corrupted png thumbnails. Can somebody check the function and tell where i ve gone wrong.
function image_thumb($file, $tnfilename)
{
//maximum width: 225px
//maximum height 225px
$imageInfo = getimagesize($file);
if ($imageInfo["mime"] == 'image/jpeg') $fullImage = imagecreatefromjpeg($file);
elseif ($imageInfo["mime"] == 'image/png') $fullImage = imagecreatefrompng($file);
$imageWidth = $imageInfo[0];
$imageHeight = $imageInfo[1];
$imageRatio = $imageWidth/$imageHeight;
if ($imageRatio < 1) { $newHeight = 225; $newWidth = (225/$imageHeight) * $imageWidth; echo $newWidth;}
else { $newWidth = 225; $newHeight = (225/$imageWidth) * $imageHeight;}
$tnImage = imagecreatetruecolor($newWidth, $newHeight);
imagealphablending($tnImage, true);
imagecopyresampled($tnImage, $fullImage, 0, 0, 0, 0, $newWidth, $newHeight, $imageWidth, $imageHeight);
imagesavealpha($tnImage, true);
imagepng($tnImage, $tnfilename, 70, PNG_ALL_FILTERS);
imagedestroy($fullImage);
imagedestroy($tnImage);
return $tnfilename;
}