Home > Backend Development > PHP Tutorial > Example of setting color using imagecolorallocate() function in PHP image processing, imagecolorallocate_PHP tutorial

Example of setting color using imagecolorallocate() function in PHP image processing, imagecolorallocate_PHP tutorial

WBOY
Release: 2016-07-13 10:13:51
Original
1355 people have browsed it

An example of using the imagecolorallocate() function to set colors in PHP image processing, imagecolorallocate

While using PHP to dynamically output beautiful images, it is also inseparable from color settings, just like you need to use a palette when painting. To set the color of an image, you need to call the imagecolorallocate() function. If you need to set multiple colors in the image, just call this function multiple times. The prototype of this function looks like this:

Copy code The code is as follows:

int imagecolorallocate(resource $image,int $red,int $green,int $blue) //Assign a color to a picture

This function returns an identifier that represents the color composed of the given RGB components. The parameters $red, $green and $blue are the red, green and blue components of the required color respectively. These parameters are integers from 0 to 255 or hexadecimal from 0x00 to 0xFF. The first parameter $image is the handle of the canvas image. This function must call the color in the image represented by $image. But be aware that if the canvas is created using the imagecreate() function, the first call to the imagecolorallocate() function will fill the background color with the image based on the palette. The usage code of this function is as follows:
Copy code The code is as follows:

$im = imagecreate(100,100);//Provide a canvas resource for setting color function
//Set the background to red
$background = imagecolorallocate($m,255,0,0);//The first call sets the background color for the canvas
//Set some colors
$white = imagecolorallocate($im,255,255,255);//Returns the identifier set to white by a decimal integer
$black = imagecolorallocate($im,0,0,0);//Return the identifier set to black by the decimal parameter
//Hexadecimal mode
$white = imagecolorallocate($im,0xFF,0xFF,0xFF);//Returns the identifier set to white by a hexadecimal integer
$black = imagecolorallocate($im,0x00,0x00,0x00);//Returns the identifier set to black by a hexadecimal integer
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/914044.htmlTechArticlePHP image processing example of using the imagecolorallocate() function to set colors, imagecolorallocate uses PHP to dynamically output beautiful images. , it is also inseparable from the setting of colors, just like painting...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template