piyush_v Posted June 6, 2007 Share Posted June 6, 2007 trying to make a script that interprets an image and reads the rgb values of each pixel. Ive come up with the code tht can interpret the values with help from my friends but i have no idea asto how to print it out. the format is supposed to be Pixel R G B and example line would be 120X200 120 230 240 the code till now is <?php $source_file = "test_image.jpg"; $im = ImageCreateFromJpeg($source_file); $imgw = imagesx($im); $imgh = imagesy($im); // n = total number or pixels $n = $imgw*$imgh; for ($i=0; $i<$imgw; $i++) { for ($j=0; $j<$imgh; $j++) { // get the rgb value for current pixel $rgb = ImageColorAt($im, $i, $j); // extract each value for r, g, b $r = ($rgb >> 16) & 0xFF; $g = ($rgb >> & 0xFF; $b = $rgb & 0xFF; } } ?> any help will be appreciated thanks Link to comment https://forums.phpfreaks.com/topic/54386-output-problem/ Share on other sites More sharing options...
thefortrees Posted June 6, 2007 Share Posted June 6, 2007 Use echo or print. echo - http://us.php.net/manual/en/function.echo.php print - http://us.php.net/manual/en/function.print.php Link to comment https://forums.phpfreaks.com/topic/54386-output-problem/#findComment-268938 Share on other sites More sharing options...
leap500 Posted June 6, 2007 Share Posted June 6, 2007 Hi This should do it: <?php $source_file = "test_image.jpg"; $im = ImageCreateFromJpeg($source_file); $imgw = imagesx($im); $imgh = imagesy($im); // n = total number or pixels $n = $imgw*$imgh; for ($i=0; $i<$imgw; $i++) { for ($j=0; $j<$imgh; $j++) { // get the rgb value for current pixel $rgb = ImageColorAt($im, $i, $j); // extract each value for r, g, b $r = ($rgb >> 16) & 0xFF; $g = ($rgb >> & 0xFF; $b = $rgb & 0xFF; echo $i . "x" . $j . " " . $r . " " . $g . " " . $b . "<br />"; } } ?> Link to comment https://forums.phpfreaks.com/topic/54386-output-problem/#findComment-269011 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.