当尝试将PNG转换为GIF时,将透明返回为黑色:
$file = "example.png"
$whf = getimagesize($file);
$wf = $whf[0];
$hf = $whf[1];
$h = "100";
$w = "100";
$img = imagecreatetruecolor($w, $h);
$imgi = imagecreatefrompng($file);
// Here means to be some magic code...
imagecopyresampled($img, $imgi, 0, 0, 0, 0, $w, $h, $wf, $hf);
imagegif($img, "example.gif");
imagedestroy($img);我试过的密码,但什么都没有:
1:
imagesavealpha($img, true);
imagecolortransparent($img, 127<<24);2:
imagealphablending($img, false);
imagesavealpha($img, true);这行得通!但只有一个细节。您需要绝对透明的背景,没有"png梯度透明“。Imagick使用一半梯度透明到绝对透明,另一半用于绝对平原。谢谢伊萨格罗!
$black = imagecolorallocate($img, 0, 0, 0);
imagecolortransparent($img, $black); 发布于 2015-01-27 16:25:06
我认为您需要调用图像颜色分配来获取颜色引用并将其传递给图像透明
$black = imagecolorallocate($im, 0, 0, 0);
imagecolortransparent($img, $black);https://stackoverflow.com/questions/28175068
复制相似问题