我有以下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]);
}然后以jpg的形式将数据pipe到res。
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)我尝试在stream回调中检查err,结果是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: '' }发布于 2016-03-07 03:54:43
在Mac上,安装带有brew的imagemagick修复了这个问题。
brew install imagemagick
在我的router中
var gm = require('gm').subClass({ imageMagick: true });
https://stackoverflow.com/questions/35829696
复制相似问题