Easy Tutorial
❮ Func String Fprintf Func Date Microtime ❯

PHP imagecolorat - Get the Color Index of a Pixel

PHP Image Processing

imagecolorat — Get the color index of a specified pixel.

Syntax

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

Returns the color index of the specified pixel in the image.

If PHP is compiled with the GD library 2.0 or higher and the image is a true color image, this function returns the RGB value as an integer. Use bit-shifting and masking to get the individual red, green, and blue component values.

Example

Get individual RGB values.

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

Related Articles

PHP Image Processing

❮ Func String Fprintf Func Date Microtime ❯