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

imagecolorat

Description

The imagecolorat of Image for PHP get the index of the color of a pixel.

Syntax

imagecolorat(
    GdImage $image,
    int $x,
    int $y
): int|false

Parameters

image

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

x

x-coordinate of the point.

y

y-coordinate of the point.

Return

Returns the index of the color or false on failure.

Warning: This function may return Boolean false, but may also return a non-Boolean value which evaluates to false. Use the === operator for testing the return value of this function.

Examples

1 · return

<?

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

$x = 0;
$y = 0;

$return = imagecolorat($image, $x, $y);

var_export($return);

?>
0

2 · >>

<?

$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);

$r = 0xff & ($color >> 16);
$g = 0xff & ($color >> 8);
$b = 0xff & $color;
$a = 0xff & ($color >> 24);

var_dump($r, $g, $b, $a);

?>
int(255)
int(128)
int(0)
int(64)
HomeMenu