Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

imagecolortransparent

Description

The imagecolortransparent of Image for PHP define a color as transparent.

Syntax

imagecolortransparent(
    GdImage $image,
    ?int $color = null
): int

Parameters

image

A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor().

color

A color identifier created with imagecolorallocate().

Return

The identifier of the new (or current, if none is specified) transparent color is returned. If color is null, and the image has no transparent color, the returned identifier will be -1.

Examples

1 · image

<?

$width = 100;
$height = 100;
$image = imagecreatetruecolor($width, $height);

$return = imagecolortransparent($image);

echo $return;

?>
-1

2 · color

<?

$width = 100;
$height = 100;
$image = imagecreatetruecolor($width, $height);

$red = 0;
$green = 0;
$blue = 0;
$color = imagecolorallocate($image, $red, $green, $blue);

$return = imagecolortransparent($image, $color);

echo $return;

?>
0

3 · base64

<?

$width = 100;
$height = 100;
$image = imagecreatetruecolor($width, $height);

$red = 0;
$green = 0;
$blue = 0;
$color = imagecolorallocate($image, $red, $green, $blue);

imagecolortransparent($image, $color);

ob_start();

    imagepng($image);

$output = ob_get_clean();

echo '<!doctype html>
<html>
<body>
    <img src="data:image/png;base64,' . base64_encode($output) . '">
</body>
</html>';

?>
<!doctype html>
<html>
<body>
    <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAABnRSTlMAAAAAAABupgeRAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAANElEQVR4nO3BAQ0AAADCoPdPbQ43oAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAfgx1lAABqFDyOQAAAABJRU5ErkJggg==">
</body>
</html>
HomeMenu