嘿,当我从png创建缩略图时,尝试保持png的透明度时遇到麻烦,有人对此有任何经验吗?任何帮助都会很棒,这是我目前正在做的事情:
$fileName= "../js/ajaxupload/tees/".$fileName;
list($width, $height) = getimagesize($fileName);
$newwidth = 257;
$newheight = 197;
$thumb = imagecreatetruecolor($newwidth, $newheight);
imagealphablending($thumb, true);
$source = imagecreatefrompng($fileName);
imagealphablending($source, true);
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagesavealpha($thumb, true);
imagepng($thumb,$newFilename);
最佳答案
过去,我已经成功地做到了这一点:
$thumb = imagecreatetruecolor($newwidth, $newheight);
imagealphablending($thumb, false);
imagesavealpha($thumb, true);
$source = imagecreatefrompng($fileName);
imagealphablending($source, true);
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagepng($thumb,$newFilename);
我发现使用
imagecopyresampled()
的输出图像质量比imagecopyresized()
更好关于php - PHP的PNG透明度,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/313070/