以下代码引发错误:
const COUNT = 2528; // 2527 works, 2528 errors
const gm = require('gm').subClass({ imageMagick: true });
const brokenData = [];
for (let i = 0; i < COUNT; i++) {
brokenData.push([
Math.random() * 500, Math.random() * 500
]);
}
const tile = gm('./blank-tile.png')
.resize(500, 500)
.fill("red");
brokenData.forEach((point) => {
tile.drawCircle(point[0], point[1], point[0] + 4, point[1]);
});
tile.write(__dirname + '/test.png', (err) => {
if (err) {
throw err;
}
console.log('success');
});
根据评论,绘制 2527 圈时很好,但在 2528 圈时会引发错误。每次都是一样的,至少在我的机器上。
这是错误:
Error: spawn E2BIG
at ChildProcess.spawn (internal/child_process.js:358:11)
at Object.spawn (child_process.js:533:9)
at spawn (/Users/callumacrae/Sites/testing-gm/node_modules/cross-spawn/index.js:17:18)
at gm._spawn (/Users/callumacrae/Sites/testing-gm/node_modules/gm/lib/command.js:224:14)
at /Users/callumacrae/Sites/testing-gm/node_modules/gm/lib/command.js:101:12
at series (/Users/callumacrae/Sites/testing-gm/node_modules/array-series/index.js:11:36)
at gm._preprocess (/Users/callumacrae/Sites/testing-gm/node_modules/gm/lib/command.js:177:5)
at gm.write (/Users/callumacrae/Sites/testing-gm/node_modules/gm/lib/command.js:99:10)
at Object.<anonymous> (/Users/callumacrae/Sites/testing-gm/test.js:21:6)
at Module._compile (internal/modules/cjs/loader.js:688:30)
我假设它来自 gm 内的某个地方,因为我没有提供任何长参数列表!
无论我使用 imagemagick 还是 graphicsmagick,都会发生同样的事情。节点版本 10.13.0。
有任何想法吗?