在 PHP 中,使用 GD 库和 FreeType 支持,可以设置 imagettftext 的透明度
$font = 'path/to/your/font.ttf'; $fontSize = 20; $fontColor = imagecolorallocatealpha($image, 255, 255, 255, 127); // 设置字体颜色和透明度(RGBA) $width = 300; $height = 200; $image = imagecreatetruecolor($width, $height); $text = 'Hello, World!'; $textWidth = imagettfbbox($fontSize, 0, $font, $text); $textX = ($width - $textWidth[4]) / 2; $textY = ($height - $textWidth[5]) / 2 + $fontSize; imagettftext($image, $fontSize, 0, $textX, $textY, $fontColor, $font); header('Content-type: image/png'); imagepng($image); imagedestroy($image); 将以上代码片段组合在一起,即可创建一个带有透明度的 imagettftext 图像。注意,透明度值的范围是 0(完全透明)到 127(完全不透明)。