PHP Imagecolortransparent() FunctionImagecolortransparent() function is another inbuilt PHP function mainly used to distinguish a color as transparent. It is used to customize the color of the image to be transparent. It returns the identifier of the new transparent color, where if there is no transparent element defined on an image or no color is specified, the function will return - 1 in return. Syntax Parametersimagecolortransparent() function accepts these two parameters.
The imagecolortransparent( ) function returns the identifier of the new transparent color on successful execution of the program. If the color of the image is not specified or does not contain any transparent color, it will return - 1 on a failed attempt. ExamplesBelow are the multiple examples that use the imagecolortransparent( ) function. Program 1: PHP program to display the basic use of imagecolortransparent( ) 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 2: PHP program to display the basic use of imagecolortransparent( ) 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. And we have used the Imagecolortransparent( ) function to make the black background transparent, and finally, we have used the image-filled rectangle ( ) function to create a blue rectangle. 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 imagecolortransparent( ) 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. And we have used the Imagecolortransparent( ) function to make the black background transparent, and finally, we have used the Imagerectangle ( ) function to create a red hollow 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 basic use of imagecolortransparent( ) 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. To display the output of the image, we have used an inbuilt PHP command header and imagepng to display on the browser. And we have used the Imagecolortransparent( )function to make the black background transparent, and finally, we have used the Image ellipse ( ) function to create a hollow green circle. Next TopicPHP Imagecolorallocate() Function |