PHP imagecolorat: Retrieve Pixel Color Index Value
The article explains PHP's imagecolorat function, which returns the RGB integer of a pixel in a true‑color image using the GD library, and shows how to extract red, green, and blue components with bitwise operations through a complete code example.
imagecolorat retrieves the color index of a specific pixel in an image when PHP is compiled with GD library 2.0+ and the image is truecolor.
It returns an integer representing the RGB value, which can be split into red, green, and blue components using bitwise shifts and masks.
Return value : The color index of the pixel at the specified coordinates.
Example :
$im = ImageCreateFromPng("rockym.png");
$rgb = ImageColorAt($im, 100, 100);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.