In the use of PHP dynamic output beautiful images, but also inseparable from the setting of colors, like painting when you need to use the same color palette. To set the color of the image, you need to call the Imagecolorallocate () function to complete. If you need to set a variety of colors in the image, just call the function multiple times. The prototype of the function looks like this:
Copy Code code as follows:
int Imagecolorallocate (resource $image, int $red, int $green, int $blue)//Assign color to a picture
The function returns an identifier that represents the color composed of the given RGB component. Parameter $red, $green and $blue are the red, green and blue components of the desired color respectively. These parameters are integers from 0 to 255 or hexadecimal 0x00 to 0xFF. The 1th parameter $image is a handle to the canvas image that must call the color in the image represented by $image. Note, however, that if the canvas is created using the Imagecreate () function, the first call to the Imagecolorallocate () function fills the background color with the palette-based image. The use code for the function is as follows:
Copy Code code as follows:
<?php
$im = Imagecreate (100,100);//provide a canvas resource for setting color functions
Background set to Red
$background = Imagecolorallocate ($m, 255,0,0);//First call to set the background color for the canvas
Set some colors
$white = Imagecolorallocate ($im, 255,255,255);//Returns an identifier that is set to White by a decimal integer
$black = Imagecolorallocate ($im, 0,0,0)//Returns an identifier set to Black by the decimal parameter
Hexadecimal mode
$white = Imagecolorallocate ($im, 0xff,0xff,0xff);//Returns an identifier set to white by a hexadecimal integer
$black = Imagecolorallocate ($im, 0x00,0x00,0x00);//Returns an identifier set to black by a hexadecimal integer
?>