English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Basic PHP Tutorial

Advanced PHP Tutorial

PHP & MySQL

PHP Reference Manual

Usage and examples of PHP imagecolorat() function to get the color index value of a pixel

PHP Image Processing

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 the GD library is added when PHP is compiled 2If the PHP version is 0.0 or higher and the image is a true-color image, this function returns the RGB value of the point as an integer. Use bit shifting and masking to get the value of the red, green, and blue components separately.

Example

Get the individual RGB values.

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

Related articles

PHP Image Processing