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

imagecolorsforindex

Description

The imagecolorsforindex of Image for PHP get the colors for an index.

Syntax

imagecolorsforindex(
    GdImage $image,
    int $color
): array

Parameters

image

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

color

The color index.

Return

Returns an associative array with red, green, blue and alpha keys that contain the appropriate values for the specified color index.

Examples

1 · return

<?

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

$red = 255;
$green = 128;
$blue = 0;
$alpha = 64;
$background = imagecolorallocatealpha($image, $red, $green, $blue, $alpha);

$x = 0;
$y = 0;
imagefill($image, $x, $y, $background);

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

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

print_r($return);

?>
Array
(
    [red] => 255
    [green] => 128
    [blue] => 0
    [alpha] => 64
)
HomeMenu