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')
})
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].
What I need is something like this:
gm(streamOrBuffer).extractFrame(0)
.write('/path/to/firstframe.png', function(err){
if (err) print('aaw, shucks')
})
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 could not find any gm command that looked like it could do what I want. Any ideas?
According to the source you can use .selectFrame(0)
.
gm(streamOrBuffer)
.selectFrame(0)
.write('/path/to/firstframe.png', function(err) {
if (err) console.log(err);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With