<div class="codebody" id="code85296"> <?PHP // Set the content-type header('Content-type: image/png'); // Create the image $im = imagecreatetruecolor(175,15); imagesavealpha($im,true); // Create some colors $white = imagecolorallocate($im,255); $grey = imagecolorallocate($im,128,128); $black = imagecolorallocate($im,0); imagefilledrectangle($im,150,25,$black); $trans_colour = imagecolorallocatealpha($im,127); imagefill($im,$trans_colour); // The text to draw $text = $_GET['text']; // Replace path by your own font path $font = 'catriel regular.ttf'; // Add some shadow to the text imagettftext($im,9,13,16,$black,$font,$text); // Add the text imagettftext($im,12,15,$white,$text); // Using imagepng() results in clearer text compared with imagejpeg() imagepng($im); imagedestroy($im); ?>
你要做的就是创建一个真正的彩色图像,确保阿尔法保存状态是,然后填写一个颜色,也经历了阿尔法级别设置为完全透明(127)的图像。 从上面的代码产生的巴新将有一个完全透明的背景(一红色圆圈拖到Photoshop中的图像,以了解自己) The resulting PNG from the code above will have a red circle on a fully transparent background (drag the image into Photoshop to see for yourself)