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);
?>
输出:
程序2:
// Create the size of image or blank image.
$image = imagecreatetruecolor(500, 300);
// Display the height of image.
echo imagesy($image);
?>
输出:
300
相关文章: