PHP imagecolorallocate - to assign a color image
imagecolorallocate - assign a color to an image.
grammar
int imagecolorallocate ( resource $image , int $red , int $green , int $blue )
imagecolorallocate () returns an identifier representing the RGB color from a given component composition. red, green and blue are the desired color red, green, and blue components. These parameters are integers 0-255 or hexadecimal 0x00 to 0xFF. imagecolorallocate () must be called to create each image used in the image represented by the color.
Returns -1 if the allocation fails.
Note: The first time imagecolorallocate () call based on the image will fill the background color palette, which uses imagecreate () image created.
Examples
<?php header("Content-type: image/png"); $im = @imagecreate(100, 50) or die("不能初始化新的 GD 图像流"); $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 above example of the output picture is as follows:
related articles
- imagecolorallocatealpha () assign a color and transparency of an image.
- imagecolordeallocate () unassigned image color.