This article describes how to use the imagecolorallocate () function to set the color for PHP image processing. This article provides two ways to set the color in decimal and hexadecimal notation, for more information about how to use PHP to dynamically output beautiful images, see the color settings. To set the image color, call the imagecolorallocate () function. If you need to set multiple colors in the image, you only need to call this function multiple times. The function is prototype as follows:
Int imagecolorallocate (resource $ image, int $ red, int $ green, int $ blue) // assign color to an image
This function returns an identifier representing the color composed of a given RGB component. The $ red, $ green, and $ blue parameters are the red and green colors required. These parameters are integers from 0 to 255 or hexadecimal values 0 × 00 to 0xFF. The 1st parameter $ image is the handle of the canvas image. this function must call the color in the image represented by $ image. However, if you use the imagecreate () function to create a canvas, the first call to the imagecolorallocate () function will fill the background color with the image based on the color palette. The code for using this function is as follows:
For more PHP image processing, use the imagecolorallocate () function to set the color example. For more information, see PHP!