gpt4 book ai didi

php - 使用 PHP 实现 PNG 透明度

转载 作者:IT王子 更新时间:2023-10-29 00:52:31 24 4
gpt4 key购买 nike

嘿,当我从它创建缩略图时,试图保持 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com