我正在尝试使用imagecolorat()从每个像素获取rgb颜色信息,我不确定将rgb值保存到$ xy()的语法是否正确。我正在看文档,但我仍然不明白出了什么问题。
我的错误显示:第69行/sites/uploadresults.php中的解析错误:语法错误,意外','
#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 >> 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);
}
}
整个代码在这里: http://pastebin.com/ZNDEzXFK
提前致谢!
答案 0 :(得分:2)
我想它应该是
$xy[i] = array($r, $g, $b);
IOW $xy
是数组数组,每个子数组是RGB三元组?
BTW开头的行$xy = array(i);
看起来很可疑,我认为它应该只是$xy = array();
,即你将它初始化为空数组。