slpctrl Posted January 31, 2009 Share Posted January 31, 2009 <?php function getpixels($pic){ $image = imagecreatefromjpeg($pic); list($width, $height) = getimagesize($pic); $height = $height/2; $vars = array(); for ($i=0; $i<=$width; $i++){ $color = imagecolorat($image, $i, $height); array_push($vars, $color); return $vars; } } $pixls = getpixels("world.jpg"); foreach($pixls as $pixl){ echo "$pixl<br />"; } ?> What I was trying to do here was to get the hex color code of each pixel across an image, but the code returns numbers like this: "162486" which clearly isn't any hex color codes. How can I modify this to return the hex color value of each pixel? Link to comment https://forums.phpfreaks.com/topic/143288-solved-need-some-help-gd-library/ Share on other sites More sharing options...
slpctrl Posted January 31, 2009 Author Share Posted January 31, 2009 Never mind, I just put the return vars in the wrong spot. This does it: <?php function getpixels($pic){ $image = imagecreatefromjpeg($pic); list($width, $height) = getimagesize($pic); $height = $height/2; $vars = array(); for ($i=0; $i<=$width; $i++){ $color = imagecolorat($image, $i, $height); array_push($vars, $color); } return $vars; } $pixls = getpixels("world.jpg"); foreach($pixls as $pixl){ echo "$pixl<br />"; } ?> Link to comment https://forums.phpfreaks.com/topic/143288-solved-need-some-help-gd-library/#findComment-751485 Share on other sites More sharing options...
slpctrl Posted January 31, 2009 Author Share Posted January 31, 2009 Actually, I could use help on one more thing. The 'image' that I'm using here is drawn in php, and is a PHP file. It's MIME type is a .png, but when I enter the .php file as the image obviously it doesn't work. How can I work around this? ??? Link to comment https://forums.phpfreaks.com/topic/143288-solved-need-some-help-gd-library/#findComment-751490 Share on other sites More sharing options...
slpctrl Posted January 31, 2009 Author Share Posted January 31, 2009 Fixed that too. The PHP drew the file with the MIME type of PNG, and I was using imagecreatefromjpg. Simply changing jpg to png solved that. Link to comment https://forums.phpfreaks.com/topic/143288-solved-need-some-help-gd-library/#findComment-751499 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.