PHP | imagecolorat() function (original) (raw)

Last Updated : 11 Jul, 2025

The imagecolorat() function is an inbuilt function in PHP which is used to get the index of the color of the pixel. This function returns the pixel value at the specified location.
Syntax:

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

Parameters: This function accepts three parameters as mentioned above and described below:

Return Value: This function returns the color index (color pixel value) or FALSE on failure.
Below program illustrate the imagecolorat() function in PHP.
Note: The image given below is used in the following program.

geeks image

Program 1:

php `

rgb=imagecolorat(rgb = imagecolorat(rgb=imagecolorat(image, 30, 25); red=(red = (red=(rgb >> 16) & 255; green=(green = (green=(rgb >> 8) & 255; blue=blue = blue=rgb & 255; var_dump($red, green,green, green,blue); ?>

`

Output:

int(34) int(170) int(66)

Program 2:

php `

rgb=imagecolorat(rgb = imagecolorat(rgb=imagecolorat(image, 30, 25); // Assign color name and its value. colors=imagecolorsforindex(colors = imagecolorsforindex(colors=imagecolorsforindex(image, $rgb); var_dump($colors); ?>

`

Output:

array(4) { ["red"]=> int(34) ["green"]=> int(170) ["blue"]=> int(66) ["alpha"]=> int(0) }

Reference: https://www.php.net/manual/en/function.imagecolorat.php