Latest web development tutorials

PHP imagecolorat - get the color value of a pixel index

PHP Image Processing PHP Image Processing

imagecolorat - get the color index value of a pixel.

grammar

int imagecolorat ( resource $image , int $x , int $y )

Returns the image specified by the drawing color of the pixel location specified index.

If PHP is compiled with the GD library 2.0 or later and the image is a true color image, this function returns an integer RGB values ​​of that point. By displacing the mask to get the value of the red, green, and blue components of each.

Examples

To obtain the respective RGB values.

<?php
$im = ImageCreateFromPng("w3big-logo.png");
$rgb = ImageColorAt($im, 100, 25);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
?>

related articles

PHP Image Processing PHP Image Processing