php imagecreate 白色,PHP imagecreatetruecolor()用法及代码示例

本文介绍了PHP中的imagecreatetruecolor()函数,用于创建指定尺寸的真彩色图像。示例代码展示了如何使用该函数创建一个300x300像素的空白图像,并填充背景色,然后绘制一个三角形。此外,还提供了一个例子展示如何获取图像的高度。这两个示例帮助理解PHP中处理图像的基本操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

imagecreatetruecolor()函数是PHP中的内置函数,用于创建新的true-color图像。此函数返回给定尺寸的空白图像。

用法:

resource imagecreatetruecolor( $width, $height )

参数:该函数接受上述和以下描述的两个参数:

$width:此参数用于设置图像的宽度。

$height:此参数用于设置图像的高度。

返回值:如果成功,则此函数返回图像资源标识符;如果错误,则返回False。

以下示例程序旨在说明PHP中的imagecreatetruecolor()函数:

程序1:

// Set the vertices of polygon

$values = array(

150,  50, // Point 1 (x, y)

50, 250,  // Point 2 (x, y)

250,  250 // Point 3 (x, y)

);

// Create the size of image or blank image

$image = imagecreatetruecolor(300, 300);

// Set the background color of image

$background_color = imagecolorallocate($image,  0, 153, 0);

// Fill background with above selected color

imagefill($image, 0, 0, $background_color);

// Allocate a color for the polygon

$image_color = imagecolorallocate($image, 255, 255, 255);

// Draw the polygon

imagepolygon($image, $values, 3, $image_color);

// Output the picture to the browser

header('Content-type: image/png');

imagepng($image);

?>

输出:

09c78ef84920817bb21bd7391b7df82a.png

程序2:

// Create the size of image or blank image.

$image = imagecreatetruecolor(500, 300);

// Display the height of image.

echo imagesy($image);

?>

输出:

300

相关文章:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值