简体   繁体   English

从 Node.js 中的动画 GIF 获取正确的调色板

[英]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.我想获得动画 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.我在 Node.js 中使用 npm 库 'gif-frames' 将每个帧保存为图像,我的问题是大多数帧的图像都有奇怪的 colors,如果你在浏览器上打开的 GIF 不同,或在 Photoshop 中。 I guess this is because of the way animated GIF are compressed.我想这是因为动画 GIF 的压缩方式。 I tried solving the problem in Python using PIL but I have the same problem.我尝试使用 PIL 解决 Python 中的问题,但我遇到了同样的问题。 How can I get an image for each frame with its intended colors?如何获得具有预期 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我在这个文件夹中收集了 2 个示例动画 GIF 和生成的帧https://drive.google.com/drive/folders/154QMzq3IVTMqiKoX_mURNqvUabT89xfw

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."我发现了问题,我只需要使用参数cumulative: true来自模块指南:“将累积指定为 true 将通过将每一帧叠加在前一帧之上来计算每一帧。”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM