Gusepo
Gusepo

Reputation: 889

Get correct color palette from animated GIF in Node.js

I'd like to get the color palette of each frame of an animated GIF. I'm using npm library 'gif-frames' in Node.js to save each frame as an image, my problem is that the images of most of the frames have strange colors, different from the one you see if you open the GIF on a browser or in Photoshop. I guess this is because of the way animated GIF are compressed. I tried solving the problem in Python using PIL but I have the same problem. How can I get an image for each frame with its intended colors?

That's the code I'm using

var gifFrames = require('gif-frames');
var fs = require('fs');

gifFrames({ url: 'icontech-2-2019-5.gif', frames: 67 }).then(function (frameData) {
frameData[0].getImage().pipe(fs.createWriteStream('firstframe.jpg'));
});

I collected in this folder 2 sample animated GIFs and the resulting frames https://drive.google.com/drive/folders/154QMzq3IVTMqiKoX_mURNqvUabT89xfw

Upvotes: 0

Views: 265

Answers (1)

Gusepo
Gusepo

Reputation: 889

I found the problem, I simply have to use the parameter cumulative: true From the module guide: "Specifying cumulative as true will compute each frame by layering it on top of previous frames."

Upvotes: 0

Related Questions