使用 imagettftext 创建的重叠文本字符串
我为 png 透明度支持创建了一个图像资源,其内容如下:
$image = imagecreatetruecolor($new_width, $new_height);
imagealphablending($image, false);
imagesavealpha($image, true);
$new_image_bg = imagecolorallocatealpha($image, 255, 255, 255, 127);
imagefill($image, 0, 0, $new_image_bg);
然后,我使用 imagettftext() 向该图像资源添加重叠的文本层,但这会覆盖图像的当前区域。我正在尝试将其合并到现有的图像资源中,以保持文本字符串的透明度。以下是我试图避免的示例:
I have an image resource created for png transaprency support with the following:
$image = imagecreatetruecolor($new_width, $new_height);
imagealphablending($image, false);
imagesavealpha($image, true);
$new_image_bg = imagecolorallocatealpha($image, 255, 255, 255, 127);
imagefill($image, 0, 0, $new_image_bg);
I'm then adding overlapping layers of text to this image resource with imagettftext()
, however this overwrites the current area of the image. I'm trying to merge this into the existing image resource maintaining the transparency of the text string. Below is an example of what I'm trying to avoid:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一种解决方案是:不要将文本直接放置在目标图像中,而是将其放置在辅助图像中,然后执行
imagecopymerge()
操作。One solution is: rather than placing text directly in your target image, place it in a secondary image and then perform an
imagecopymerge()
operation.您是否为正在制作的图像定义了透明颜色?
Have you defined a transparent colour for the image that you are making?