我将这两个示例合并起来并以动态方式生成文本。但借助这一设置,我还能够使用透明背景。
<?php
header('Content-type: image/png');
$im = imagecreatetruecolor(175, 15);
imagesavealpha($im, true);
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 150, 25, $black);
$trans_colour = imagecolorallocatealpha($im, 0, 0, 0, 127);
imagefill($im, 0, 0, $trans_colour);
$text = $_GET['text'];
$font = 'catriel regular.ttf';
imagettftext($im, 9, 0, 13, 16, $black, $font, $text);
imagettftext($im, 9, 0, 12, 15, $white, $font, $text);
imagepng($im);
imagedestroy($im);
?>