imagecolorallocate()function是PHP中的内置函数, 用于设置图像的颜色。此函数返回以RGB格式给出的颜色。
语法如下:
int imagecolorallocate ( $image, $red, $green, $blue )
参数:该函数接受上述和以下所述的四个参数:
- $image:它由图像创建功能之一(例如imagecreatetruecolor())返回。它用于创建图像尺寸。
- $red:此参数用于设置红色分量的值。
- $green:此参数用于设置绿色分量的值。
- $blue:此参数用于设置蓝色分量的值。
下面的程序说明了imagecolorallocate()PHP中的功能。
程序1:
<
?php// It create the size of image or blank image.
$image_size = imagecreatetruecolor(500, 300);
// Set the background color of image using
// imagecolorallocate() function.
$bg = imagecolorallocate( $image_size , 0, 103, 0);
// Fill background with above selected color.
imagefill( $image_size , 0, 0, $bg );
// output image in the browser
header( "Content-type: image/png" );
imagepng( $image_size );
// free memory
imagedestroy( $image_size );
?>
输出如下:
文章图片
程序2:
<
?php// It create the size of image or blank image.
$image_size = imagecreatetruecolor(500, 300);
// Set the background color of image.
$bg = imagecolorallocate( $image_size , 0, 103, 0);
// Fill background with above selected color.
imagefill( $image_size , 0, 0, $bg );
// Set the colors of image
$white_color = imagecolorallocate( $image_size , 255, 255, 255);
// Draw a circle
imagearc( $image_size , 200, 150, 200, 200, 0, 360, $white_color );
// output image in the browser
header( "Content-type: image/png" );
imagepng( $image_size );
// free memory
imagedestroy( $image_size );
?>
输出如下:
文章图片
相关文章:
- PHP | imageellipse()函数
- PHP | imagearc()函数
- PHP | imagefilledellipse()函数
推荐阅读
- Linux网络工具相关命令用法详细介绍
- Java标识符介绍和用法示例
- PHP如何使用gmp_div_q()函数(代码示例)
- PHP如何使用ftp_put()函数(代码示例)
- Java如何实现多线程聊天应用程序(S2(客户端编程))
- Python中的构造函数用法快速指南
- Scala的特征线性化详细指南
- Materialize CSS颜色介绍和用法示例
- XP设置系统优化精华 让系统跑得更快