我有Buffer
个base64
个对象数组,我是根据jpg
编码的图像字符串创建的,包含png
和[
<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: '' }
对象如下所示:
{{1}}
答案 0 :(得分:1)
在Mac OS X上,使用imagemagick
安装brew
解决了问题。
brew install imagemagick
和我的router
:
var gm = require('gm').subClass({ imageMagick: true });