So, I want to create a gif and add the image as a frame. I am using gifencoder. I saw examples and itβs pretty easy to add colors, txt, etc., but I couldnβt figure out how to do the same with the image. I need something like a stream of png files.
ex: from website for color frame
let canvas = new Canvas(width, height); var ctx = canvas.getContext('2d'); red rectangle ctx.fillStyle = '#ff0000'; ctx.fillRect(0, 0, 320, 240); encoder.addFrame(ctx);
Edit:
I tried to do something like below, and while the frames appear in my journal, as I would like, the frames are not added, no errors. Before someone suggests converting a png / gif file to base64, this module cannot add such frames that, if you have another question, please continue and say this.
fs.createReadStream('test.gif') .pipe(new GIFDecoder) //gif-stream .pipe(concat(function(frames) { //concat-frames console.log(frames); for (var i=0; i<frames.length; i++) { encoder.addFrame(frames[i]); } }));
no matter what I try at best, I get only a black gif, nothing more.
Edit 2:
Okay, so the reason I am trying to add frames from the gif was because it just seemed easier. Below I tried to get the image, converted it to RGBA (I noticed that the module accepts the rgba format, not rgb, which is probably why it was always black), and then adds the frame. Adding a frame, if I have data, is very simple, because I just call the method and insert the data, so I am going to leave this.
var request = require('request').defaults({ encoding: null }); request.get('https://upload.wikimedia.org/wikipedia/commons/0/01/Quinlingpandabearr.jpg', function (error, response, body) { if (!error && response.statusCode == 200) { var img = new Canvas(105, 159); var context = img.getContext('2d'); img.src = "data:" + response.headers["content-type"] + ";base64," + new Buffer(body).toString('base64'); var img_to_rgba = context.getImageData(0, 0, img.width, img.height); console.log(img_to_rgba);