Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用imagettftext和imagecolortransparent是否可以实现真正的透明度?_Php_Gd - Fatal编程技术网

Php 使用imagettftext和imagecolortransparent是否可以实现真正的透明度?

Php 使用imagettftext和imagecolortransparent是否可以实现真正的透明度?,php,gd,Php,Gd,当通过imagecolortransparent将imagettftext与呈现为透明的图像一起使用时,文本的边框似乎与原始背景色(黑色)而不是透明度混合,从而创建了文本的轮廓,如图所示: 与使用imagestring相反,此处: 现在我不确定是否有更好的方法来组合图像,使它们从一开始就透明,或者是否有其他我不知道的透明方法。以下是我正在使用的相关PHP代码: if ($type) { $icon = imagecreatefrompng("images/" . $type . ".png

当通过imagecolortransparent将imagettftext与呈现为透明的图像一起使用时,文本的边框似乎与原始背景色(黑色)而不是透明度混合,从而创建了文本的轮廓,如图所示:
与使用imagestring相反,此处:

现在我不确定是否有更好的方法来组合图像,使它们从一开始就透明,或者是否有其他我不知道的透明方法。以下是我正在使用的相关PHP代码:

if ($type) {
  $icon = imagecreatefrompng("images/" . $type . ".png");
}
else {
  die('Invalid type.  Valid types are: arcane, elysian, divine, spectral');
}
$img = imagecreatetruecolor(128, 25);
$black = imagecolorallocate($img, 0, 0, 0);
imagecolortransparent($img, $black);
imagecopymerge($img,$icon,0,0,0,0,28,25,100);

imagettftext( $img, 16, 0, 30, 20, $col, $font, $input_num );

header( "Content-type: image/png" );
imagepng( $img );

imagecolortransparent
由于消除混叠,将永远无法正常工作---轮廓附近的背景色不是真正的黑色。最好的选择是首先使用带有透明区域的PNG图像,而不是黑色背景的图像