【发布时间】:2020-06-07 16:38:03
【问题描述】:
我对 PHP 7.4.5 和 GD 有疑问。我有一个图像处理脚本,有时我会收到此错误:
imagecolorallocate(): 红色分量超出范围
有人知道如何避免这种情况吗?
$image = imagecreatetruecolor($calcWidth, $calcHeight);
for ($y = 0; $y < $height; ++$y) {
for ($x = 0; $x < $width; ++$x) {
[$r, $g, $b] = $pixels[$y][$x];
$allocate = imagecolorallocate($image, $r, $g, $b);
imagesetpixel($image, $x, $y, $allocate);
}
}
【问题讨论】:
-
是的,这是我在整个网络上找到的关于此错误的唯一答案。但这并没有帮助,因为我没有透明图像。
-
即使没有透明度,这个答案也应该有所帮助.. 因为使用
imagecolorstotal()应该可以让您检测总颜色是否在范围内?