robertboyle Posted May 7, 2006 Share Posted May 7, 2006 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?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. Quote Link to comment Share on other sites More sharing options...
AndyB Posted May 7, 2006 Share Posted May 7, 2006 It gives you three [b]components[/b] of the color at that pixel - the red, green, and blue values (RGB values) Quote Link to comment Share on other sites More sharing options...
Barand Posted May 7, 2006 Share Posted May 7, 2006 If it's not a truecolor image then imagecolorat() returns the index of the pixel color in the pallette so you need[code]$a = imagecolorat($im, 83, 50);$c = imagecolorsforindex($im, $a);printf('#%02X%02X%02X', $c['red'], $c['green'], $c['blue']);[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.