JQu*_*ile 5 javascript node.js
我正在使用Gifshot生成动画。我成功生成了一个“文件”。但是,似乎编码已关闭。通过以下代码生成生成的图像:
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');
}
}
);
}
}
);
Run Code Online (Sandbox Code Playgroud)
当上面的代码运行时,animation.gif会生成到我的本地文件系统中(它会生成一个108kb的文件)。但是,当我打开它时,该动画实际上并不存在。我不确定自己在做什么错。我知道Gifshot返回Base 64图像。我认为这就是问题所在。因此,我尝试整合此处找到的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');
}
}
);
}
}
);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1025 次 |
| 最近记录: |