English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
PHP imagecolorallocate() function allocation color usage and example
Syntax
int imagecolorallocate ( resource $image , int $red , int $green , int $blue ) 255 as an integer or a hexadecimal number from 0x00 to 0xFF. imagecolorallocate() must be called to create each color used in the image represented by image. imagecolorallocate() returns an identifier representing the color composed of the given RGB components. red, green, and blue are the red, green, and blue components of the color required. These parameters are 0 to
If allocation fails, it returns -1.
Note:The first call to imagecolorallocate() will fill the background color for the palette-based image, that is, using imagecreate() established image.
<?php header("Content-type: image/png $im = @imagecreate(100, 50) or die("Unable to initialize a 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 image of the output result of the above example is as follows:
imagecolorallocatealpha() Allocate colors and opacity for an image.
imagecolordeallocate() Deallocate the allocation of image colors.