How to use gifwrap - 10 common examples

To help you get started, we’ve selected a few gifwrap examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github GilbertGobbels / GAwesomeBot / Modules / Emoji / PrepareFrames.js View on Github external
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
 */
// Code is slightly modified from the source. See license above.

const { GifCodec, GifFrame, BitmapImage } = require("gifwrap");
const Jimp = require("jimp");
const { AUTO } = Jimp;

const codec = new GifCodec();

module.exports = async (result, buffer) => {
	let frames = [];
	let gif;
	if (Buffer.isBuffer(buffer)) {
		gif = await codec.decodeGif(buffer);
		({ frames } = gif);
	} else if (buffer instanceof GifFrame) {
		frames = [buffer];
	}
	frames.map(async frame => {
		const image = new Jimp(frame.bitmap.width, frame.bitmap.height);
		const bImage = new BitmapImage(frame);
		image.bitmap = bImage.bitmap;
		image.resize(result.type === "unicode" ? 72 : 128, AUTO);
		return new GifFrame(bImage);
github GilbertGobbels / GAwesomeBot / Modules / Emoji / Emoji.js View on Github external
const prepareFrames = require("./PrepareFrames");
const prepareEndFrames = require("./PrepareEndFrames");
const EmojiUtils = require("./EmojiUtil");

const Jimp = require("jimp");
const { read, MIME_PNG, AUTO } = Jimp;
const { GifCodec, GifFrame, BitmapImage, GifUtil } = require("gifwrap");
const { get } = require("snekfetch");

const codec = new GifCodec();

module.exports = async emojis => {
	emojis = emojis.map(e => e.trim()).filter(Boolean);
	if (emojis.length > 6) emojis = emojis.splice(0, 6);
	const results = await Promise.all(emojis.map(e => EmojiUtils.getEmojiMetadata(e)));
	// #region SingleParamGiven
	if (results.length === 1) {
		if (results[0].type === "unicode") {
			return {
				buffer: (await get(results[0].url)).body,
			};
		}
		if (results[0].url.endsWith(".gif")) {
			const decodedGif = await codec.decodeGif((await get(results[0].url)).body);
			const { frames } = decodedGif;
			frames.map(async frame => {
github tt-bot-dev / tt.bot / lib / e2p / prepareEndingFrame.js View on Github external
function getPixl(i) {
            let aPos = pos;
            pos += images[i][0].bitmap.width + 8;
            return aPos;
        }
        const oneLargeImage = new Jimp(total, height);
        let imgMap = images.map(f => {
            if (f[i]) return f[i];
            else return f[0];
        });
        imgMap.forEach((f, idx) => {
            const ima = new Jimp(1, 1, 0);
            ima.bitmap = new GifWrap.BitmapImage(f.bitmap).bitmap;
            oneLargeImage.composite(ima, getPixl(idx), 0);
        });
        f.push(new GifWrap.GifFrame(new GifWrap.BitmapImage(oneLargeImage.bitmap), {
            delayCentisecs: 2
        }));
    }
    console.log("Returned image has", f.length, "frames");
    return f;
};
github GilbertGobbels / GAwesomeBot / Modules / EmojiGIF.js View on Github external
const { get } = require("snekfetch");
const { GifCodec, BitmapImage, GifFrame } = require("gifwrap");
const Jimp = require("jimp");
const { AUTO } = Jimp;
const DJSUtil = require("discord.js/src/util/Util");

const codec = new GifCodec();

module.exports = async emojis => {
	let split = emojis.map(s => s.trim()).filter(s => s !== "");
	if (split.length > 3) split = split.slice(0, 3);

	const getEmoji = async emoji => {
		let	emoji2 = DJSUtil.parseEmoji(emoji);
		if (emoji2 && emoji2.animated) {
			const { body } = await get(`https://cdn.discordapp.com/emojis/${emoji2.id}.gif`);
			return body;
		} else if (/^\d{17,19}$/.test(emoji)) {
			const { body } = await get(`https://cdn.discordapp.com/emojis/${emoji}.gif`);
			return body;
		} else {
			return null;
		}
github GilbertGobbels / GAwesomeBot / Modules / Emoji / PrepareEndFrames.js View on Github external
const getPixel = index => {
			const aPos = pos;
			pos += images[index][0].bitmap.width + 8;
			return aPos;
		};
		const largeFrame = new Jimp(totalWidth, totalHeight);
		const imageMap = images.map(frame => {
			if (frame[i]) return frame[i];
			return frame[0];
		});
		imageMap.forEach((frame, index) => {
			const tempImage = new Jimp(0, 0);
			tempImage.bitmap = new BitmapImage(frame.bitmap).bitmap;
			largeFrame.composite(tempImage, getPixel(index), 0);
		});
		finishedFrames.push(new GifFrame(new BitmapImage(largeFrame.bitmap), {
			delayCentisecs: 2,
		}));
	}
	return finishedFrames;
};
github GilbertGobbels / GAwesomeBot / Modules / Emoji / Emoji.js View on Github external
frames.map(async frame => {
				const image = new Jimp(frame.bitmap.width, frame.bitmap.height);
				const bImage = new BitmapImage(frame);
				image.bitmap = bImage.bitmap;
				image.resize(128, AUTO);
				return new GifFrame(bImage);
			});
			const { buffer } = await codec.encodeGif((await Promise.all(frames)).map(frame => {
github tt-bot-dev / tt.bot / lib / e2p / prepareFrames.js View on Github external
frames.map(g => new Promise((rs, rj) => new Jimp(g.bitmap.width, g.bitmap.height, (e, image) => {
        if (e) rj(e);
        let bImg = new GifWrap.BitmapImage(g);
        image.bitmap = bImg.bitmap;
        let w = result.type == "unicodeEmote" ? 72 : 128;
        image.resize(w,AUTO);
        rs(new GifWrap.GifFrame(bImg));
    })
    ));
github dadi / cdn / dadi / lib / handlers / image.js View on Github external
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
      })
    })
  })
}
github GilbertGobbels / GAwesomeBot / Modules / Emoji / PrepareFrames.js View on Github external
frames.map(async frame => {
		const image = new Jimp(frame.bitmap.width, frame.bitmap.height);
		const bImage = new BitmapImage(frame);
		image.bitmap = bImage.bitmap;
		image.resize(result.type === "unicode" ? 72 : 128, AUTO);
		return new GifFrame(bImage);
	});
	return {
github GilbertGobbels / GAwesomeBot / Modules / EmojiGIF.js View on Github external
const img = new Jimp(frame.bitmap.width, frame.bitmap.height, (error, image) => {
				if (error) return reject(error);
				let bImage = new BitmapImage(frame);
				image.bitmap = bImage.bitmap;
				image.resize(128, AUTO);
				resolve(new GifFrame(bImage));
			});
		}));

gifwrap

A Jimp-compatible library for working with GIFs

MIT
Latest version published 2 years ago

Package Health Score

65 / 100
Full package analysis