PHP Imagecolortransparent() Function

Imagecolortransparent() 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

Parameters

imagecolortransparent() function accepts these two parameters.

S.NoParameterDescriptionOptional / mandatory
1$ imageThis parameter is used to define the size of the image we want to display. This parameter is used by an image resource like the imagecreatetruecolor( ) function, which returns an image source.Mandatory
6$ colorThis parameter is used to define the color of the image. This parameter is used for creating a color identity like the imagecolorallocate ( ) function.Mandatory

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.

Examples

Below are the multiple examples that use the imagecolortransparent( ) function.

Program 1: PHP program to display the basic use of imagecolortransparent( ) function.

Output

PHP Imagecolortransparent() Function

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

PHP Imagecolortransparent() Function

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

PHP Imagecolortransparent() Function

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

PHP Imagecolortransparent() Function

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.






Latest Courses