使用 php-gd 循环从图像的每个像素获取 imagecolorat() 数据
我正在尝试使用 imagecolorat() 从每个像素获取 RGB 颜色信息,但我不确定将 RGB 值保存到 $xy() 中的语法是否正确。我正在查看文档,但我仍然不明白出了什么问题。
我的错误显示: 解析错误:语法错误,意外的 ',' in /sites/uploadresults.php 第 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 >> 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
提前致谢!
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 >> 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想应该是
IOW
$xy
是数组的数组,每个子数组 RGB 三元组?顺便说一句,开头的行
$xy = array(i);
看起来很可疑,我认为它应该只是$xy = array();
,即你将其初始化为空数组。I guess it should be
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.