【发布时间】:2016-11-15 09:23:04
【问题描述】:
我编写了这段代码来获取图像的第一个像素和最后一个像素的十六进制颜色。 第一个像素的代码有效,我得到了十六进制代码。 但是对于最后一个像素,我有一个错误:
PHP Notice: imagecolorat(): 1,1024 is out of bounds in /var/playground/imghex.php on line 55
这是我的代码:
$gradientHeight = getimagesize($res["gradient"]);
// get Positions
$im = imagecreatefrompng($res["gradient"]);
$rgb = imagecolorat($im, 0, 0);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
// store
$res["Gradient1"] = rgb2hex([$r, $g, $b]);
// get positions
print_r($gradientHeight);
$rgb2 = imagecolorat($im, $gradientHeight[0], $gradientHeight[1]);
$r2 = ($rgb2 >> 16) & 0xFF;
$g2 = ($rgb2 >> 8) & 0xFF;
$b2 = $rgb2 & 0xFF;
// store
$res["Gradient2"] = rgb2hex([$r2, $g2, $b2]);
// print
print_r($res);
怎么了?我没有看到任何错误
【问题讨论】:
-
@FirstOne 你的意思是
$rgb2 = imagecolorat($im, $gradientHeight[0] - 1, $gradientHeight[1]);吗?因为PHP Notice: imagecolorat(): 0,1024 is out of bounds -
已解决,谢谢
:)请给出答案,以便我为您投票并选择您的有效答案
标签: php hex gd getimagesize