Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return Jimp.read(buffer).then(image => {
let bitmap = new BitmapImage(image.bitmap)
GifUtil.quantizeDekker(bitmap)
let frame = new GifFrame(bitmap)
let tmpGifFile = `${path.join(tmpDirectory, sha1(this.parsedUrl.original.path))}.gif`
return GifUtil.write(tmpGifFile, [frame]).then(gif => {
return fs.unlink(tmpGifFile).then(() => {
return gif.buffer
})
})
})
}
rawFrames.forEach(frames => {
frames.forEach(frame => {
frame.interlaced = false;
});
});
for (let i = 0; i < rawFrames.length; i++) {
if (i === 0) totalWidth += rawFrames[i][0].bitmap.width;
else totalWidth += rawFrames[i][0].bitmap.width + 8;
}
const finalTotalFrames = await prepareEndFrames(totalWidth, totalHeight, rawFrames.slice(), totalFrames);
finalTotalFrames.forEach(frame => {
frame.interlaced = false;
});
GifUtil.quantizeDekker(finalTotalFrames);
const gif = await codec.encodeGif(finalTotalFrames);
let image = gif.buffer;
if (gif.frames.length === 1) {
const frame = gif.frames[0];
const tempImage = new Jimp(0, 0);
tempImage.bitmap = new BitmapImage(frame).bitmap;
image = await new Promise((resolve, reject) => tempImage.getBuffer(MIME_PNG, (error, buffer) => error ? reject(error) : resolve(buffer)));
}
return {
buffer: image,
animated: gif.frames.length > 1,
};
};