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. Link to comment https://forums.phpfreaks.com/topic/9235-retrieve-pixel-color-from-image/ 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) Link to comment https://forums.phpfreaks.com/topic/9235-retrieve-pixel-color-from-image/#findComment-34022 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] Link to comment https://forums.phpfreaks.com/topic/9235-retrieve-pixel-color-from-image/#findComment-34095 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.