diff --git a/commands/9gag.js b/commands/9gag.js index ff3d71d..e634fb1 100644 --- a/commands/9gag.js +++ b/commands/9gag.js @@ -1,4 +1,3 @@ -const fs = require("fs"); const gm = require("gm").subClass({ imageMagick: true }); @@ -10,8 +9,9 @@ exports.run = async (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 data = gm(image.path).coalesce().out("null:").out(watermark).gravity("East").out("-layers", "composite").out("-layers", "optimize"); + const buffer = await gmToBuffer(data, image.outputType); return message.channel.createMessage("", { - file: await gmToBuffer(data, image.outputType), + file: buffer, name: `9gag.${image.outputType}` }); }; diff --git a/commands/bandicam.js b/commands/bandicam.js index bdb5859..052a6cb 100644 --- a/commands/bandicam.js +++ b/commands/bandicam.js @@ -11,8 +11,9 @@ exports.run = async (message) => { gm(image.path).size(async (error, size) => { if (error) throw error; const data = gm(image.path).coalesce().out("null:").out(watermark).gravity("North").resize(null, size.height).out("-layers", "composite").out("-layers", "optimize"); + const buffer = await gmToBuffer(data, image.outputType); return message.channel.createMessage("", { - file: await gmToBuffer(data, image.outputType), + file: buffer, name: `bandicam.${image.outputType}` }); }); diff --git a/commands/blur.js b/commands/blur.js index a466320..5cf5277 100644 --- a/commands/blur.js +++ b/commands/blur.js @@ -8,8 +8,9 @@ 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 blur!`; const command = gm(image.path).blur(10); + const buffer = await gmToBuffer(command, image.outputType); return message.channel.createMessage("", { - file: await gmToBuffer(command, image.outputType), + file: buffer, name: `blur.${image.outputType}` }); }; diff --git a/commands/blurple.js b/commands/blurple.js index 475bc1b..832b066 100644 --- a/commands/blurple.js +++ b/commands/blurple.js @@ -8,8 +8,9 @@ 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 blurple!`; const data = gm(image.path).threshold(75, true).out("+level-colors").out("\"#7289DA\",white"); + const buffer = await gmToBuffer(data, image.outputType); return message.channel.createMessage("", { - file: await gmToBuffer(data, image.outputType), + file: buffer, name: `blurple.${image.outputType}` }); }; diff --git a/commands/circle.js b/commands/circle.js index 1bab266..e2321ae 100644 --- a/commands/circle.js +++ b/commands/circle.js @@ -8,8 +8,9 @@ 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 radial blur!`; const data = gm(image.path).coalesce().out("-radial-blur", 10); + const buffer = await gmToBuffer(data, image.outputType); return message.channel.createMessage("", { - file: await gmToBuffer(data, image.outputType), + file: buffer, name: `circle.${image.outputType}` }); }; diff --git a/commands/deviantart.js b/commands/deviantart.js index bc3e497..e8e168a 100644 --- a/commands/deviantart.js +++ b/commands/deviantart.js @@ -11,8 +11,9 @@ exports.run = async (message) => { gm(image.path).size(async (error, size) => { if (error) throw error; const data = gm(image.path).coalesce().out("null:").out(watermark).gravity("Center").resize(null, size.height).out("-layers", "composite").out("-layers", "optimize"); + const buffer = await gmToBuffer(data, image.outputType); return message.channel.createMessage("", { - file: await gmToBuffer(data, image.outputType), + file: buffer, name: `deviantart.${image.outputType}` }); }); diff --git a/commands/explode.js b/commands/explode.js index 4b731cf..f0ca681 100644 --- a/commands/explode.js +++ b/commands/explode.js @@ -8,8 +8,9 @@ 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 explode!`; const data = gm(image.path).coalesce().implode([-2]); + const buffer = await gmToBuffer(data, image.outputType); return message.channel.createMessage("", { - file: await gmToBuffer(data, image.outputType), + file: buffer, name: `explode.${image.outputType}` }); }; diff --git a/commands/flip.js b/commands/flip.js index 3844247..f430b84 100644 --- a/commands/flip.js +++ b/commands/flip.js @@ -8,8 +8,9 @@ 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 flip!`; const command = gm(image.path).flip(); + const buffer = await gmToBuffer(command, image.outputType); return message.channel.createMessage("", { - file: await gmToBuffer(command, image.outputType), + file: buffer, name: `flip.${image.outputType}` }); }; diff --git a/commands/flop.js b/commands/flop.js index 2f70b67..37b4187 100644 --- a/commands/flop.js +++ b/commands/flop.js @@ -8,8 +8,9 @@ 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 flop!`; const command = gm(image.path).flop(); + const buffer = await gmToBuffer(command, image.outputType); return message.channel.createMessage("", { - file: await gmToBuffer(command, image.outputType), + file: buffer, name: `flop.${image.outputType}` }); }; diff --git a/commands/funky.js b/commands/funky.js index f40a90e..12de603 100644 --- a/commands/funky.js +++ b/commands/funky.js @@ -11,8 +11,9 @@ exports.run = async (message) => { gm(image.path).size(async (error, size) => { if (error) throw error; const data = gm(image.path).coalesce().out("null:").out(watermark).gravity("NorthEast").resize(null, size.height).out("-layers", "composite").out("-layers", "optimize"); + const buffer = await gmToBuffer(data, image.outputType); return message.channel.createMessage("", { - file: await gmToBuffer(data, image.outputType), + file: buffer, name: `funky.${image.outputType}` }); }); diff --git a/commands/gamexplain.js b/commands/gamexplain.js index 8e697a5..4487e64 100644 --- a/commands/gamexplain.js +++ b/commands/gamexplain.js @@ -9,8 +9,9 @@ exports.run = async (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 command = 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").out("-layers", "optimize"); + const buffer = await gmToBuffer(command, image.outputType); return message.channel.createMessage("", { - file: await gmToBuffer(command, image.outputType), + file: buffer, name: `gamexplain.${image.outputType}` }); }; diff --git a/commands/haah.js b/commands/haah.js index 11f6d9c..2f8c364 100644 --- a/commands/haah.js +++ b/commands/haah.js @@ -18,8 +18,9 @@ exports.run = async (message) => { gm(data2).flop().write(data, async (error) => { if (error) throw error; const command = gm(data2).extent(size.width, size.height).out("null:").out(data).geometry(`+${size.width / 2}+0`).out("-layers", "Composite").out("-layers", "optimize"); + const buffer = await gmToBuffer(command, image.outputType); return message.channel.createMessage("", { - file: await gmToBuffer(command, image.outputType), + file: buffer, name: `haah.${image.outputType}` }); }); diff --git a/commands/homebrew.js b/commands/homebrew.js index a96987e..e3fd182 100644 --- a/commands/homebrew.js +++ b/commands/homebrew.js @@ -9,8 +9,9 @@ exports.run = async (message, args) => { const template = "./assets/images/hbc.png"; const cleanedMessage = args.join(" ").toLowerCase().replace(/\n/g, " "); const command = gm(template).gravity("Center").font("./assets/hbc.ttf").out("-kerning", "-5").fill("white").pointSize(96).drawText(0, 0, cleanedMessage); + const buffer = await gmToBuffer(command); return message.channel.createMessage("", { - file: await gmToBuffer(command), + file: buffer, name: "homebrew.png" }); }; diff --git a/commands/hooh.js b/commands/hooh.js index 0aa3123..d1938fd 100644 --- a/commands/hooh.js +++ b/commands/hooh.js @@ -18,8 +18,9 @@ exports.run = async (message) => { gm(data2).flip().write(data, async (error) => { if (error) throw error; const command = gm(data2).extent(size.width, size.height).out("null:").out(data).geometry(`+0+${size.height / 2}`).out("-layers", "Composite").out("-layers", "Optimize"); + const buffer = await gmToBuffer(command, image.outputType); return message.channel.createMessage("", { - file: await gmToBuffer(command, image.outputType), + file: buffer, name: `hooh.${image.outputType}` }); }); diff --git a/commands/hypercam.js b/commands/hypercam.js index b0efe00..a14556d 100644 --- a/commands/hypercam.js +++ b/commands/hypercam.js @@ -11,8 +11,9 @@ exports.run = async (message) => { gm(image.path).size(async (error, size) => { if (error) throw error; const data = gm(image.path).coalesce().out("null:").out(watermark).gravity("NorthWest").resize(null, size.height).out("-layers", "composite").out("-layers", "optimize"); + const buffer = await gmToBuffer(data, image.outputType); return message.channel.createMessage("", { - file: await gmToBuffer(data, image.outputType), + file: buffer, name: `hypercam.${image.outputType}` }); }); diff --git a/commands/ifunny.js b/commands/ifunny.js index 1213a56..b2365fc 100644 --- a/commands/ifunny.js +++ b/commands/ifunny.js @@ -11,8 +11,9 @@ exports.run = async (message) => { gm(image.path).size(async (error, size) => { if (error) throw error; const data = gm(image.path).coalesce().out("null:").out(watermark).gravity("South").resize(size.width, null).out("-layers", "composite").out("-layers", "optimize"); + const buffer = await gmToBuffer(data, image.outputType); return message.channel.createMessage("", { - file: await gmToBuffer(data, image.outputType), + file: buffer, name: `ifunny.${image.outputType}` }); }); diff --git a/commands/implode.js b/commands/implode.js index 9fecdd0..3a27eec 100644 --- a/commands/implode.js +++ b/commands/implode.js @@ -8,8 +8,9 @@ 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 implode!`; const data = gm(image.path).implode([1]); + const buffer = await gmToBuffer(data, image.outputType); return message.channel.createMessage("", { - file: await gmToBuffer(data, image.outputType), + file: buffer, name: `implode.${image.outputType}` }); }; diff --git a/commands/invert.js b/commands/invert.js index 15d1d0c..01f986d 100644 --- a/commands/invert.js +++ b/commands/invert.js @@ -8,8 +8,9 @@ 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 invert!`; const data = gm(image.path).negative(); + const buffer = await gmToBuffer(data, image.outputType); return message.channel.createMessage("", { - file: await gmToBuffer(data, image.outputType), + file: buffer, name: `invert.${image.outputType}` }); }; diff --git a/commands/jpeg.js b/commands/jpeg.js index fff4861..1e9db91 100644 --- a/commands/jpeg.js +++ b/commands/jpeg.js @@ -8,8 +8,9 @@ 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 more JPEG!`; const data = gm(image.path).setFormat("jpg").quality(1); + const buffer = await gmToBuffer(data); return message.channel.createMessage("", { - file: await gmToBuffer(data), + file: buffer, name: "jpeg.jpg" }); }; diff --git a/commands/leak.js b/commands/leak.js index 800f44d..b2c2357 100644 --- a/commands/leak.js +++ b/commands/leak.js @@ -11,8 +11,9 @@ exports.run = async (message) => { const template = "./assets/images/leak.png"; const command = 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"); // 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"); + const buffer = await gmToBuffer(command); return message.channel.createMessage("", { - file: await gmToBuffer(command), + file: buffer, name: `leak.${image.outputType}` }); }; diff --git a/commands/meme.js b/commands/meme.js index 4599ca3..b3c0202 100644 --- a/commands/meme.js +++ b/commands/meme.js @@ -21,8 +21,9 @@ exports.run = async (message, args) => { gm().out("-size", size.width).background("none").gravity("Center").out("(", "(").font("Impact").out("-pointsize", 40).out(`pango:${bottomText ? bottomText.toUpperCase().replace(/&/g, "\\&").replace(/>/g, "\\>").replace(/`).out(")", "(", "+clone").out("-channel", "A").out("-morphology", "EdgeOut", "Octagon", "+channel", "+level-colors", "black", ")").compose("DstOver").out(")", "-composite").write(file3, async (error) => { if (error) throw error; const data = gm(file).out("-coalesce").out("null:").gravity("North").out(file2).out("-layers", "composite").out("null:").gravity("South").out(file3).out("-layers", "composite").out("-layers", "optimize"); + const buffer = await gmToBuffer(data, image.outputType); return message.channel.createMessage("", { - file: await gmToBuffer(data, image.outputType), + file: buffer, name: `meme.${image.outputType}` }); }); diff --git a/commands/scott.js b/commands/scott.js index 15b2204..8df91e7 100644 --- a/commands/scott.js +++ b/commands/scott.js @@ -9,8 +9,9 @@ exports.run = async (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 command = 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").out("-layers", "optimize"); + const buffer = await gmToBuffer(command, image.outputType); return message.channel.createMessage("", { - file: await gmToBuffer(command, image.outputType), + file: buffer, name: `scott.${image.outputType}` }); }; diff --git a/commands/sharpen.js b/commands/sharpen.js index fb7ea57..f098ee4 100644 --- a/commands/sharpen.js +++ b/commands/sharpen.js @@ -8,8 +8,9 @@ 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 sharpen!`; const command = gm(image.path).coalesce().sharpen(10); + const buffer = await gmToBuffer(command, image.outputType); return message.channel.createMessage("", { - file: await gmToBuffer(command, image.outputType), + file: buffer, name: `sharpen.${image.outputType}` }); diff --git a/commands/shutterstock.js b/commands/shutterstock.js index 4b2b47c..fe59f39 100644 --- a/commands/shutterstock.js +++ b/commands/shutterstock.js @@ -11,8 +11,9 @@ exports.run = async (message) => { gm(image.path).size(async (error, size) => { if (error) throw error; const command = gm(image.path).coalesce().out("null:").out(watermark).gravity("Center").resize(null, size.height).out("-layers", "composite").out("-layers", "optimize"); + const buffer = await gmToBuffer(command, image.outputType); return message.channel.createMessage("", { - file: await gmToBuffer(command, image.outputType), + file: buffer, name: `shutterstock.${image.outputType}` }); }); diff --git a/commands/sonic.js b/commands/sonic.js index 1b3c760..cdfbcbf 100644 --- a/commands/sonic.js +++ b/commands/sonic.js @@ -13,8 +13,9 @@ exports.run = async (message, args) => { gm(474, 332).out("+size").background("none").gravity("Center").out("-pointsize", 72).out("-font", "Bitstream Vera Sans").out(`pango:${wrap(cleanedMessage, {width: 15, indent: ""})}`).write(file, async (error) => { if (error) throw error; const command = gm(template).composite(file).gravity("Center").geometry("474x332+160+10"); + const buffer = await gmToBuffer(command, "png"); return message.channel.createMessage("", { - file: await gmToBuffer(command, "png"), + file: buffer, name: "sonic.png" }); }); diff --git a/commands/speed.js b/commands/speed.js index 15d1f9e..2442465 100644 --- a/commands/speed.js +++ b/commands/speed.js @@ -22,8 +22,9 @@ exports.run = async (message) => { } else { const numbers = (await util.promisify(exec)(`seq 0 2 ${value.Scene.length}`)).stdout.split("\n").join(","); const data = gm().out("(").out(image.path).coalesce().out(")").out("-delete", numbers).out("-layers", "optimize"); + const buffer = await gmToBuffer(data, image.outputType); return message.channel.createMessage("", { - file: await gmToBuffer(data, image.outputType), + file: buffer, name: "speed.gif" }); } diff --git a/commands/stretch.js b/commands/stretch.js index 3ec2c5e..a8d726e 100644 --- a/commands/stretch.js +++ b/commands/stretch.js @@ -8,8 +8,9 @@ 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 stretch!`; const data = gm(image.path).coalesce().resize("512x512!"); + const buffer = await gmToBuffer(data, image.outputType); return message.channel.createMessage("", { - file: await gmToBuffer(data, image.outputType), + file: buffer, name: `stretch.${image.outputType}` }); }; diff --git a/commands/swirl.js b/commands/swirl.js index 2140288..41c5517 100644 --- a/commands/swirl.js +++ b/commands/swirl.js @@ -8,8 +8,9 @@ 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 swirl!`; const data = gm(image.path).coalesce().swirl(180); + const buffer = await gmToBuffer(data, image.outputType); return message.channel.createMessage("", { - file: await gmToBuffer(data, image.outputType), + file: buffer, name: `swirl.${image.outputType}` }); }; diff --git a/commands/tile.js b/commands/tile.js index 2df8f38..f3256e0 100644 --- a/commands/tile.js +++ b/commands/tile.js @@ -10,8 +10,9 @@ exports.run = async (message) => { gm(image.path).coalesce().command("montage").out("-duplicate").out(24).tile("5x5").geometry("+0+0").stream("miff", async (error, output) => { if (error) throw error; const data = gm(output).coalesce().resize("800x800>"); + const buffer = await gmToBuffer(data, image.outputType); return message.channel.createMessage("", { - file: await gmToBuffer(data, image.outputType), + file: buffer, name: `tile.${image.outputType}` }); }); diff --git a/commands/trump.js b/commands/trump.js index 97fda9d..19751ce 100644 --- a/commands/trump.js +++ b/commands/trump.js @@ -9,8 +9,9 @@ exports.run = async (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 command = 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").out("-layers", "optimize"); + const buffer = await gmToBuffer(command, image.outputType); return message.channel.createMessage("", { - file: await gmToBuffer(command, image.outputType), + file: buffer, name: `trump.${image.outputType}` }); }; diff --git a/commands/waaw.js b/commands/waaw.js index 0469669..bfcb4da 100644 --- a/commands/waaw.js +++ b/commands/waaw.js @@ -18,8 +18,9 @@ exports.run = async (message) => { gm(data2).flop().write(data, async (error) => { if (error) throw error; const command = gm(data2).extent(size.width, size.height).out("null:").out(data).geometry(`+${size.width / 2}+0`).out("-layers", "Composite").out("-layers", "optimize"); + const buffer = await gmToBuffer(command, image.outputType); return message.channel.createMessage("", { - file: await gmToBuffer(command, image.outputType), + file: buffer, name: `waaw.${image.outputType}` }); }); diff --git a/commands/wall.js b/commands/wall.js index c462927..44edb4d 100644 --- a/commands/wall.js +++ b/commands/wall.js @@ -10,8 +10,9 @@ exports.run = async (message) => { gm(image.path).coalesce().resize(128).stream("miff", async (error, output) => { if (error) throw error; const data = 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"); + const buffer = await gmToBuffer(data, image.outputType); return message.channel.createMessage("", { - file: await gmToBuffer(data, image.outputType), + file: buffer, name: `wall.${image.outputType}` }); }); diff --git a/commands/wdt.js b/commands/wdt.js index f81ca7a..a179b8f 100644 --- a/commands/wdt.js +++ b/commands/wdt.js @@ -9,8 +9,9 @@ exports.run = async (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 command = gm(template).coalesce().out("null:").out(image.path).gravity("Center").resize("374x374>").out("-layers", "composite").out("-layers", "optimize"); + const buffer = await gmToBuffer(command, image.outputType); return message.channel.createMessage("", { - file: await gmToBuffer(command, image.outputType), + file: buffer, name: `wdt.${image.outputType}` }); }; diff --git a/commands/wide.js b/commands/wide.js index 092279b..ae97782 100644 --- a/commands/wide.js +++ b/commands/wide.js @@ -11,8 +11,9 @@ exports.run = async (message) => { if (error) throw error; if (size.width > 10000) return `${message.author.mention}, this image is too wide!`; const data = gm(image.path).coalesce().resize(`${(size.width * 19) / 2}x${size.height / 2}!`); + const buffer = await gmToBuffer(data, image.outputType); return message.channel.createMessage("", { - file: await gmToBuffer(data, image.outputType), + file: buffer, name: `wide.${image.outputType}` }); }); diff --git a/commands/woow.js b/commands/woow.js index f3c9817..785a06b 100644 --- a/commands/woow.js +++ b/commands/woow.js @@ -18,8 +18,9 @@ exports.run = async (message) => { gm(data2).flip().write(data, async (error) => { if (error) throw error; const command = gm(data2).extent(size.width, size.height).out("null:").out(data).geometry(`+0+${size.height / 2}`).out("-layers", "Composite").out("-layers", "optimize"); + const buffer = await gmToBuffer(command, image.outputType); return message.channel.createMessage("", { - file: await gmToBuffer(command, image.outputType), + file: buffer, name: `woow.${image.outputType}` }); }); diff --git a/utils/imagedetect.js b/utils/imagedetect.js index 3fb641f..41b81ff 100644 --- a/utils/imagedetect.js +++ b/utils/imagedetect.js @@ -21,7 +21,6 @@ const typeCheck = async (image, gifv = false) => { return { type: imageType.ext, data: imageBuffer, - url: image, outputType: imageType.ext === "mp4" ? "gif" : imageType.ext, path: path };