The use of PHP to dynamically output beautiful images, but also inseparable from the color settings, like painting when you need to use a palette. To set the color of the image, you need to call the Imagecolorallocate () function to complete. If you need to set multiple colors in the image, just call the function multiple times. The prototype of the function is as follows:
int Imagecolorallocate (resource $image, int $red, int $green, int $blue) //Assign color to a picture
The function returns an identifier that represents a color made up of a given RGB component. The parameters $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 the handle to the canvas image, which must call the color in the image represented by $image. Note, however, that if you are using the Imagecreate () function to create a canvas, the first call to the Imagecolorallocate () function will populate the color palette-based image with the background color. The usage code for this function is as follows:
<?php$im = Imagecreate (100,100);//provide a canvas resource for setting the color function//background set to red $background = Imagecolorallocate ($m, 255,0,0);// The first call is to set the background color for the canvas//Set some colors $white = Imagecolorallocate ($im, 255,255,255);//Returns an identifier set to White by a decimal integer $black = imagecolorallocate ($im, 0,0,0);//Returns an identifier set to Black by the decimal parameter//16 binary $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?>