From 6dfba281ef318a89e806f83455a4c8336c3954c8 Mon Sep 17 00:00:00 2001 From: TheEssem Date: Sun, 15 Mar 2020 12:54:51 -0500 Subject: [PATCH] Fixed gifvs not having proper delay --- commands/9gag.js | 2 +- commands/bandicam.js | 3 ++- commands/blur.js | 2 +- commands/blurple.js | 2 +- commands/caption.js | 2 +- commands/circle.js | 2 +- commands/deviantart.js | 2 +- commands/explode.js | 2 +- commands/flip.js | 2 +- commands/flop.js | 2 +- commands/funky.js | 2 +- commands/gamexplain.js | 2 +- commands/haah.js | 2 +- commands/hooh.js | 4 ++-- commands/hypercam.js | 2 +- commands/ifunny.js | 2 +- commands/implode.js | 2 +- commands/invert.js | 2 +- commands/leak.js | 2 +- commands/magik.js | 2 +- commands/meme.js | 2 +- commands/memecenter.js | 2 +- commands/motivate.js | 8 ++++---- commands/reverse.js | 2 +- commands/scott.js | 2 +- commands/sharpen.js | 2 +- commands/shutterstock.js | 2 +- commands/sonic.js | 2 +- commands/speed.js | 4 ++-- commands/spin.js | 2 +- commands/stretch.js | 2 +- commands/swirl.js | 2 +- commands/tile.js | 2 +- commands/trump.js | 2 +- commands/waaw.js | 4 ++-- commands/wall.js | 2 +- commands/wdt.js | 2 +- commands/wide.js | 2 +- commands/woow.js | 2 +- events/ready.js | 6 +++--- utils/imagedetect.js | 8 ++++++-- 41 files changed, 55 insertions(+), 50 deletions(-) diff --git a/commands/9gag.js b/commands/9gag.js index 63d58bb..20449f2 100644 --- a/commands/9gag.js +++ b/commands/9gag.js @@ -7,7 +7,7 @@ exports.run = async (message) => { const image = await require("../utils/imagedetect.js")(message); if (image === undefined) return `${message.author.mention}, you need to provide an image to add a 9GAG watermark!`; const watermark = "./assets/images/9gag.png"; - const buffer = await gm(image.path).coalesce().out("null:").out(watermark).gravity("East").out("-layers", "composite").bufferPromise(image.type); + const buffer = await gm(image.path).coalesce().out("null:").out(watermark).gravity("East").out("-layers", "composite").bufferPromise(image.type, image.delay); return message.channel.createMessage("", { file: buffer, name: `9gag.${image.type}` diff --git a/commands/bandicam.js b/commands/bandicam.js index 50b3c79..15b11b7 100644 --- a/commands/bandicam.js +++ b/commands/bandicam.js @@ -7,7 +7,8 @@ exports.run = async (message) => { const image = await require("../utils/imagedetect.js")(message); if (image === undefined) return `${message.author.mention}, you need to provide an image to add a Bandicam watermark!`; const watermark = "./assets/images/bandicam.png"; - const buffer = await gm(image.path).coalesce().out("null:").out(watermark).gravity("North").resize(null, "%[fx:u.h]").out("-layers", "composite").bufferPromise(image.type); + console.log(image.delay); + const buffer = await gm(image.path).coalesce().out("null:").out(watermark).gravity("North").resize(null, "%[fx:u.h]").out("-layers", "composite").bufferPromise(image.type, image.delay); return message.channel.createMessage("", { file: buffer, name: `bandicam.${image.type}` diff --git a/commands/blur.js b/commands/blur.js index 3c57bce..f8023a0 100644 --- a/commands/blur.js +++ b/commands/blur.js @@ -6,7 +6,7 @@ exports.run = async (message) => { message.channel.sendTyping(); const image = await require("../utils/imagedetect.js")(message); if (image === undefined) return `${message.author.mention}, you need to provide an image to blur!`; - const buffer = await gm(image.path).coalesce().blur(15).bufferPromise(image.type); + const buffer = await gm(image.path).coalesce().blur(15).bufferPromise(image.type, image.delay); return message.channel.createMessage("", { file: buffer, name: `blur.${image.type}` diff --git a/commands/blurple.js b/commands/blurple.js index 23db2c0..14f62e7 100644 --- a/commands/blurple.js +++ b/commands/blurple.js @@ -6,7 +6,7 @@ exports.run = async (message) => { message.channel.sendTyping(); const image = await require("../utils/imagedetect.js")(message); if (image === undefined) return `${message.author.mention}, you need to provide an image to make blurple!`; - const buffer = await gm(image.path).coalesce().threshold(75, true).out("+level-colors").out("\"#7289DA\",white").bufferPromise(image.type); + const buffer = await gm(image.path).coalesce().threshold(75, true).out("+level-colors").out("\"#7289DA\",white").bufferPromise(image.type, image.delay); return message.channel.createMessage("", { file: buffer, name: `blurple.${image.type}` diff --git a/commands/caption.js b/commands/caption.js index 2c2b910..8c30515 100644 --- a/commands/caption.js +++ b/commands/caption.js @@ -12,7 +12,7 @@ exports.run = async (message, args) => { const output = await gm().out("-size", `${size.width}x`).background("white").fill("black").font("./assets/caption.otf", size.width / 10).gravity("Center").out(`caption:${args.join(" ")}`).bufferPromise("png"); const size2 = await gm(output).sizePromise(); //const output2 = await gm(output).gravity("Center").trim().out("+repage").extent(size.width, size2.height + (size.width / 10)).streamPromise(); - const outputFinal = await gm(output).in("(").gravity("Center").trim().out("+repage").extent(size.width, size2.height + (size.width / 10)).out(")").background("white").out("-alpha", "set").out("(").out(image.path).out("-coalesce").out(")").colorspace("sRGB").out("-set", "page", "%[fx:u.w]x%[fx:u.h+v.h]+%[fx:t?(u.w-v.w)/2:0]+%[fx:t?u.h:0]").out("-coalesce").out("null:").out("-insert", 1).out("-layers", "composite").bufferPromise(image.type); + const outputFinal = await gm(output).in("(").gravity("Center").trim().out("+repage").extent(size.width, size2.height + (size.width / 10)).out(")").background("white").out("-alpha", "set").out("(").out(image.path).out("-coalesce").out(")").colorspace("sRGB").out("-set", "page", "%[fx:u.w]x%[fx:u.h+v.h]+%[fx:t?(u.w-v.w)/2:0]+%[fx:t?u.h:0]").out("-coalesce").out("null:").out("-insert", 1).out("-layers", "composite").bufferPromise(image.type, image.delay); await processMessage.delete(); //return upload(message, outputFinal, `caption.${image.type}`); return message.channel.createMessage("", { diff --git a/commands/circle.js b/commands/circle.js index 1e95e1c..d602de5 100644 --- a/commands/circle.js +++ b/commands/circle.js @@ -6,7 +6,7 @@ exports.run = async (message) => { message.channel.sendTyping(); const image = await require("../utils/imagedetect.js")(message); if (image === undefined) return `${message.author.mention}, you need to provide an image to add radial blur!`; - const buffer = await gm(image.path).coalesce().out("-rotational-blur", 10).bufferPromise(image.type); + const buffer = await gm(image.path).coalesce().out("-rotational-blur", 10).bufferPromise(image.type, image.delay); return message.channel.createMessage("", { file: buffer, name: `circle.${image.type}` diff --git a/commands/deviantart.js b/commands/deviantart.js index 4451e04..85d2735 100644 --- a/commands/deviantart.js +++ b/commands/deviantart.js @@ -7,7 +7,7 @@ exports.run = async (message) => { const image = await require("../utils/imagedetect.js")(message); if (image === undefined) return `${message.author.mention}, you need to provide an image to add a DeviantArt watermark!`; const watermark = "./assets/images/deviantart.png"; - const buffer = await gm(image.path).coalesce().out("null:").out(watermark).gravity("Center").resize(null, "%[fx:u.h]").out("-layers", "composite").bufferPromise(image.type); + const buffer = await gm(image.path).coalesce().out("null:").out(watermark).gravity("Center").resize(null, "%[fx:u.h]").out("-layers", "composite").bufferPromise(image.type, image.delay); return message.channel.createMessage("", { file: buffer, name: `deviantart.${image.type}` diff --git a/commands/explode.js b/commands/explode.js index 31abc4d..577485e 100644 --- a/commands/explode.js +++ b/commands/explode.js @@ -6,7 +6,7 @@ exports.run = async (message) => { message.channel.sendTyping(); const image = await require("../utils/imagedetect.js")(message); if (image === undefined) return `${message.author.mention}, you need to provide an image to explode!`; - const buffer = await gm(image.path).coalesce().implode([-2]).bufferPromise(image.type); + const buffer = await gm(image.path).coalesce().implode([-2]).bufferPromise(image.type, image.delay); return message.channel.createMessage("", { file: buffer, name: `explode.${image.type}` diff --git a/commands/flip.js b/commands/flip.js index b384158..af30d0f 100644 --- a/commands/flip.js +++ b/commands/flip.js @@ -6,7 +6,7 @@ exports.run = async (message) => { message.channel.sendTyping(); const image = await require("../utils/imagedetect.js")(message); if (image === undefined) return `${message.author.mention}, you need to provide an image to flip!`; - const buffer = await gm(image.path).flip().bufferPromise(image.type); + const buffer = await gm(image.path).flip().bufferPromise(image.type, image.delay); return message.channel.createMessage("", { file: buffer, name: `flip.${image.type}` diff --git a/commands/flop.js b/commands/flop.js index 9605783..1b611f7 100644 --- a/commands/flop.js +++ b/commands/flop.js @@ -6,7 +6,7 @@ exports.run = async (message) => { message.channel.sendTyping(); const image = await require("../utils/imagedetect.js")(message); if (image === undefined) return `${message.author.mention}, you need to provide an image to flop!`; - const buffer = await gm(image.path).flop().bufferPromise(image.type); + const buffer = await gm(image.path).flop().bufferPromise(image.type, image.delay); return message.channel.createMessage("", { file: buffer, name: `flop.${image.type}` diff --git a/commands/funky.js b/commands/funky.js index a993575..1c6211b 100644 --- a/commands/funky.js +++ b/commands/funky.js @@ -7,7 +7,7 @@ exports.run = async (message) => { const image = await require("../utils/imagedetect.js")(message); if (image === undefined) return `${message.author.mention}, you need to provide an image to add New Funky Mode!`; const watermark = "./assets/images/funky.png"; - const buffer = await gm(image.path).coalesce().out("null:").out(watermark).gravity("NorthEast").resize(null, "%[fx:u.h]").out("-layers", "composite").bufferPromise(image.type); + const buffer = await gm(image.path).coalesce().out("null:").out(watermark).gravity("NorthEast").resize(null, "%[fx:u.h]").out("-layers", "composite").bufferPromise(image.type, image.delay); return message.channel.createMessage("", { file: buffer, name: `funky.${image.type}` diff --git a/commands/gamexplain.js b/commands/gamexplain.js index c0b2c80..73dde1f 100644 --- a/commands/gamexplain.js +++ b/commands/gamexplain.js @@ -7,7 +7,7 @@ exports.run = async (message) => { const image = await require("../utils/imagedetect.js")(message); if (image === undefined) return `${message.author.mention}, you need to provide an image to make a GameXplain thumbnail meme!`; const template = "./assets/images/gamexplain.png"; - const buffer = await gm(template).background("white").out("null:").out("(").out(image.path).coalesce().out("-virtual-pixel", "transparent").resize("1181x571!").out(")").compose("over").gravity("Center").out("-geometry", "+0+40").out("-layers", "composite").bufferPromise(image.type); + const buffer = await gm(template).background("white").out("null:").out("(").out(image.path).coalesce().out("-virtual-pixel", "transparent").resize("1181x571!").out(")").compose("over").gravity("Center").out("-geometry", "+0+40").out("-layers", "composite").bufferPromise(image.type, image.delay); return message.channel.createMessage("", { file: buffer, name: `gamexplain.${image.type}` diff --git a/commands/haah.js b/commands/haah.js index f3ebf4b..56079b7 100644 --- a/commands/haah.js +++ b/commands/haah.js @@ -8,7 +8,7 @@ exports.run = async (message) => { if (image === undefined) return `${message.author.mention}, you need to provide an image to mirror!`; const data = `/tmp/${Math.random().toString(36).substring(2, 15)}.miff`; await gm(image.path).coalesce().gravity("West").crop("50%", 0).out("+repage").writePromise(data); - const buffer = await gm(data).extent("%[fx:u.w*2]", "%[fx:u.h]").out("null:").out("(").out(data).flop().out(")").gravity("East").out("-layers", "Composite").bufferPromise(image.type); + const buffer = await gm(data).extent("%[fx:u.w*2]", "%[fx:u.h]").out("null:").out("(").out(data).flop().out(")").gravity("East").out("-layers", "Composite").bufferPromise(image.type, image.delay); return message.channel.createMessage("", { file: buffer, name: `haah.${image.type}` diff --git a/commands/hooh.js b/commands/hooh.js index 781a938..5501cd4 100644 --- a/commands/hooh.js +++ b/commands/hooh.js @@ -9,8 +9,8 @@ exports.run = async (message) => { const data = `/tmp/${Math.random().toString(36).substring(2, 15)}.miff`; const size = await gm(image.path).sizePromise(); await gm(image.path).coalesce().gravity("South").crop(0, "50%").out("+repage").writePromise(data); - // const buffer = await gm(data2).extent("%[fx:u.w]", "%[fx:u.h*2]").out("null:").out(data).gravity("North").out("-layers", "Composite").bufferPromise(image.type); - const buffer = await gm(data).extent(size.width, size.height).out("null:").out("(").out(data).flip().out(")").geometry(`+0+${size.height / 2}`).out("-layers", "Composite").bufferPromise(image.type); + // const buffer = await gm(data2).extent("%[fx:u.w]", "%[fx:u.h*2]").out("null:").out(data).gravity("North").out("-layers", "Composite").bufferPromise(image.type, image.delay); + const buffer = await gm(data).extent(size.width, size.height).out("null:").out("(").out(data).flip().out(")").geometry(`+0+${size.height / 2}`).out("-layers", "Composite").bufferPromise(image.type, image.delay); return message.channel.createMessage("", { file: buffer, name: `hooh.${image.type}` diff --git a/commands/hypercam.js b/commands/hypercam.js index 8430217..a24376d 100644 --- a/commands/hypercam.js +++ b/commands/hypercam.js @@ -7,7 +7,7 @@ exports.run = async (message) => { const image = await require("../utils/imagedetect.js")(message); if (image === undefined) return `${message.author.mention}, you need to provide an image to add a Hypercam watermark!`; const watermark = "./assets/images/hypercam.png"; - const buffer = await gm(image.path).coalesce().out("null:").out(watermark).gravity("NorthWest").resize(null, "%[fx:u.h]").out("-layers", "composite").bufferPromise(image.type); + const buffer = await gm(image.path).coalesce().out("null:").out(watermark).gravity("NorthWest").resize(null, "%[fx:u.h]").out("-layers", "composite").bufferPromise(image.type, image.delay); return message.channel.createMessage("", { file: buffer, name: `hypercam.${image.type}` diff --git a/commands/ifunny.js b/commands/ifunny.js index c510ff5..9552184 100644 --- a/commands/ifunny.js +++ b/commands/ifunny.js @@ -7,7 +7,7 @@ exports.run = async (message) => { const image = await require("../utils/imagedetect.js")(message); if (image === undefined) return `${message.author.mention}, you need to provide an image to add a iFunny watermark!`; const watermark = "./assets/images/ifunny.png"; - const buffer = await gm(image.path).coalesce().extent("%[fx:u.w]", "%[fx:u.h+(42*min(u.w/1024,u.h/42))]").out("null:").out(watermark).gravity("South").resize("%[fx:u.w]", null).out("-layers", "composite").bufferPromise(image.type); + const buffer = await gm(image.path).coalesce().extent("%[fx:u.w]", "%[fx:u.h+(42*min(u.w/1024,u.h/42))]").out("null:").out(watermark).gravity("South").resize("%[fx:u.w]", null).out("-layers", "composite").bufferPromise(image.type, image.delay); return message.channel.createMessage("", { file: buffer, name: `ifunny.${image.type}` diff --git a/commands/implode.js b/commands/implode.js index 64f3fdc..abb7382 100644 --- a/commands/implode.js +++ b/commands/implode.js @@ -6,7 +6,7 @@ exports.run = async (message) => { message.channel.sendTyping(); const image = await require("../utils/imagedetect.js")(message); if (image === undefined) return `${message.author.mention}, you need to provide an image to implode!`; - const buffer = await gm(image.path).implode([1]).bufferPromise(image.type); + const buffer = await gm(image.path).implode([1]).bufferPromise(image.type, image.delay); return message.channel.createMessage("", { file: buffer, name: `implode.${image.type}` diff --git a/commands/invert.js b/commands/invert.js index ff2e400..9383492 100644 --- a/commands/invert.js +++ b/commands/invert.js @@ -6,7 +6,7 @@ exports.run = async (message) => { message.channel.sendTyping(); const image = await require("../utils/imagedetect.js")(message); if (image === undefined) return `${message.author.mention}, you need to provide an image to invert!`; - const buffer = await gm(image.path).coalesce().negative().bufferPromise(image.type); + const buffer = await gm(image.path).coalesce().negative().bufferPromise(image.type, image.delay); return message.channel.createMessage("", { file: buffer, name: `invert.${image.type}` diff --git a/commands/leak.js b/commands/leak.js index d2be305..aa88efe 100644 --- a/commands/leak.js +++ b/commands/leak.js @@ -8,7 +8,7 @@ exports.run = async (message) => { if (image === undefined) return `${message.author.mention}, you need to provide an image to make a Super Smash Bros. leak meme!`; if (image.type === "gif") return `${message.author.mention}, this command doesn't work with GIFs!`; const template = "./assets/images/leak.png"; - const buffer = await gm(template).out("-background").out("white").out("-gravity").out("Center").out("(").out("-clone").out("0").out("(").out(image.path).out("-virtual-pixel").out("white").out("-resize").out("640x360!").rotate("white", 15).out(")").out("-geometry").out("+450-200").out("-composite").out(")").out("+swap").out("-composite").out("-alpha").out("remove").out("-alpha").out("off").bufferPromise(image.type); + const buffer = await gm(template).out("-background").out("white").out("-gravity").out("Center").out("(").out("-clone").out("0").out("(").out(image.path).out("-virtual-pixel").out("white").out("-resize").out("640x360!").rotate("white", 15).out(")").out("-geometry").out("+450-200").out("-composite").out(")").out("+swap").out("-composite").out("-alpha").out("remove").out("-alpha").out("off").bufferPromise(image.type, image.delay); // const command = gm(template).out("-background", "white").gravity("Center").out("null:").out("(").out(path).out("-resize", "640x360!").out("-virtual-pixel", "white").rotate("white", 15).coalesce().geometry("+450-200").out(")").compose("over").out("-alpha", "remove").out("-alpha", "off").out("-layers", "composite"); return message.channel.createMessage("", { file: buffer, diff --git a/commands/magik.js b/commands/magik.js index eb92138..d245cdf 100644 --- a/commands/magik.js +++ b/commands/magik.js @@ -7,7 +7,7 @@ exports.run = async (message) => { if (image === undefined) return `${message.author.mention}, you need to provide an image to add some magik!`; if (image.type === "gif") return `${message.author.mention}, this command doesn't work with GIFs!`; const processMessage = await message.channel.createMessage(" Processing... This might take a while"); - const resultBuffer = await gm(image.path).in("(").in("(").coalesce().resize(600, 600).out(")").out("-liquid-rescale", "300x300").out(")").out("-liquid-rescale", "800x800").bufferPromise(image.type); + const resultBuffer = await gm(image.path).in("(").in("(").coalesce().resize(600, 600).out(")").out("-liquid-rescale", "300x300").out(")").out("-liquid-rescale", "800x800").bufferPromise(image.type, image.delay); await processMessage.delete(); return message.channel.createMessage("", { file: resultBuffer, diff --git a/commands/meme.js b/commands/meme.js index 726ecf4..e2e00c0 100644 --- a/commands/meme.js +++ b/commands/meme.js @@ -14,7 +14,7 @@ exports.run = async (message, args) => { await gm(image.path).coalesce().resize(600, 600).noProfile().writePromise(file); await gm(file).out("-size", "%[fx:u.w]").out("-delete", "0--1").background("none").gravity("Center").out("(", "(").font("Impact").out("-pointsize", 40).out(`pango:${topText.toUpperCase().replace(/&/g, "\\&").replace(/>/g, "\\>").replace(/`).out(")", "(", "+clone").out("-alpha", "extract").out("-morphology", "EdgeOut", "Octagon", "-background", "black", "-alpha", "shape", ")").compose("DstOver").out(")", "-composite").writePromise(file2); if (bottomText) await gm(file).out("-size", "%[fx:u.w]").out("-delete", "0--1").background("none").gravity("Center").out("(", "(").font("Impact").out("-pointsize", 40).out(`pango:${bottomText.toUpperCase().replace(/&/g, "\\&").replace(/>/g, "\\>").replace(/`).out(")", "(", "+clone").out("-alpha", "extract").out("-morphology", "EdgeOut", "Octagon", "-background", "black", "-alpha", "shape", ")").compose("DstOver").out(")", "-composite").writePromise(file3); - const buffer = await gm(file).out("-coalesce").out("null:").gravity("North").out(file2).out("-layers", "composite").out("null:").gravity("South").out(bottomText ? file3 : "null:").out("-layers", "composite").bufferPromise(image.type); + const buffer = await gm(file).out("-coalesce").out("null:").gravity("North").out(file2).out("-layers", "composite").out("null:").gravity("South").out(bottomText ? file3 : "null:").out("-layers", "composite").bufferPromise(image.type, image.delay); return message.channel.createMessage("", { file: buffer, name: `meme.${image.type}` diff --git a/commands/memecenter.js b/commands/memecenter.js index dd7fcb4..f372c85 100644 --- a/commands/memecenter.js +++ b/commands/memecenter.js @@ -7,7 +7,7 @@ exports.run = async (message) => { const image = await require("../utils/imagedetect.js")(message); if (image === undefined) return `${message.author.mention}, you need to provide an image to add a MemeCenter watermark!`; const watermark = "./assets/images/memecenter.png"; - const output = await gm(image.path).coalesce().background("white").extent("%[fx:u.w]", "%[fx:u.h+15]").out("null:").out(watermark).gravity("SouthEast").compose("over").out("-layers", "composite").bufferPromise(image.type); + const output = await gm(image.path).coalesce().background("white").extent("%[fx:u.w]", "%[fx:u.h+15]").out("null:").out(watermark).gravity("SouthEast").compose("over").out("-layers", "composite").bufferPromise(image.type, image.delay); return message.channel.createMessage("", { file: output, name: `memecenter.${image.type}` diff --git a/commands/motivate.js b/commands/motivate.js index 57bc39b..b2a0c09 100644 --- a/commands/motivate.js +++ b/commands/motivate.js @@ -11,8 +11,8 @@ exports.run = async (message, args) => { const file = `/tmp/${Math.random().toString(36).substring(2, 15)}.miff`; const text = `/tmp/${Math.random().toString(36).substring(2, 15)}.png`; const text2 = `/tmp/${Math.random().toString(36).substring(2, 15)}.png`; - const buffer = await gm().in("(").in(image.path).coalesce().resize(500, 500).borderColor("black").border(5, 5).out(")").borderColor("white").border(3, 3).bufferPromise("miff"); - await gm(buffer).coalesce().background("black").gravity("Center").extent(600, "%[fx:s.h+50]").writePromise(file); + const buffer = await gm().in("(").in(image.path).coalesce().resize(500, 500).borderColor("black").border(5, 5).out(")").borderColor("white").border(3, 3).bufferPromise("miff", image.delay); + await gm(buffer).coalesce().gravity("Center").extent(600, "%[fx:s.h+50]").writePromise(file); const size2 = await gm(file).sizePromise(); await gm().background("black").out("-size", "600").fill("white").font("Times").pointSize(56).gravity("Center").out(`pango:${topText.replace(/&/g, "\\&").replace(/>/g, "\\>").replace(/ { if (bottomText) { await gm().background("black").out("-size", "600").fill("white").font("Times").pointSize(28).gravity("Center").out(`pango:${bottomText.replace(/&/g, "\\&").replace(/>/g, "\\>").replace(/ { const image = await require("../utils/imagedetect.js")(message); if (image === undefined) return `${message.author.mention}, you need to provide a GIF to reverse!`; if (image.type !== "gif") return `${message.author.mention}, that isn't a GIF!`; - const buffer = await gm(image.path).coalesce().out("-reverse").bufferPromise(image.type); + const buffer = await gm(image.path).coalesce().out("-reverse").bufferPromise(image.type, image.delay); return message.channel.createMessage("", { file: buffer, name: "reverse.gif" diff --git a/commands/scott.js b/commands/scott.js index 5f9717d..7fa0ca5 100644 --- a/commands/scott.js +++ b/commands/scott.js @@ -7,7 +7,7 @@ exports.run = async (message) => { const image = await require("../utils/imagedetect.js")(message); if (image === undefined) return `${message.author.mention}, you need to provide an image to make a Scott the Woz TV meme!`; const template = "./assets/images/scott.png"; - const buffer = await gm(template).out("null:").out("(").out(image.path).coalesce().out("-virtual-pixel", "transparent").resize("415x234!").out("+distort", "Perspective", "0,0 129,187 415,0 517,182 415,234 517,465 0,234 132,418").out(")").compose("over").gravity("Center").geometry("-238-98").out("-layers", "composite").bufferPromise(image.type); + const buffer = await gm(template).out("null:").out("(").out(image.path).coalesce().out("-virtual-pixel", "transparent").resize("415x234!").out("+distort", "Perspective", "0,0 129,187 415,0 517,182 415,234 517,465 0,234 132,418").out(")").compose("over").gravity("Center").geometry("-238-98").out("-layers", "composite").bufferPromise(image.type, image.delay); return message.channel.createMessage("", { file: buffer, name: `scott.${image.type}` diff --git a/commands/sharpen.js b/commands/sharpen.js index 854cc50..67e7534 100644 --- a/commands/sharpen.js +++ b/commands/sharpen.js @@ -6,7 +6,7 @@ exports.run = async (message) => { message.channel.sendTyping(); const image = await require("../utils/imagedetect.js")(message); if (image === undefined) return `${message.author.mention}, you need to provide an image to sharpen!`; - const buffer = await gm(image.path).coalesce().sharpen(10).bufferPromise(image.type); + const buffer = await gm(image.path).coalesce().sharpen(10).bufferPromise(image.type, image.delay); return message.channel.createMessage("", { file: buffer, name: `sharpen.${image.type}` diff --git a/commands/shutterstock.js b/commands/shutterstock.js index 62aca00..dc7564c 100644 --- a/commands/shutterstock.js +++ b/commands/shutterstock.js @@ -7,7 +7,7 @@ exports.run = async (message) => { const image = await require("../utils/imagedetect.js")(message); if (image === undefined) return `${message.author.mention}, you need to provide an image to add a Shutterstock watermark!`; const watermark = "./assets/images/shutterstock.png"; - const buffer = await gm(image.path).coalesce().out("null:").out(watermark).gravity("Center").resize(null, "%[fx:u.h]").out("-layers", "composite").bufferPromise(image.type); + const buffer = await gm(image.path).coalesce().out("null:").out(watermark).gravity("Center").resize(null, "%[fx:u.h]").out("-layers", "composite").bufferPromise(image.type, image.delay); return message.channel.createMessage("", { file: buffer, name: `shutterstock.${image.type}` diff --git a/commands/sonic.js b/commands/sonic.js index 743a6c8..01bf812 100644 --- a/commands/sonic.js +++ b/commands/sonic.js @@ -10,7 +10,7 @@ exports.run = async (message, args) => { const file = `/tmp/${Math.random().toString(36).substring(2, 15)}.png`; const cleanedMessage = args.join(" ").replace(/&/g, "\\&").replace(/>/g, "\\>").replace(/${wrap(cleanedMessage, {width: 15, indent: ""})}`).writePromise(file); - const buffer = await gm(template).composite(file).gravity("Center").geometry("474x332+160+10").bufferPromise("png", "sonic"); + const buffer = await gm(template).composite(file).gravity("Center").geometry("474x332+160+10").bufferPromise("png", null, "sonic"); return message.channel.createMessage("", { file: buffer, name: "sonic.png" diff --git a/commands/speed.js b/commands/speed.js index 088a8f7..fc16510 100644 --- a/commands/speed.js +++ b/commands/speed.js @@ -14,14 +14,14 @@ exports.run = async (message) => { const value = await gm(image.path).identifyPromise(); const delay = value.Delay ? value.Delay[0].split("x") : [0, 100]; if (Math.round(parseInt(delay[0]) / 2) >= 2) { - const buffer = await gm().delay(`${parseInt(delay[0]) / 2}x${delay[1]}`).out(image.path).bufferPromise(image.type); + const buffer = await gm().delay(`${parseInt(delay[0]) / 2}x${delay[1]}`).out(image.path).bufferPromise(image.type, image.delay); return message.channel.createMessage("", { file: buffer, name: "speed.gif" }); } else { const numbers = (await util.promisify(exec)(`seq 0 2 ${value.Scene.length}`)).stdout.split("\n").join(","); - const buffer = await gm().out("(").out(image.path).coalesce().out(")").out("-delete", numbers).bufferPromise(image.type); + const buffer = await gm().out("(").out(image.path).coalesce().out(")").out("-delete", numbers).bufferPromise(image.type, image.delay); return message.channel.createMessage("", { file: buffer, name: "speed.gif" diff --git a/commands/spin.js b/commands/spin.js index f370c6a..fc32e9e 100644 --- a/commands/spin.js +++ b/commands/spin.js @@ -6,7 +6,7 @@ exports.run = async (message) => { const image = await require("../utils/imagedetect.js")(message); if (image === undefined) return `${message.author.mention}, you need to provide an image to spin!`; const processMessage = await message.channel.createMessage(" Processing... This might take a while"); - const resultBuffer = await gm(image.path).out("-duplicate", "29").scale("256x256>").scale("256x256<").background("transparent").virtualPixel("background").out("-distort", "SRT", "'%[fx:360*t/n]'").set("delay", "5").set("dispose", "Background").out("-loop", "0").bufferPromise(image.type); + const resultBuffer = await gm(image.path).coalesce().out("-duplicate", "29").scale("256x256>").scale("256x256<").background("white").virtualPixel("background").out("-rotate", "%[fx:360*t/n]").set("delay", "5").set("dispose", "background").out("-loop", "0").bufferPromise("gif"); await processMessage.delete(); return message.channel.createMessage("", { file: resultBuffer, diff --git a/commands/stretch.js b/commands/stretch.js index 7513bf3..5a9a58d 100644 --- a/commands/stretch.js +++ b/commands/stretch.js @@ -6,7 +6,7 @@ exports.run = async (message) => { message.channel.sendTyping(); const image = await require("../utils/imagedetect.js")(message); if (image === undefined) return `${message.author.mention}, you need to provide an image to stretch!`; - const buffer = await gm(image.path).coalesce().resize("512x512!").bufferPromise(image.type); + const buffer = await gm(image.path).coalesce().resize("512x512!").bufferPromise(image.type, image.delay); return message.channel.createMessage("", { file: buffer, name: `stretch.${image.type}` diff --git a/commands/swirl.js b/commands/swirl.js index 57dd5d5..a0ff74f 100644 --- a/commands/swirl.js +++ b/commands/swirl.js @@ -6,7 +6,7 @@ exports.run = async (message) => { message.channel.sendTyping(); const image = await require("../utils/imagedetect.js")(message); if (image === undefined) return `${message.author.mention}, you need to provide an image to swirl!`; - const buffer = await gm(image.path).coalesce().swirl(180).bufferPromise(image.type); + const buffer = await gm(image.path).coalesce().swirl(180).bufferPromise(image.type, image.delay); return message.channel.createMessage("", { file: buffer, name: `swirl.${image.type}` diff --git a/commands/tile.js b/commands/tile.js index b3a1a30..fb62471 100644 --- a/commands/tile.js +++ b/commands/tile.js @@ -7,7 +7,7 @@ exports.run = async (message) => { const image = await require("../utils/imagedetect.js")(message); if (image === undefined) return `${message.author.mention}, you need to provide an image to tile!`; const output = await gm(image.path).coalesce().command("montage").out("-duplicate").out(24).tile("5x5").geometry("+0+0").streamPromise("miff"); - const buffer = await gm(output).coalesce().resize("800x800>").bufferPromise(image.type); + const buffer = await gm(output).coalesce().resize("800x800>").bufferPromise(image.type, image.delay); return message.channel.createMessage("", { file: buffer, name: `tile.${image.type}` diff --git a/commands/trump.js b/commands/trump.js index 794a4e2..b23cbbe 100644 --- a/commands/trump.js +++ b/commands/trump.js @@ -7,7 +7,7 @@ exports.run = async (message) => { const image = await require("../utils/imagedetect.js")(message); if (image === undefined) return `${message.author.mention}, you need to provide an image to make a Trump meme!`; const template = "./assets/images/trump.png"; - const buffer = await gm(template).background("white").out("null:").out("(").out(image.path).coalesce().out("-virtual-pixel", "transparent").resize("365x179!").out("+distort", "Perspective", "0,0 207,268 365,0 548,271 365,179 558,450 0,179 193,450").out(")").compose("over").gravity("Center").geometry("-217-135").out("-layers", "composite").bufferPromise(image.type); + const buffer = await gm(template).background("white").out("null:").out("(").out(image.path).coalesce().out("-virtual-pixel", "transparent").resize("365x179!").out("+distort", "Perspective", "0,0 207,268 365,0 548,271 365,179 558,450 0,179 193,450").out(")").compose("over").gravity("Center").geometry("-217-135").out("-layers", "composite").bufferPromise(image.type, image.delay); return message.channel.createMessage("", { file: buffer, name: `trump.${image.type}` diff --git a/commands/waaw.js b/commands/waaw.js index f873611..8ba67c8 100644 --- a/commands/waaw.js +++ b/commands/waaw.js @@ -11,8 +11,8 @@ exports.run = async (message) => { const size = await gm(image.path).sizePromise(); await gm(image.path).coalesce().gravity("East").crop("50%", 0).out("+repage").writePromise(data2); await gm(data2).flop().writePromise(data); - // const buffer = await gm(data2).extent("%[fx:u.w*2]", "%[fx:u.h]").out("null:").out(data).gravity("West").out("-layers", "Composite").bufferPromise(image.type); - const buffer = await gm(data2).extent(size.width, size.height).out("null:").out(data).geometry(`+${size.width / 2}+0`).out("-layers", "Composite").bufferPromise(image.type); + // const buffer = await gm(data2).extent("%[fx:u.w*2]", "%[fx:u.h]").out("null:").out(data).gravity("West").out("-layers", "Composite").bufferPromise(image.type, image.delay); + const buffer = await gm(data2).extent(size.width, size.height).out("null:").out(data).geometry(`+${size.width / 2}+0`).out("-layers", "Composite").bufferPromise(image.type, image.delay); return message.channel.createMessage("", { file: buffer, name: `waaw.${image.type}` diff --git a/commands/wall.js b/commands/wall.js index 79ba38a..ca31f2a 100644 --- a/commands/wall.js +++ b/commands/wall.js @@ -7,7 +7,7 @@ exports.run = async (message) => { const image = await require("../utils/imagedetect.js")(message); if (image === undefined) return `${message.author.mention}, you need to provide an image to make a wall from!`; const output = await gm(image.path).coalesce().resize(128).streamPromise("miff"); - const buffer = await gm(output).coalesce().virtualPixel("tile").matteColor("none").out("-background", "none").resize("512x512!").out("-distort").out("Perspective").out("0,0,57,42 0,128,63,130 128,0,140,60 128,128,140,140").bufferPromise(image.type); + const buffer = await gm(output).coalesce().virtualPixel("tile").matteColor("none").out("-background", "none").resize("512x512!").out("-distort").out("Perspective").out("0,0,57,42 0,128,63,130 128,0,140,60 128,128,140,140").bufferPromise(image.type, image.delay); return message.channel.createMessage("", { file: buffer, name: `wall.${image.type}` diff --git a/commands/wdt.js b/commands/wdt.js index 6199519..57dd374 100644 --- a/commands/wdt.js +++ b/commands/wdt.js @@ -7,7 +7,7 @@ exports.run = async (message) => { const image = await require("../utils/imagedetect.js")(message); if (image === undefined) return `${message.author.mention}, you need to provide an image to make a "who did this" meme!`; const template = "./assets/images/whodidthis.png"; - const buffer = await gm(template).out("null:").out("(").out(image.path).coalesce().out(")").gravity("Center").resize("374x374>").out("-layers", "composite").bufferPromise(image.type); + const buffer = await gm(template).out("null:").out("(").out(image.path).coalesce().out(")").gravity("Center").resize("374x374>").out("-layers", "composite").bufferPromise(image.type, image.delay); return message.channel.createMessage("", { file: buffer, name: `wdt.${image.type}` diff --git a/commands/wide.js b/commands/wide.js index f2a08ae..1cb8c92 100644 --- a/commands/wide.js +++ b/commands/wide.js @@ -6,7 +6,7 @@ exports.run = async (message) => { message.channel.sendTyping(); const image = await require("../utils/imagedetect.js")(message); if (image === undefined) return `${message.author.mention}, you need to provide an image to stretch!`; - const buffer = await gm(image.path).coalesce().resize("%[fx:(u.w*19)/2]x%[fx:u.h/2]!").bufferPromise(image.type); + const buffer = await gm(image.path).coalesce().resize("%[fx:(u.w*19)/2]x%[fx:u.h/2]!").bufferPromise(image.type, image.delay); return message.channel.createMessage("", { file: buffer, name: `wide.${image.type}` diff --git a/commands/woow.js b/commands/woow.js index 63021f3..37ebcaf 100644 --- a/commands/woow.js +++ b/commands/woow.js @@ -10,7 +10,7 @@ exports.run = async (message) => { const data2 = `/tmp/${Math.random().toString(36).substring(2, 15)}.miff`; await gm(image.path).coalesce().gravity("North").crop(0, "50%").out("+repage").writePromise(data2); await gm(data2).flip().writePromise(data); - const buffer = await gm(data2).extent("%[fx:u.w]", "%[fx:u.h*2]").out("null:").out(data).gravity("South").out("-layers", "Composite").bufferPromise(image.type); + const buffer = await gm(data2).extent("%[fx:u.w]", "%[fx:u.h*2]").out("null:").out(data).gravity("South").out("-layers", "Composite").bufferPromise(image.type, image.delay); return message.channel.createMessage("", { file: buffer, name: `woow.${image.type}` diff --git a/events/ready.js b/events/ready.js index 677d0c3..ec53fda 100644 --- a/events/ready.js +++ b/events/ready.js @@ -50,10 +50,10 @@ module.exports = async () => { gm.prototype.sizePromise = promisify(gm.prototype.size); gm.prototype.identifyPromise = promisify(gm.prototype.identify); //gm.prototype.bufferPromise = promisify(gm.prototype.toBuffer); - gm.prototype.bufferPromise = function(format, type) { + gm.prototype.bufferPromise = function(format, delay, type) { return new Promise((resolve, reject) => { if (format) { - this.out(type !== "sonic" ? "-layers" : "", type !== "sonic" ? "optimize" : "").stream(format, (err, stdout, stderr) => { + this.in(delay ? "-delay" : "", delay ? delay.split("/").reverse().join("x") : "").out(type !== "sonic" ? "-layers" : "", type !== "sonic" ? "optimize" : "").out("-limit", "memory", "64MB").out("-limit", "map", "128MB").stream(format, (err, stdout, stderr) => { if (err) return reject(err); const chunks = []; stdout.on("data", (chunk) => { @@ -69,7 +69,7 @@ module.exports = async () => { }); }); } else { - this.out(type !== "sonic" ? "-layers" : "", type !== "sonic" ? "optimize" : "").stream((err, stdout, stderr) => { + this.in(delay ? "-delay" : "", delay ? delay.split("/").reverse().join("x") : "").out(type !== "sonic" ? "-layers" : "", type !== "sonic" ? "optimize" : "").out("-limit", "memory", "64MB").out("-limit", "map", "128MB").stream((err, stdout, stderr) => { if (err) return reject(err); const chunks = []; stdout.on("data", (chunk) => { diff --git a/utils/imagedetect.js b/utils/imagedetect.js index a653c92..cd22b72 100644 --- a/utils/imagedetect.js +++ b/utils/imagedetect.js @@ -1,6 +1,8 @@ const fetch = require("node-fetch"); const fileType = require("file-type"); -const writeFile = require("util").promisify(require("fs").writeFile); +const { promisify } = require("util"); +const writeFile = promisify(require("fs").writeFile); +const execPromise = promisify(require("child_process").exec); const urlRegex = /(?:\w+:)?\/\/(\S+)/; // this checks if the file is, in fact, an image @@ -18,11 +20,13 @@ const typeCheck = async (image, gifv = false) => { // if it is, then return the url with the file type const path = `/tmp/${Math.random().toString(36).substring(2, 15)}.${imageType.ext}`; await writeFile(path, imageBuffer); - return { + const payload = { data: imageBuffer, type: imageType.ext !== "mp4" ? (imageType.ext === "jpg" ? "jpeg" : imageType.ext) : "gif", path: path }; + if (gifv) payload.delay = (await execPromise(`ffprobe -v 0 -of csv=p=0 -select_streams v:0 -show_entries stream=r_frame_rate ${path}`)).stdout.replace("\n", ""); + return payload; } else { // if not, then return false return false;