PHP image processing using the Imagecolorallocate () function to set the color example, imagecolorallocate
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:
Copy the Code code 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:
Copy the Code code 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 background color of the canvas is set for the first call
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
Hexadecimal mode
$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
?>
http://www.bkjia.com/PHPjc/914044.html www.bkjia.com true http://www.bkjia.com/PHPjc/914044.html techarticle PHP image processing using the Imagecolorallocate () function set color example, imagecolorallocate in the use of PHP dynamic output beautiful images, but also inseparable from the color settings, like painting ...