imagecreatetruecolor
创建一个新的真彩色图像
此函数从 PHP 4.3.0 起可用。
imagecreatetruecolor() 函数用于创建一个真彩色图像,即带有 RGB 颜色模式的图像。该图像的每个像素可以包含 256 级的红色、绿色和蓝色组成的颜色。
resource imagecreatetruecolor(int $width, int $height);
成功时,返回图像资源,失败时返回 false。
下面是一个简单的示例,演示如何使用 imagecreatetruecolor 创建一个 300x200 像素的真彩色图像。
此示例代码首先创建了一个 300x200 像素的真彩色图像,然后填充了图像的背景颜色为红色。
$width = 300;
$height = 200;
$image = imagecreatetruecolor($width, $height);
$red = imagecolorallocate($image, 255, 0, 0);
imagefill($image, 0, 0, $red);
// 输出图像到浏览器
header('Content-Type: image/png');
imagepng($image);
// 释放图像资源
imagedestroy($image);