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

imagecolorset

Description

The imagecolorset of Image for PHP set the color for the specified palette index.

Syntax

imagecolorset(
    GdImage $image,
    int $color,
    int $red,
    int $green,
    int $blue,
    int $alpha = 0
): ?false

Parameters

image

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

color

An index in the palette.

red

Value of red component.

green

Value of green component.

blue

Value of blue component.

alpha

Value of alpha component.

Return

The function returns null on success, or false on failure.

Examples

1 · image color red green blue

<?

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

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

$x = 0;
$y = 0;
$color = imagecolorat($image, $x, $y);

$red = 255;
$green = 255;
$blue = 255;

$return = imagecolorset($image, $color, $red, $green, $blue);

var_export($return);

?>
NULL

2 · alpha

<?

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

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

$x = 0;
$y = 0;
$color = imagecolorat($image, $x, $y);

$red = 255;
$green = 255;
$blue = 255;
$alpha = 64;

$return = imagecolorset($image, $color, $red, $green, $blue, $alpha);

var_export($return);

?>
NULL

3 · base64

<?

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

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

$x = 0;
$y = 0;
$color = imagecolorat($image, $x, $y);

$red = 255;
$green = 255;
$blue = 255;
$alpha = 64;
imagecolorset($image, $color, $red, $green, $blue, $alpha);

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,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkAQMAAABKLAcXAAAAA1BMVEX///+nxBvIAAAAAXRSTlN+91uEXQAAAAlwSFlzAAAOxAAADsQBlSsOGwAAABRJREFUOI1jYBgFo2AUjIJRQE8AAAV4AAH5pV7HAAAAAElFTkSuQmCC">
</body>
</html>
HomeMenu