使用 php-gd 循环从图像的每个像素获取 imagecolorat() 数据

发布于 2024-11-28 10:39:29 字数 1041 浏览 6 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

素染倾城色 2024-12-05 10:39:29

我想应该是

$xy[i] = array($r, $g, $b);

IOW $xy 是数组的数组,每个子数组 RGB 三元组?

顺便说一句,开头的行 $xy = array(i); 看起来很可疑,我认为它应该只是 $xy = array();,即你将其初始化为空数组。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文