我使用以下功能组合
$img_r = imagecreatefrompng($src);
$dst_1 = imagecreate( $targ_w_1, $targ_h_1 );
imagecopyresampled($dst_1,$img_r,0,0,0,0,$targ_w_1,$targ_h_1,$size_test[0],$size_test[1]);
imagepng($dst_1, $final_source_1,9);
最终结果质量非常低,因为我理解imagepng最高质量是9.你不能在那里写100。但质量仍然非常糟糕。也许我使用错误的函数来处理图像?有什么建议吗?
原始220x220图片
调整图片大小为120x120
调整大小相同的图像220x220
解决
答案 0 :(得分:2)
答案 1 :(得分:2)
据我所知,PNG格式和基础c库中没有质量设置。有压缩,但由于PNG是一种无损格式,压缩图像不会降低质量。
压缩设置为9时,压缩效果最佳(=最小文件大小)。
您遇到的问题可能是您的目标图片是使用imagecreate()
创建的;一个调色板的图像。
您更有可能寻找imagecreatetruecolor()
答案 2 :(得分:1)
问题在于alpha。在我阅读Jaccos评论后,我去谷歌找到了这个
imagealphablending($dst_1, false);
imagesavealpha($dst_1,true);
$transparent = imagecolorallocatealpha($dst_1, 255, 255, 255, 127);
imagefilledrectangle($dst_1, 0, 0,$targ_w_1, $targ_h_1, $transparent);
在使用imagecreatetruecolor ad之后,必须正确处理代码的安静,一切都会好起来的。)