使用node.js中的graphicsmagick提取gif框架 [英] Extract frame of gif with graphicsmagick in node.js

查看:132
本文介绍了使用node.js中的graphicsmagick提取gif框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to convert a gif into a png using graphicsmagick on node.js. In their documentation they have the following code:

// 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]。

But what if I read the data not from a file, but from a stream or buffer? There I do not have to give a path and therefore cannot append the [0].

我需要的是这样的:

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

有一个类似的问题这里,但海报最终在画布上绘制了gif以提取客户端的第一帧。

There was a similar question here, but the poster ended up drawing the gif on a canvas to extract the first frame on the client side.

I找不到任何看起来像我能做的gm命令。有任何想法吗?

I could not find any gm command that looked like it could do what I want. Any ideas?

推荐答案

根据来源你可以使用 .selectFrame(0)

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

这篇关于使用node.js中的graphicsmagick提取gif框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆