PHP imagecolorat - Get the color index value of a pixel
imagecolorat — Get the color index value of a pixel.
Syntax
int imagecolorat ( resource $image , int $x , int $y )
Returns the color index value of the pixel at the specified position in the image specified by image.
If PHP is compiled with GD library 2.0 or higher and the image is a true color image, this function returns the RGB value of that point as an integer. Use shifting and masking to extract the values of the red, green, and blue components.
Examples
Get the respective RGB values.
<?php
$im = ImageCreateFromPng("example-logo.png");
$rgb = ImageColorAt($im, 100, 25);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
?>
Related Articles
- imagecolorset()Set the color for the specified palette index.
- imagecolorsforindex()Get the color of a specified index.
PHP Image Processing