twolfson / gif-encoder

Streaming GIF encoder
The Unlicense
87 stars 10 forks source link

Add image frame to gif #9

Closed Wodki closed 7 years ago

Wodki commented 7 years ago
var file = require('fs').createWriteStream('img.gif');
gif.pipe(file);
gif.writeHeader();    

fs.createReadStream('mygif.gif')
.pipe(new GIFDecoder)
.pipe(concat(function(frames) {
    console.log(frames)
    for (var i=0; i<frames.length; i++) {
        gif.addFrame(frames[i]);
    }
    gif.finish();
}));

so I am trying to add a single frame to the gif, that is my image/other gif/whatever but I cant at best I get a black gif, any ideas? I have been trying to do so for the past 2-3 days with this and other modules but with no success, any help will be really appreciated, thanks.

ps: I also tried converting a png to base64 but as I came to understand it doesnt accept base 64.

twolfson commented 7 years ago

I'm going to guess you're using gif-stream for GIFDecoder:

https://www.npmjs.com/package/gif-stream

This package returns an array of RGB pixels whereas we expect RGBA. As a result, we are likely reading the second frame's red channel as our alpha channel.

I suggest attacking this in 2 parts: