节点 gm 流上出错
Error on Node gm Stream
我有以下Buffer
对象数组,这些对象是从由jpg
和png
图像组成的编码图像字符串base64
创建的:
[
<Buffer 75 ab 5a 8a 66 a0 7b f8 e9 7a 06 da b1 ee b8 ff d8 ff e0 00 10 4a 46 49 46 00 01 02 00 00 01 00 01 00 00 ff db 00 43 00 03 02 02 03 02 02 03 03 03 03 ... >,
<Buffer 75 ab 5a 8a 66 a0 7b f8 e9 7a 06 da b1 ee b8 ff d8 ff e0 00 10 4a 46 49 46 00 01 02 00 00 01 00 01 00 00 ff db 00 43 00 03 02 02 03 02 02 03 03 03 03 ... >
]
我正在尝试使用Node.js
库gm
将图像拼接在一起。
var currentGm = gm(images.shift());
for (var i=0; i<images.length; i++) {
currentGm.append(images[i]);
}
然后将该数据pipe
为res
jpg
.
currentGm.stream('jpg').pipe(res);
但是我收到此错误:
events.js:141
throw er; // Unhandled 'error' event
^
Error: spawn gm ENOENT
at exports._errnoException (util.js:856:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:178:32)
at onErrorNT (internal/child_process.js:344:16)
at nextTickCallbackWith2Args (node.js:478:9)
at process._tickDomainCallback (node.js:433:17)
我尝试检查err
stream
回调,它null
.
currentGm
也看起来像这样:
gm {
domain: null,
_events: {},
_eventsCount: 0,
_maxListeners: undefined,
_options: {},
data: {},
_in: [],
_out: [],
_outputFormat: null,
_subCommand: 'convert',
sourceBuffer: <Buffer 75 ab 5a 8a 66 a0 7b f8 e9 7a 06 da b1 ee b8 ff d8 ff e0 00 10 4a 46 49 46 00 01 02 00 00 01 00 01 00 00 ff db 00 43 00 03 02 02 03 02 02 03 03 03 03 ... >,
source: 'unknown.jpg',
_sourceFormatters: [ [Function] ] }
回调stdout
对象如下所示:
Socket {
_connecting: false,
_hadError: false,
_handle:
Pipe {
_externalStream: {},
fd: 27,
writeQueueSize: 0,
owner: [Circular],
onread: [Function: onread],
reading: true },
_parent: null,
_host: null,
_readableState:
ReadableState {
objectMode: false,
highWaterMark: 16384,
buffer: [],
length: 0,
pipes: null,
pipesCount: 0,
flowing: null,
ended: false,
endEmitted: false,
reading: true,
sync: false,
needReadable: true,
emittedReadable: false,
readableListening: false,
defaultEncoding: 'utf8',
ranOut: false,
awaitDrain: 0,
readingMore: false,
decoder: null,
encoding: null },
readable: true,
domain: null,
_events:
{ end: { [Function: g] listener: [Function: onend] },
finish: [Function: onSocketFinish],
_socketEnd: [Function: onSocketEnd],
close: [Function] },
_eventsCount: 4,
_maxListeners: undefined,
_writableState:
WritableState {
objectMode: false,
highWaterMark: 16384,
needDrain: false,
ending: false,
ended: false,
finished: false,
decodeStrings: false,
defaultEncoding: 'utf8',
length: 0,
writing: false,
corked: 0,
sync: true,
bufferProcessing: false,
onwrite: [Function],
writecb: null,
writelen: 0,
bufferedRequest: null,
lastBufferedRequest: null,
pendingcb: 0,
prefinished: false,
errorEmitted: false },
writable: false,
allowHalfOpen: false,
destroyed: false,
bytesRead: 0,
_bytesDispatched: 0,
_sockname: null,
_writev: null,
_pendingData: null,
_pendingEncoding: '' }
在 Mac OS X 上,使用 brew
安装 imagemagick
修复了此问题。
brew install imagemagick
在我的router
:
var gm = require('gm').subClass({ imageMagick: true });
相关文章:
- javascript中的数组出错
- 节点Js:How to catch a“;没有这样的文件或目录“;读取线模块出错
- 在Meteor项目中安装并包含npm模块后出错
- 解析JSON并从中删除对象会出错
- AngularJS指令出错-无法读取属性'编译'的未定义
- 使用javascript在MVC中查找网格长度时出错
- 尝试调用AngularJS上的函数时出错
- Google 脚本:用于创建日历活动的脚本运行时不会出错,但不会执行任何操作
- 全局安装gull后出错
- 我在代码点火器中出错
- Java脚本将URL转换为已保存的URL时出错
- Backbone.js将模型绑定到视图时出错
- 将javascript代码转换为jquery代码时出错
- 加载db.json时出错
- 在运行时创建元素时移到一边时出错
- 失败:等待Protractor与页面同步时出错:“”;在窗口上找不到角度”;
- 重置表单字段时出错
- 将对象的列表c#传递给javascript:undefined变量时出错
- 地理定位api和谷歌地图出错
- 节点 gm 流上出错