Php imagecolorallocate
Imagecolorallocate-assign a color image
Int imagecolorallocate (resource $ image, int $ red, int $ green, int $ blue
)
Returns the color of a given RGB component.
Imagecolorallocate () must be called to create each color, which will be used in the image represented by the image.
Note: the first time imagecolorallocate () is called to fill the image of the color palette background-image creation make
Use imagecreate ().
Image
Image resources are created through image functions such as imagecreatetruecolor ().
Red
The value of the red component.
Green
The green component of value.
Blue
The value of the blue component.
These parameters are between 0 and 255, or 0x00 and 0xFF hexadecimal integers.
Report error return value
A-color identifier or FALSE if the allocation fails.
<? Php
$ Im = imagecreate (100,100 );
// Sets background to red
$ Background = imagecolorallocate ($ im, 255, 0, 0 );
// Sets some colors
$ White = imagecolorallocate ($ im, 255,255,255 );
$ Black = imagecolorallocate ($ im, 0, 0, 0 );
// Hexadecimal way
$ White = imagecolorallocate ($ im, 0xFF, 0xFF, 0xFF );
$ Black = imagecolorallocate ($ im, 0x00, 0x00, 0x00 );
?>
There is a very simple function, basically the same imagecolorallocate (), without the need for only one
Image resource work.
<? Php
Function createcolor ($ r, $ g, $ B ){
Return hexdec (str_pad (dechex ($ r), 2, 0, STR_PAD_LEFT). str_pad (dechex ($ g ),
2, 0, STR_PAD_LEFT). str_pad (dechex ($ B), 2, 0, STR_PAD_LEFT ));
}
/* As mentioned above, this function is not exactly the same thing as imagecolorallocate (), instead
An image resource is required. This means that the code in the following two blocks has identical results :*/
$ Color = colorcreate (105,199,204 );
// Block 2
$ Img = imagecreatetruecolor (100,100); // the arguments here don't really
Matter
$ Color = imagecolorallocate ($ img, 105,199,204 );
Imagedestroy ($ img );
?>