php背景透明度,带有透明度/ Alpha背景的PHP GD文本

好吧,我有一个问题,让我的文字覆盖在部分透明的图像上.我希望文本是可靠的,但我希望图像的背景部分是透明的,文本的部分是实心的,我有,问题是文本继承了其中一个的透明背景前面的图层.这里是代码,输出的一个例子,在那个输出下我想要的样子.图像位于浅灰色背景上,因此在深灰色之间的图像周围的光边界是透明的,但没有其他任何东西应该特别是文本.它似乎不是文本本身,而是文本块的背景是透明的.你可以看到它是不可取的.请帮忙,这是我完成项目的唯一问题. 🙂

无法发布图像,因此继承了示例输出图像和所需结果的链接(orig):

$img = imagecreatetruecolor(200, 50);

$imageX = imagesx($img);

$imageY = imagesy($img);

imagealphablending($img, false);

imagesavealpha($img, true);

$transparent = imagecolorallocatealpha($img, 255,255,255, 127);

$white = imagecolorallocate($img, 255,255,255);

$grey = imagecolorallocate($img, 127,127,127);

imagefilledrectangle($img, 0, 0, $imageX, $imageY, $grey);

imagefilledrectangle($img, 2, 2, $imageX-4, $imageY-4, $transparent);

$font = "./arialbd.ttf";

$fontSize = 12;

$text = "THIS IS A TEST";

$textDim = imagettfbbox($fontSize, 0, $font, $text);

$textX = $textDim[2] - $textDim[0];

$textY = $textDim[7] - $textDim[1];

$text_posX = ($imageX / 2) - ($textX / 2);

$text_posY = ($imageY / 2) - ($textY / 2);

imagefilledrectangle($img, 10, 10, $imageX-10, $imageY-10, $grey);

imagettftext($img, $fontSize, 0, $text_posX, $text_posY, $white, $font, $text);

header("Content-Type: image/png");

imagepng($img);

?>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值