Forum Moderators: coopster

Message Too Old, No Replies

Retrieve pixels from image

How to retrieve the color of a pixel in PHP?

         

alste123

10:02 am on May 7, 2006 (gmt 0)

10+ Year Member



Hi,

Imagine I have a photo/image and I want to know what color is attributed to a certain pixel.
Is it possible to do that with PHP?

Thanks!

alste123

10:06 am on May 7, 2006 (gmt 0)

10+ Year Member



I found this in the PHP manual:

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

but apparently, it gives me three different colors. Plus, would it still work if $im points to an image file?

Thanks.

jatar_k

7:45 pm on May 8, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



what do you mean it gives you three colours?

universetoday

3:39 am on May 9, 2006 (gmt 0)

10+ Year Member



Is it giving the RGB values? Like 0-255 for red, blue and green? Those can be converted into hex colours.