PHP如何使用imagecolorallocate()函数(代码实例)

imagecolorallocate()function是PHP中的内置函数, 用于设置图像的颜色。此函数返回以RGB格式给出的颜色。
语法如下:

int imagecolorallocate ( $image, $red, $green, $blue )

参数:该函数接受上述和以下所述的四个参数:
  • $image:它由图像创建功能之一(例如imagecreatetruecolor())返回。它用于创建图像尺寸。
  • $red:此参数用于设置红色分量的值。
  • $green:此参数用于设置绿色分量的值。
  • $blue:此参数用于设置蓝色分量的值。
返回值:如果颜色分配失败, 则此函数返回成功的颜色标识符, 否则返回FALSE。
下面的程序说明了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 ); ?>

输出如下:
PHP如何使用imagecolorallocate()函数(代码实例)

文章图片
程序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如何使用imagecolorallocate()函数(代码实例)

文章图片
相关文章:
  • PHP | imageellipse()函数
  • PHP | imagearc()函数
  • PHP | imagefilledellipse()函数
【PHP如何使用imagecolorallocate()函数(代码实例)】参考: http://php.net/manual/en/function.imagecolorallocate.php

    推荐阅读