PHP Imagecolorallocate() FunctionImagecolorallocate( ) function is another inbuilt PHP function mainly used to implement a new color to an image. It returns the color of an image in an RGB format (RED GREEN BLUE) SyntaxParameters: This function accepts four parameters.
The imagecolorallocate( ) function returns the identifier of the new color on successful execution of the program. If the color of the image is not specified or does not contain any color, it will return a false on a failed attempt. Program 1: PHP program to display the basic use of imagecolorallocate( ) function Output The above code gives the following output. Here in this program, we have declared various variables like $ image to define the size of the image that we require $background color to define the color of background we require. We have used the image fill ( ) function to set the declared color to the image's background. To display the output of the image, we have used an inbuilt PHP command header and imagepng to display on the browser. Program 2: PHP program to display the basic use of imagecolorallocate ( ) with imagestring ( ) function Output The above program gives this output. Here in this program, we have declared various variables like $ image to define the size of the image that we require, $background color to define the color of background we require, $text color to define the color of text we require. We have used the image string ( ) function to declare the string we want to display as an image. To display the output of the image, we have used an inbuilt PHP command header and imagepng to display on the browser. Program 3: PHP program to display the basic use of imagecolorallocate ( ) with imagefilledrectangel ( ) function Output Here in this program, we have declared various variables like $ image to define the size of the image that we require, $background color to define the background we require, $background - color - 2 to define the other color of background we require. We have used the imagefilledrectangle ( ) function to create a green rectangle. To display the output of the image, we have used an inbuilt PHP command header and imagepng to display on the browser. Program 4: PHP program to display the use of imagecolorallocate ( ) function to draw a polygon using imagecreatetruecolor ( ) function Output Here in this program, we have declared various variables like $ image to define the size of the image that we require, $background color to define the color of background we require, $text color to define the color of text we require, an array $values to set the coordinates of the polygon we need to declare, and we have used image polygon ( ) function to display the polygon we want to display as an image, to display the output of the image we have used an inbuilt PHP command header and imagepng to display on browser. Program 4: PHP program to display the use of imagecolorallocate ( ) function to draw a polygon. Output Here in this program, we have declared various variables like $ image to define the size of the image that we require, $background color to define the color of background we require, $text color to define the color of text we require, an array $values to set the coordinates of the polygon we need to declare, and we have used image polygon ( ) function to display the polygon we want to display as an image, to display the output of the image we have used an inbuilt PHP command header and imagepng to display on browser. Next TopicPHP Image createtruecolor( ) Function |