繁体   English   中英

由gd制作透明png图像

[英]make transparent png image by gd

我想制作透明的png图像,并通过imagefttext(黑色)在其上打印字符串。 我读了一些例子,我想我应该使用 imagecolortransparent function,但它是由黑色背景制作的。 我该怎么做?

试试这个

<?php
//Canvas size 100x50
$image = imagecreatetruecolor(100, 50);
imagealphablending($image, false);
//Create alpha channel for transparent layer
$col=imagecolorallocatealpha($image,255,255,255,127);
//Create overlapping 100x50 transparent layer
imagefilledrectangle($image,0,0,100, 50,$col);
//Continue to keep layers transparent
imagealphablending($image,true);
//Insert the text
imagefttext($image,10,0,10,20,0,'octin.ttf','test sting');
//Keep trnsparent when saving
imagesavealpha($image,true);

//Save & output
if(imagepng($image, "test.png", 1)){
   header("Content-Type: image/png");
   readfile('test.png');
}
imagedestroy($image);
?>

Output 100x50px [测试.png]

输出

哎呀我忘了r ...我的错

也许它可以帮助一些人:我想要的东西与您发现的东西相同:它像一个魅力一样用PHP GD展平多个透明PNG

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM