Added support for "gifv"s, fixed embed issue with image

This commit is contained in:
TheEssem 2020-02-18 14:44:39 -06:00
parent fb59135388
commit 777b86e480
41 changed files with 167 additions and 175 deletions

View file

@ -1,3 +1,4 @@
const fs = require("fs");
const gm = require("gm").subClass({
imageMagick: true
});
@ -8,10 +9,10 @@ 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 data = gm(image.data).coalesce().out("null:").out(watermark).gravity("East").out("-layers", "composite").out("-layers", "optimize");
const data = gm(image.path).coalesce().out("null:").out(watermark).gravity("East").out("-layers", "composite").out("-layers", "optimize");
return message.channel.createMessage("", {
file: await gmToBuffer(data),
name: `9gag.${image.type}`
file: await gmToBuffer(data, image.outputType),
name: `9gag.${image.outputType}`
});
};

View file

@ -8,12 +8,12 @@ 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";
gm(image.data).size(async (error, size) => {
gm(image.path).size(async (error, size) => {
if (error) throw error;
const data = gm(image.data).coalesce().out("null:").out(watermark).gravity("North").resize(null, size.height).out("-layers", "composite").out("-layers", "optimize");
const data = gm(image.path).coalesce().out("null:").out(watermark).gravity("North").resize(null, size.height).out("-layers", "composite").out("-layers", "optimize");
return message.channel.createMessage("", {
file: await gmToBuffer(data),
name: `bandicam.${image.type}`
file: await gmToBuffer(data, image.outputType),
name: `bandicam.${image.outputType}`
});
});
};

View file

@ -7,10 +7,10 @@ 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 command = gm(image.data).blur(10);
const command = gm(image.path).blur(10);
return message.channel.createMessage("", {
file: await gmToBuffer(command),
name: `blur.${image.type}`
file: await gmToBuffer(command, image.outputType),
name: `blur.${image.outputType}`
});
};

View file

@ -7,10 +7,10 @@ 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 data = gm(image.data).threshold(75, true).out("+level-colors").out("\"#7289DA\",white");
const data = gm(image.path).threshold(75, true).out("+level-colors").out("\"#7289DA\",white");
return message.channel.createMessage("", {
file: await gmToBuffer(data),
name: `blurple.${image.type}`
file: await gmToBuffer(data, image.outputType),
name: `blurple.${image.outputType}`
});
};

View file

@ -1,17 +1,15 @@
const fs = require("fs");
const gm = require("gm").subClass({
imageMagick: true
});
const gmToBuffer = require("../utils/gmbuffer.js");
//const upload = require("../utils/upload.js");
exports.run = async (message, args) => {
const image = await require("../utils/imagedetect.js")(message);
if (image === undefined) return `${message.author.mention}, you need to provide an image/GIF to add a caption!`;
if (args.length === 0) return `${message.author.mention}, you need to provide some text to add a caption!`;
const path = `/tmp/${Math.random().toString(36).substring(2, 15)}.${image.type}`;
const processMessage = await message.channel.createMessage("<a:processing:479351417102925854> Processing... This might take a while");
require("util").promisify(fs.writeFile)(path, image.data);
gm(image.data).size(async (error, size) => {
gm(image.path).size(async (error, size) => {
if (error) throw error;
const command = gm().out("-size", `${size.width}x`).background("white").fill("black").font("./assets/caption.otf", size.width / 10).gravity("Center").out(`caption:${args.join(" ")}`);
const output = await gmToBuffer(command, "png");
@ -19,12 +17,13 @@ exports.run = async (message, args) => {
if (error) throw error;
gm(output).gravity("Center").trim().out("+repage").extent(size.width, size2.height + (size.width / 10)).stream(async (error, output2) => {
if (error) throw error;
const command3 = gm(output2).out("-alpha", "set").background("none").out("(").out(path).out("-coalesce").out(")").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").out("-layers", "optimize");
const outputFinal = await gmToBuffer(command3, image.type);
const command3 = gm(output2).out("-alpha", "set").background("none").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").out("-layers", "optimize");
const outputFinal = await gmToBuffer(command3, image.outputType);
await processMessage.delete();
//return upload(message, outputFinal, `caption.${image.type}`);
return message.channel.createMessage("", {
file: outputFinal,
name: `caption.${image.type}`
name: `caption.${image.outputType}`
});
});
});

View file

@ -7,10 +7,10 @@ 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 data = gm(image.data).out("-radial-blur", 10);
const data = gm(image.path).coalesce().out("-radial-blur", 10);
return message.channel.createMessage("", {
file: await gmToBuffer(data),
name: `circle.${image.type}`
file: await gmToBuffer(data, image.outputType),
name: `circle.${image.outputType}`
});
};

View file

@ -8,12 +8,12 @@ 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";
gm(image.data).size(async (error, size) => {
gm(image.path).size(async (error, size) => {
if (error) throw error;
const data = gm(image.data).coalesce().out("null:").out(watermark).gravity("Center").resize(null, size.height).out("-layers", "composite").out("-layers", "optimize");
const data = gm(image.path).coalesce().out("null:").out(watermark).gravity("Center").resize(null, size.height).out("-layers", "composite").out("-layers", "optimize");
return message.channel.createMessage("", {
file: await gmToBuffer(data),
name: `deviantart.${image.type}`
file: await gmToBuffer(data, image.outputType),
name: `deviantart.${image.outputType}`
});
});
};

View file

@ -7,10 +7,10 @@ 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 data = gm(image.data).implode([-2]);
const data = gm(image.path).coalesce().implode([-2]);
return message.channel.createMessage("", {
file: await gmToBuffer(data),
name: `explode.${image.type}`
file: await gmToBuffer(data, image.outputType),
name: `explode.${image.outputType}`
});
};

View file

@ -7,10 +7,10 @@ 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 command = gm(image.data).flip();
const command = gm(image.path).flip();
return message.channel.createMessage("", {
file: await gmToBuffer(command),
name: `flip.${image.type}`
file: await gmToBuffer(command, image.outputType),
name: `flip.${image.outputType}`
});
};

View file

@ -7,10 +7,10 @@ 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 command = gm(image.data).flop();
const command = gm(image.path).flop();
return message.channel.createMessage("", {
file: await gmToBuffer(command),
name: `flop.${image.type}`
file: await gmToBuffer(command, image.outputType),
name: `flop.${image.outputType}`
});
};

View file

@ -8,12 +8,12 @@ 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";
gm(image.data).size(async (error, size) => {
gm(image.path).size(async (error, size) => {
if (error) throw error;
const data = gm(image.data).coalesce().out("null:").out(watermark).gravity("NorthEast").resize(null, size.height).out("-layers", "composite").out("-layers", "optimize");
const data = gm(image.path).coalesce().out("null:").out(watermark).gravity("NorthEast").resize(null, size.height).out("-layers", "composite").out("-layers", "optimize");
return message.channel.createMessage("", {
file: await gmToBuffer(data),
name: `funky.${image.type}`
file: await gmToBuffer(data, image.outputType),
name: `funky.${image.outputType}`
});
});
};

View file

@ -2,19 +2,16 @@ const gm = require("gm").subClass({
imageMagick: true
});
const gmToBuffer = require("../utils/gmbuffer.js");
const fs = require("fs");
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 a GameXplain thumbnail meme!`;
const template = "./assets/images/gamexplain.png";
const path = `/tmp/${Math.random().toString(36).substring(2, 15)}.${image.type}`;
require("util").promisify(fs.writeFile)(path, image.data);
const command = gm(template).background("white").out("null:").out("(").out(path).coalesce().out("-virtual-pixel", "transparent").resize("1181x571!").out(")").compose("over").gravity("Center").out("-geometry", "+0+40").out("-layers", "composite").out("-layers", "optimize");
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");
return message.channel.createMessage("", {
file: await gmToBuffer(command, image.type),
name: `gamexplain.${image.type}`
file: await gmToBuffer(command, image.outputType),
name: `gamexplain.${image.outputType}`
});
};

View file

@ -11,16 +11,16 @@ 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`;
const data2 = `/tmp/${Math.random().toString(36).substring(2, 15)}.miff`;
gm(image.data).size((error, size) => {
gm(image.path).size((error, size) => {
if (error) throw error;
gm(image.data).coalesce().gravity("West").crop("50%", 0).out("+repage").write(data2, (error) => {
gm(image.path).coalesce().gravity("West").crop("50%", 0).out("+repage").write(data2, (error) => {
if (error) throw error;
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");
return message.channel.createMessage("", {
file: await gmToBuffer(command, image.type),
name: `haah.${image.type}`
file: await gmToBuffer(command, image.outputType),
name: `haah.${image.outputType}`
});
});
});

View file

@ -11,16 +11,16 @@ 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`;
const data2 = `/tmp/${Math.random().toString(36).substring(2, 15)}.miff`;
gm(image.data).size((error, size) => {
gm(image.path).size((error, size) => {
if (error) throw error;
gm(image.data).coalesce().gravity("South").crop(0, "50%").out("+repage").write(data2, (error) => {
gm(image.path).coalesce().gravity("South").crop(0, "50%").out("+repage").write(data2, (error) => {
if (error) throw error;
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");
return message.channel.createMessage("", {
file: await gmToBuffer(command, image.type),
name: `hooh.${image.type}`
file: await gmToBuffer(command, image.outputType),
name: `hooh.${image.outputType}`
});
});
});

View file

@ -8,12 +8,12 @@ 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";
gm(image.data).size(async (error, size) => {
gm(image.path).size(async (error, size) => {
if (error) throw error;
const data = gm(image.data).coalesce().out("null:").out(watermark).gravity("NorthWest").resize(null, size.height).out("-layers", "composite").out("-layers", "optimize");
const data = gm(image.path).coalesce().out("null:").out(watermark).gravity("NorthWest").resize(null, size.height).out("-layers", "composite").out("-layers", "optimize");
return message.channel.createMessage("", {
file: await gmToBuffer(data),
name: `hypercam.${image.type}`
file: await gmToBuffer(data, image.outputType),
name: `hypercam.${image.outputType}`
});
});
};

View file

@ -8,12 +8,12 @@ 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";
gm(image.data).size(async (error, size) => {
gm(image.path).size(async (error, size) => {
if (error) throw error;
const data = gm(image.data).coalesce().out("null:").out(watermark).gravity("South").resize(size.width, null).out("-layers", "composite").out("-layers", "optimize");
const data = gm(image.path).coalesce().out("null:").out(watermark).gravity("South").resize(size.width, null).out("-layers", "composite").out("-layers", "optimize");
return message.channel.createMessage("", {
file: await gmToBuffer(data),
name: `ifunny.${image.type}`
file: await gmToBuffer(data, image.outputType),
name: `ifunny.${image.outputType}`
});
});
};

View file

@ -17,7 +17,7 @@ exports.run = async (message, args) => {
"title": "Search Results",
"color": 16711680,
"footer": {
"text": `Page ${i + 1} of ${images.length}`
"text": `Page ${i + 1} of ${images.items.length}`
},
"image": {
"url": value.link

View file

@ -7,10 +7,10 @@ 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 data = gm(image.data).implode([1]);
const data = gm(image.path).implode([1]);
return message.channel.createMessage("", {
file: await gmToBuffer(data),
name: `implode.${image.type}`
file: await gmToBuffer(data, image.outputType),
name: `implode.${image.outputType}`
});
};

View file

@ -7,10 +7,10 @@ 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 data = gm(image.data).negative();
const data = gm(image.path).negative();
return message.channel.createMessage("", {
file: await gmToBuffer(data),
name: `invert.${image.type}`
file: await gmToBuffer(data, image.outputType),
name: `invert.${image.outputType}`
});
};

View file

@ -7,7 +7,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 more JPEG!`;
const data = gm(image.data).setFormat("jpg").quality(1);
const data = gm(image.path).setFormat("jpg").quality(1);
return message.channel.createMessage("", {
file: await gmToBuffer(data),
name: "jpeg.jpg"

View file

@ -2,21 +2,18 @@ const gm = require("gm").subClass({
imageMagick: true
});
const gmToBuffer = require("../utils/gmbuffer.js");
const fs = require("fs");
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 a Super Smash Bros. leak meme!`;
if (image.type === "gif") return `${message.author.mention}, this command doesn't work with GIFs!`;
if (image.type === "gif" || image.type === "mp4") return `${message.author.mention}, this command doesn't work with GIFs!`;
const template = "./assets/images/leak.png";
const path = `/tmp/${Math.random().toString(36).substring(2, 15)}.${image.type}`;
require("util").promisify(fs.writeFile)(path, image.data);
const command = gm(template).out("-background").out("white").out("-gravity").out("Center").out("(").out("-clone").out("0").out("(").out(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").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");
return message.channel.createMessage("", {
file: await gmToBuffer(command),
name: `leak.${image.type}`
name: `leak.${image.outputType}`
});
};

View file

@ -6,7 +6,7 @@ const gmToBuffer = require("../utils/gmbuffer.js");
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 some magik!`;
if (image.type === "gif") return `${message.author.mention}, this command doesn't work with GIFs!`;
if (image.type === "gif" || image.type === "mp4") return `${message.author.mention}, this command doesn't work with GIFs!`;
const processMessage = await message.channel.createMessage("<a:processing:479351417102925854> Processing... This might take a while");
gm(image.data).resize(800, 800).stream("miff", (error, stream) => {
if (error) throw error;
@ -17,7 +17,7 @@ exports.run = async (message) => {
await processMessage.delete();
return message.channel.createMessage("", {
file: resultBuffer,
name: `magik.${image.type}`
name: `magik.${image.outputType}`
});
});
});

View file

@ -12,7 +12,7 @@ exports.run = async (message, args) => {
const file = `/tmp/${Math.random().toString(36).substring(2, 15)}.miff`;
const file2 = `/tmp/${Math.random().toString(36).substring(2, 15)}.png`;
const file3 = `/tmp/${Math.random().toString(36).substring(2, 15)}.png`;
gm(image.data).out("-coalesce").resize(600, 600).noProfile().write(file, (error) => {
gm(image.path).coalesce().resize(600, 600).noProfile().write(file, (error) => {
if (error) throw error;
gm(file).size((error, size) => {
if (error) throw error;
@ -22,8 +22,8 @@ exports.run = async (message, args) => {
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");
return message.channel.createMessage("", {
file: await gmToBuffer(data, image.type),
name: `meme.${image.type}`
file: await gmToBuffer(data, image.outputType),
name: `meme.${image.outputType}`
});
});
});

View file

@ -9,10 +9,10 @@ exports.run = async (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";
let resultBuffer;
gm(image.data).size(async (error, size) => {
gm(image.path).size(async (error, size) => {
if (error) throw error;
const command = gm(image.data).coalesce().background("white").extent(size.width, size.height + 15).out("null:").out(watermark).gravity("SouthEast").compose("over").out("-layers", "composite").out("-layers", "optimize");
const output = await gmToBuffer(command, image.type);
const command = gm(image.path).coalesce().background("white").extent(size.width, size.height + 15).out("null:").out(watermark).gravity("SouthEast").compose("over").out("-layers", "composite").out("-layers", "optimize");
const output = await gmToBuffer(command, image.outputType);
gm(output).size(async (error, size2) => {
if (error) throw error;
resultBuffer = output;
@ -22,7 +22,7 @@ exports.run = async (message) => {
}
return message.channel.createMessage("", {
file: resultBuffer,
name: `memecenter.${image.type}`
name: `memecenter.${image.outputType}`
});
});
});

View file

@ -1,4 +1,3 @@
const fs = require("fs");
const gm = require("gm").subClass({
imageMagick: true
});
@ -10,13 +9,11 @@ exports.run = async (message, args) => {
if (args.length === 0) return `${message.author.mention}, you need to provide some text to make a motivational poster!`;
const processMessage = await message.channel.createMessage("<a:processing:479351417102925854> Processing... This might take a while");
const [topText, bottomText] = args.join(" ").split(",").map(elem => elem.trim());
const path = `/tmp/${Math.random().toString(36).substring(2, 15)}.${image.type}`;
const file = `/tmp/${Math.random().toString(36).substring(2, 15)}.miff`;
const file2 = `/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`;
require("util").promisify(fs.writeFile)(path, image.data);
gm().in("(").in(path).coalesce().resize(500, 500).borderColor("black").border(5, 5).out(")").borderColor("white").border(3, 3).out("-layers", "optimize").write(file, (error) => {
gm().in("(").in(image.path).coalesce().resize(500, 500).borderColor("black").border(5, 5).out(")").borderColor("white").border(3, 3).out("-layers", "optimize").write(file, (error) => {
if (error) throw error;
gm(file).size((error, size) => {
if (error) throw error;
@ -35,21 +32,21 @@ exports.run = async (message, args) => {
if (error) throw error;
gm(text2).size(async (error, size4) => {
if (error) throw error;
const command2 = gm(await gmToBuffer(command, image.type)).gravity("North").coalesce().background("black").extent(600, size2.height + size3.height + size4.height).out("null:", "(", text2, "-set", "page", `+0+${size2.height + size3.height}`, ")", "-layers", "composite", "-layers", "optimize");
const resultBuffer = await gmToBuffer(command2, image.type);
const command2 = gm(await gmToBuffer(command, image.outputType)).gravity("North").coalesce().background("black").extent(600, size2.height + size3.height + size4.height).out("null:", "(", text2, "-set", "page", `+0+${size2.height + size3.height}`, ")", "-layers", "composite", "-layers", "optimize");
const resultBuffer = await gmToBuffer(command2, image.outputType);
processMessage.delete();
return message.channel.createMessage("", {
file: resultBuffer,
name: `motivate.${image.type}`
name: `motivate.${image.outputType}`
});
});
});
} else {
const resultBuffer = await gmToBuffer(command, image.type);
const resultBuffer = await gmToBuffer(command, image.outputType);
processMessage.delete();
return message.channel.createMessage("", {
file: resultBuffer,
name: `motivate.${image.type}`
name: `motivate.${image.outputType}`
});
}
});

View file

@ -2,19 +2,16 @@ const gm = require("gm").subClass({
imageMagick: true
});
const gmToBuffer = require("../utils/gmbuffer.js");
const fs = require("fs");
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 a Scott the Woz TV meme!`;
const template = "./assets/images/scott.png";
const path = `/tmp/${Math.random().toString(36).substring(2, 15)}.${image.type}`;
require("util").promisify(fs.writeFile)(path, image.data);
const command = gm(template).out("null:").out("(").out(path).out("-virtual-pixel", "transparent").resize("415x234!").coalesce().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 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");
return message.channel.createMessage("", {
file: await gmToBuffer(command, image.type),
name: `scott.${image.type}`
file: await gmToBuffer(command, image.outputType),
name: `scott.${image.outputType}`
});
};

View file

@ -7,10 +7,10 @@ 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 command = gm(image.data).sharpen(10);
const command = gm(image.path).coalesce().sharpen(10);
return message.channel.createMessage("", {
file: await gmToBuffer(command),
name: `sharpen.${image.type}`
file: await gmToBuffer(command, image.outputType),
name: `sharpen.${image.outputType}`
});
};

View file

@ -8,12 +8,12 @@ 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";
gm(image.data).size(async (error, size) => {
gm(image.path).size(async (error, size) => {
if (error) throw error;
const command = gm(image.data).coalesce().out("null:").out(watermark).gravity("Center").resize(null, size.height).out("-layers", "composite").out("-layers", "optimize");
const command = gm(image.path).coalesce().out("null:").out(watermark).gravity("Center").resize(null, size.height).out("-layers", "composite").out("-layers", "optimize");
return message.channel.createMessage("", {
file: await gmToBuffer(command),
name: `shutterstock.${image.type}`
file: await gmToBuffer(command, image.outputType),
name: `shutterstock.${image.outputType}`
});
});
};

View file

@ -1,4 +1,3 @@
const fs = require("fs");
const { exec } = require("child_process");
const util = require("util");
const gm = require("gm").subClass({
@ -10,23 +9,21 @@ 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 a GIF to speed up!`;
if (image.type !== "gif") return `${message.author.mention}, that isn't a GIF!`;
const path = `/tmp/${Math.random().toString(36).substring(2, 15)}.gif`;
util.promisify(fs.writeFile)(path, image.data);
gm(image.data).identify(async (error, value) => {
if (image.type !== "gif" && image.type !== "mp4") return `${message.author.mention}, that isn't a GIF!`;
gm(image.path).identify(async (error, value) => {
if (error) throw error;
const delay = value.Delay[0].split("x");
const delay = value.Delay ? value.Delay[0].split("x") : [0, 100];
if (Math.round(parseInt(delay[0]) / 2) >= 2) {
const data = gm().delay(`${parseInt(delay[0]) / 2}x${delay[1]}`).out(path);
const data = gm().delay(`${parseInt(delay[0]) / 2}x${delay[1]}`).out(image.path);
return message.channel.createMessage("", {
file: await gmToBuffer(data),
file: await gmToBuffer(data, image.outputType),
name: "speed.gif"
});
} else {
const numbers = (await util.promisify(exec)(`seq 0 2 ${value.Delay.length}`)).stdout.split("\n").join(",");
const data = gm().out("(").out(path).coalesce().out(")").out("-delete", numbers).out("-layers", "optimize");
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");
return message.channel.createMessage("", {
file: await gmToBuffer(data),
file: await gmToBuffer(data, image.outputType),
name: "speed.gif"
});
}

View file

@ -7,8 +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 spin!`;
const processMessage = await message.channel.createMessage("<a:processing:479351417102925854> Processing... This might take a while");
const command = gm(image.data).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");
const resultBuffer = await gmToBuffer(command, "gif");
const command = 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");
const resultBuffer = await gmToBuffer(command, image.outputType);
await processMessage.delete();
return message.channel.createMessage("", {
file: resultBuffer,

View file

@ -7,10 +7,10 @@ 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 data = gm(image.data).resize("512x512!");
const data = gm(image.path).coalesce().resize("512x512!");
return message.channel.createMessage("", {
file: await gmToBuffer(data),
name: `stretch.${image.type}`
file: await gmToBuffer(data, image.outputType),
name: `stretch.${image.outputType}`
});
};

View file

@ -7,10 +7,10 @@ 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 data = gm(image.data).swirl(180);
const data = gm(image.path).coalesce().swirl(180);
return message.channel.createMessage("", {
file: await gmToBuffer(data),
name: `swirl.${image.type}`
file: await gmToBuffer(data, image.outputType),
name: `swirl.${image.outputType}`
});
};

View file

@ -7,12 +7,12 @@ 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 tile!`;
gm(image.data).command("montage").out("-duplicate").out(24).tile("5x5").geometry("+0+0").stream(async (error, output) => {
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).resize("800x800>");
const data = gm(output).coalesce().resize("800x800>");
return message.channel.createMessage("", {
file: await gmToBuffer(data),
name: `tile.${image.type}`
file: await gmToBuffer(data, image.outputType),
name: `tile.${image.outputType}`
});
});
};

View file

@ -2,19 +2,16 @@ const gm = require("gm").subClass({
imageMagick: true
});
const gmToBuffer = require("../utils/gmbuffer.js");
const fs = require("fs");
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 a Trump meme!`;
const template = "./assets/images/trump.png";
const path = `/tmp/${Math.random().toString(36).substring(2, 15)}.${image.type}`;
require("util").promisify(fs.writeFile)(path, image.data);
const command = gm(template).background("white").out("null:").out("(").out(path).out("-virtual-pixel", "transparent").resize("365x179!").coalesce().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 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");
return message.channel.createMessage("", {
file: await gmToBuffer(command, image.type),
name: `trump.${image.type}`
file: await gmToBuffer(command, image.outputType),
name: `trump.${image.outputType}`
});
};

View file

@ -11,16 +11,16 @@ 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`;
const data2 = `/tmp/${Math.random().toString(36).substring(2, 15)}.miff`;
gm(image.data).size((error, size) => {
gm(image.path).size((error, size) => {
if (error) throw error;
gm(image.data).coalesce().gravity("East").crop("50%", 0).out("+repage").write(data2, (error) => {
gm(image.path).coalesce().gravity("East").crop("50%", 0).out("+repage").write(data2, (error) => {
if (error) throw error;
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");
return message.channel.createMessage("", {
file: await gmToBuffer(command, image.type),
name: `waaw.${image.type}`
file: await gmToBuffer(command, image.outputType),
name: `waaw.${image.outputType}`
});
});
});

View file

@ -7,12 +7,12 @@ 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 a wall from!`;
gm(image.data).resize(128).stream(async (error, output) => {
gm(image.path).coalesce().resize(128).stream("miff", async (error, output) => {
if (error) throw error;
const data = gm(output).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 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");
return message.channel.createMessage("", {
file: await gmToBuffer(data),
name: `wall.${image.type}`
file: await gmToBuffer(data, image.outputType),
name: `wall.${image.outputType}`
});
});
};

View file

@ -2,19 +2,16 @@ const gm = require("gm").subClass({
imageMagick: true
});
const gmToBuffer = require("../utils/gmbuffer.js");
const fs = require("fs");
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 a "who did this" meme!`;
const template = "./assets/images/whodidthis.png";
const path = `/tmp/${Math.random().toString(36).substring(2, 15)}.${image.type}`;
require("util").promisify(fs.writeFile)(path, image.data);
const command = gm(template).coalesce().out("null:").out(path).gravity("Center").resize("374x374>").out("-layers", "composite").out("-layers", "optimize");
const command = gm(template).coalesce().out("null:").out(image.path).gravity("Center").resize("374x374>").out("-layers", "composite").out("-layers", "optimize");
return message.channel.createMessage("", {
file: await gmToBuffer(command, image.type),
name: `wdt.${image.type}`
file: await gmToBuffer(command, image.outputType),
name: `wdt.${image.outputType}`
});
};

View file

@ -7,13 +7,13 @@ 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!`;
gm(image.data).size(async (error, size) => {
gm(image.path).size(async (error, size) => {
if (error) throw error;
if (size.width > 10000) return `${message.author.mention}, this image is too wide!`;
const data = gm(image.data).resize(`${(size.width * 19) / 2}x${size.height / 2}!`);
const data = gm(image.path).coalesce().resize(`${(size.width * 19) / 2}x${size.height / 2}!`);
return message.channel.createMessage("", {
file: await gmToBuffer(data),
name: `wide.${image.type}`
file: await gmToBuffer(data, image.outputType),
name: `wide.${image.outputType}`
});
});
};

View file

@ -11,16 +11,16 @@ 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`;
const data2 = `/tmp/${Math.random().toString(36).substring(2, 15)}.miff`;
gm(image.data).size((error, size) => {
gm(image.path).size((error, size) => {
if (error) throw error;
gm(image.data).coalesce().gravity("North").crop(0, "50%").out("+repage").write(data2, (error) => {
gm(image.path).coalesce().gravity("North").crop(0, "50%").out("+repage").write(data2, (error) => {
if (error) throw error;
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");
return message.channel.createMessage("", {
file: await gmToBuffer(command, image.type),
name: `woow.${image.type}`
file: await gmToBuffer(command, image.outputType),
name: `woow.${image.outputType}`
});
});
});

View file

@ -87,5 +87,6 @@
"foobar2000",
"XMPlay",
"OpenMPT",
"follow @esmBot_ on Twitter"
"follow @esmBot_ on Twitter",
"with GIFs"
]

View file

@ -1,9 +1,10 @@
const fetch = require("node-fetch");
const fileType = require("file-type");
const writeFile = require("util").promisify(require("fs").writeFile);
const urlRegex = /(?:\w+:)?\/\/(\S+)/;
// this checks if the file is, in fact, an image
const typeCheck = async (image) => {
const typeCheck = async (image, gifv = false) => {
// download the file to a buffer
const imageRequest = await fetch(image);
const imageBuffer = await imageRequest.buffer();
@ -11,11 +12,18 @@ const typeCheck = async (image) => {
// get the file type
const imageType = await fileType.fromBuffer(imageBuffer);
// check if the file is a jpeg, png, or webp
if (imageType && ["image/jpeg", "image/png", "image/webp", "image/gif"].includes(imageType.mime)) {
const formats = ["image/jpeg", "image/png", "image/webp", "image/gif"];
if (gifv) formats.push("video/mp4");
if (imageType && formats.includes(imageType.mime)) {
// 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 {
type: imageType.ext,
data: imageBuffer
data: imageBuffer,
url: image,
outputType: imageType.ext === "mp4" ? "gif" : imageType.ext,
path: path
};
} else {
// if not, then return false
@ -33,7 +41,23 @@ module.exports = async (cmdMessage) => {
// iterate over each message
for (const message of messages) {
// check the attachments first
if (message.attachments.length !== 0) {
if (message.embeds.length !== 0) {
// embeds can have 2 possible entries with images, we check the thumbnail first
if (message.embeds[0].type === "gifv") {
const type = await typeCheck(message.embeds[0].video.url, true);
if (type === false) continue;
return type;
} else if (message.embeds[0].thumbnail) {
const type = await typeCheck(message.embeds[0].thumbnail.url);
if (type === false) continue;
return type;
// if there isn't a thumbnail check the image area
} else if (message.embeds[0].image) {
const type = await typeCheck(message.embeds[0].image.url);
if (type === false) continue;
return type;
}
} else if (message.attachments.length !== 0) {
// get type of file
const type = await typeCheck(message.attachments[0].url);
// move to the next message if the file isn't an image
@ -51,18 +75,6 @@ module.exports = async (cmdMessage) => {
// if the file is an image then return it
return type;
// if there's no urls then check the embeds
} else if (message.embeds.length !== 0) {
// embeds can have 2 possible entries with images, we check the thumbnail first
if (message.embeds[0].thumbnail) {
const type = await typeCheck(message.embeds[0].thumbnail.url);
if (type === false) continue;
return type;
// if there isn't a thumbnail check the image area
} else if (message.embeds[0].image) {
const type = await typeCheck(message.embeds[0].image.url);
if (type === false) continue;
return type;
}
}
}
};