imagecolorallocate — Assign a color to an image.
int imagecolorallocate ( resource $image , int $red , int $green , int $blue )
imagecolorallocate() returns an identifier representing a color consisting of the given RGB components. 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 from 0x00 to 0xFF. imagecolorallocate() must be called to create each color used in the image represented by image.
Returns -1 if allocation fails.
Note: The first call to imagecolorallocate() will fill the background color of the palette-based image, that is, the image created with imagecreate().
<?phpheader("Content-type: image/png");$im = @imagecreate(100, 50) or die("Cannot initialize new GD image stream");$background_color = imagecolorallocate($im, 255, 255 , 255);$text_color = imagecolorallocate($im, 233, 14, 91);imagestring($im, 1, 5, 5, "A Simple Text String", $text_color);imagepng($im);imagedestroy($im);?>
The picture of the output result of the above example is as follows:
imagecolorallocatealpha() assigns color and transparency to an image.
imagecolordeallocate() Deallocates an image color.