admin管理员组文章数量:1426338
I am trying to pipe 5 specific JPG file names into an animated GIF. I have looked through several libraries and found Gif-Encoder. I am not very good with streams. I cannot seem to figure out how to pipe the RGB result from the JPEG Decoder into the addFrame() method of the encoder.
function createAnimatedGif(jpgPaths, animatedGifPath) {
let encoder = new GifEncoder(1280, 720);
let writeStream = fs.createWriteStream(animatedGifPath);
encoder.pipe(writeStream);
encoder.writeHeader();
jpgPaths.forEach(filePath => {
fs.createReadStream(filePath)
.pipe(new JPEGDecoder)
//.pipe(encoder);
//.pipe(pixels => encoder.addFrame(pixels));
});
encoder.finish();
}
I am trying to pipe 5 specific JPG file names into an animated GIF. I have looked through several libraries and found Gif-Encoder. I am not very good with streams. I cannot seem to figure out how to pipe the RGB result from the JPEG Decoder into the addFrame() method of the encoder.
function createAnimatedGif(jpgPaths, animatedGifPath) {
let encoder = new GifEncoder(1280, 720);
let writeStream = fs.createWriteStream(animatedGifPath);
encoder.pipe(writeStream);
encoder.writeHeader();
jpgPaths.forEach(filePath => {
fs.createReadStream(filePath)
.pipe(new JPEGDecoder)
//.pipe(encoder);
//.pipe(pixels => encoder.addFrame(pixels));
});
encoder.finish();
}
Share
Improve this question
asked Mar 14, 2017 at 23:09
wayofthefuturewayofthefuture
9,4757 gold badges38 silver badges55 bronze badges
1 Answer
Reset to default 6Is using a read streams a must? I had some success using the module 'get-pixels'.
var getPixels = require('get-pixels')
var GifEncoder = require('gif-encoder');
var gif = new GifEncoder(1280, 720);
var file = require('fs').createWriteStream('img.gif');
var pics = ['./pics/1.jpg', './pics/2.jpg', './pics/3.jpg'];
gif.pipe(file);
gif.setQuality(20);
gif.setDelay(1000);
gif.writeHeader();
var addToGif = function(images, counter = 0) {
getPixels(images[counter], function(err, pixels) {
gif.addFrame(pixels.data);
gif.read();
if (counter === images.length - 1) {
gif.finish();
} else {
addToGif(images, ++counter);
}
})
}
addToGif(pics);
本文标签: javascriptPipe multiple JPG39s into an animated GIF using Node JSStack Overflow
版权声明:本文标题:javascript - Pipe multiple JPG's into an animated GIF using Node JS - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745404922a2657207.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论