【问题标题】:Extract frame of gif with graphicsmagick in node.js在 node.js 中使用 graphicsmagick 提取 gif 帧
【发布时间】:2016-05-31 18:01:32
【问题描述】:

我正在尝试使用 node.js 上的 graphicsmagick 将 gif 转换为 png。在他们的文档中,他们有以下代码:

// pull out the first frame of an animated gif and save as png
gm('/path/to/animated.gif[0]')
    .write('/path/to/firstframe.png', function(err){
    if (err) print('aaw, shucks')
})

但是如果我不是从文件中读取数据,而是从流或缓冲区中读取数据呢?在那里我不必给出路径,因此不能附加 [0]。

我需要的是这样的:

gm(streamOrBuffer).extractFrame(0)
    .write('/path/to/firstframe.png', function(err){
    if (err) print('aaw, shucks')
})

有一个类似的问题here,但发帖人最终在画布上绘制了 gif 以提取客户端的第一帧。

我找不到任何看起来可以执行我想要的操作的 gm 命令。有任何想法吗?

【问题讨论】:

    标签: javascript node.js image graphicsmagick


    【解决方案1】:

    根据source,您可以使用.selectFrame(0)

    gm(streamOrBuffer)
        .selectFrame(0)
        .write('/path/to/firstframe.png', function(err) {
            if (err) console.log(err);
        });
    

    【讨论】:

    猜你喜欢
    • 2021-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-22
    • 2019-01-02
    • 2012-09-15
    • 2020-06-26
    • 1970-01-01
    相关资源
    最近更新 更多