GdkPixbuf::get_pixel

int get_pixel(int x, int y);

Returns the color of a single pixel. The number returned is a pixel specification. See the example on how to split it into usable values.

Example 9. Get the color of a certain pixel

<?php
//Create a new pixbuf of size 320x240
$pixbuf = new GdkPixbuf(Gdk::COLORSPACE_RGB, true, 8, 320, 240);

//green, half-transparent
//overwrites the previously set color
$pixbuf->fill(128, 255, 0, 128);
echo "setting: (128,255,0,128)\n";

//now get the pixel at a certain position
$pixel = $pixbuf->get_pixel(10, 20);
echo 'pixel: ' . $pixel . "\n";

$r = ($pixel & 0xff000000) >> 24;
$g = ($pixel & 0x00ff0000) >> 16;
$b = ($pixel & 0x0000ff00) >> 8;
$a = ($pixel & 0x000000ff);
echo "rgba: ($r,$g,$b,$a)\n";
?>

See also: put_pixel()