我正在使用Gifshot生成动画。我成功生成了一个"file"。但是,似乎编码已关闭。通过以下代码生成生成的图像:
var images = [
'http://i.imgur.com/2OO33vX.jpg',
'http://i.imgur.com/qOwVaSN.png',
'http://i.imgur.com/Vo5mFZJ.gif'
];
var gifshot = require('gifshot');
gifshot.createGIF(
{ 'images':images, 'numFrames': images.length },
function(obj) {
if (!obj.error) {
fs.writeFile(
'./animation.gif', obj.image, 'base64',
function(err) {
if (err) {
alert(err);
} else {
alert('Should be all good');
}
}
);
}
}
);
当以上代码运行时,animation.gif会生成到我的本地文件系统中(它会生成一个108kb的文件)。但是,当我打开它时,该动画实际上并不存在。我不确定自己在做什么错。我知道Gifshot返回Base 64图像。我认为这就是问题所在。因此,我尝试整合发现的here的SO答案。但是,那也不起作用。我不确定自己在做什么错。任何帮助深表感谢。
谢谢!
最佳答案
尝试模块 base64image-to-file
var images = [
'http://i.imgur.com/2OO33vX.jpg',
'http://i.imgur.com/qOwVaSN.png',
'http://i.imgur.com/Vo5mFZJ.gif'
];
var gifshot = require('gifshot');
var base64ImageToFile = require('base64image-to-file'); //// new
gifshot.createGIF(
{ 'images':images, 'numFrames': images.length },
function(obj) {
if (!obj.error) {
base64ImageToFile(obj.image, '.', 'animation.gif', //// new
function(err) {
if (err) {
alert(err);
} else {
alert('Should be all good');
}
}
);
}
}
);
关于javascript - 通过Node将.gif保存到本地文件系统,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33738595/