32日发薪的小菜鸟:
// 创建一个 200x100 的图像资源
$image = imagecreatetruecolor(200, 100);
// 分配一个带有透明度的颜色,最后一个参数是透明度(0为完全透明,127为半透明,255为完全不透明)
$transparentColor = imagecolorallocatealpha($image, 255, 255, 255, 127); // 半透明白色背景
// 启用透明度保存功能
imagesavealpha($image, true);
// 将半透明颜色填充为整个背景
imagefill($image, 0, 0, $transparentColor);
// 为图像分配一个不透明的颜色用于文本或其他内容
$textColor = imagecolorallocate($image, 0, 0, 0); // 黑色文本
// 在图像上写一些文本
imagestring($image, 5, 50, 50, 'Hello, World!', $textColor);
// 将图像保存为 PNG 文件,透明度信息将被保留
imagepng($image, 'hello_world_transparent.png');
// 释放内存
imagedestroy($image);
?>