Computer >> Computer tutorials >  >> Programming >> PHP

imagecolortransparent() function in PHP


The imagecolortransparent() function is used to set the color of a transparent image.

Syntax

imagecolortransparent ( img, color )

Parameters

  • img: Create image with imagecreatetruecolor() function.

  • color: Color identifier created with imagecolorallocate().

Return

The imagecolortransparent() function returns the identifier of the new transparent color. The return value is -1 if color is not specified and the image has no transparent color.

Example

The following is an example

<?php
   $img = imagecreatetruecolor(500, 400);
   $blue = imagecolorallocate($img, 0, 0, 255);
   $transparent = imagecolorallocate($img, 0, 0, 0);
   imagecolortransparent($img, $transparent);
   imagefilledrectangle($img, 80, 90, 400, 220, $blue);
   header('Content-Type: image/png');
   imagepng($img);
   imagedestroy($img);
?>

Output

The following is the output:

imagecolortransparent() function in PHP