当前位置: 首页> 函数类别大全> imagecreatetruecolor

imagecreatetruecolor

创建一个新的真彩色图像
名称:imagecreatetruecolor
分类:图像处理GD
所属语言:php
一句话介绍:创建一个新的真彩色图像

imagecreatetruecolor 函数

适用PHP版本

此函数从 PHP 4.3.0 起可用。

函数说明

imagecreatetruecolor() 函数用于创建一个真彩色图像,即带有 RGB 颜色模式的图像。该图像的每个像素可以包含 256 级的红色、绿色和蓝色组成的颜色。

函数语法

resource imagecreatetruecolor(int $width, int $height);

参数

  • $width:图像的宽度(单位:像素)。
  • $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);

同类函数
热门文章