gpt4 book ai didi

javascript - Node gm 流上出现错误

转载 作者:行者123 更新时间:2023-12-03 07:30:13 25 4
gpt4 key购买 nike

我有以下 Buffer 对象数组,这些对象是从由 jpgpng< 组成的 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.jsgm 将图像拼接在一起。

var currentGm = gm(images.shift());
for (var i=0; i<images.length; i++) {
currentGm.append(images[i]);
}

然后将数据以 jpg 的形式管道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: '' }

最佳答案

在 Mac OS X 上,使用 brew 安装 imagemagick 解决了该问题。

brew 安装 imagemagick

在我的路由器中:

var gm = require('gm').subClass({ imageMagick: true });

关于javascript - Node gm 流上出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35829696/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com