Getting imagecolorat() data from every pixel from image using php-gd loop
I'm trying to get rgb color info from every pixel using imagecolorat() and I'm not sure if my syntax to save rgb values into $xy() is correct. I'm looking at documentation but I'm still not understanding what is going wrong.
My error shows: Parse error: syntax error, unexpected ',' in /sites/uploadresults.php on line 69
#loop to populate rgb values and save to array: $xy
$imagew = imagesx($img);
$imageh = imagesy($img);
$xy = array(i);
echo "Image (w,h): ($imagew, $imageh)<br/>";
$x = 0;
$y = 0;
for ($x = 0; $x <= $imagew; $x++) {
for ($y = 0;$y <= $imageh; $y++ ) {
$rgb = imagecolorat($img, $x, $y);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 开发者_Python百科8) & 0xFF;
$b = $rgb & 0xFF;
#loop to save ($r,$g,$b) into $xy
for ($i = 0; $i <= $xytotal; $i++) {
$xy[i] = ($r, $g, $b);
}
echo "xy: $xy x: $x, y: $y <br/>";
var_dump($r, $g, $b);
}
}
Entire code is here: http://pastebin.com/ZNDEzXFK
Thanks in advance!
I guess it should be
$xy[i] = array($r, $g, $b);
IOW $xy
is array of arrays, each subarray RGB triple?
BTW the line $xy = array(i);
in the beginning looks suspicious, I think it should be just $xy = array();
, ie you initialize it to empty array.
精彩评论