Modified image commands to work completely with animated GIF files, fixed oversight with caption and help

This commit is contained in:
TheEssem 2020-01-08 19:10:26 -06:00
parent 689ca12522
commit c70f7dee5e
22 changed files with 62 additions and 38 deletions

View File

@ -8,7 +8,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 data = gm(image.data).composite(watermark).gravity("East");
const data = gm(image.data).coalesce().out("null:").out(watermark).gravity("East").out("-layers", "composite");
const resultBuffer = await gmToBuffer(data);
return message.channel.createMessage("", {
file: resultBuffer,

View File

@ -10,7 +10,7 @@ exports.run = async (message) => {
const watermark = "./assets/images/bandicam.png";
gm(image.data).size(async (error, size) => {
if (error) throw error;
const data = gm(image.data).composite(watermark).gravity("North").resize(null, size.height);
const data = gm(image.data).coalesce().out("null:").out(watermark).gravity("North").resize(null, size.height).out("-layers", "composite");
const resultBuffer = await gmToBuffer(data);
return message.channel.createMessage("", {
file: resultBuffer,

View File

@ -7,6 +7,7 @@ const gmToBuffer = require("../utils/gmbuffer.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);

View File

@ -10,7 +10,7 @@ exports.run = async (message) => {
const watermark = "./assets/images/deviantart.png";
gm(image.data).size(async (error, size) => {
if (error) throw error;
const data = gm(image.data).composite(watermark).gravity("Center").resize(null, size.height);
const data = gm(image.data).coalesce().out("null:").out(watermark).gravity("Center").resize(null, size.height).out("-layers", "composite");
const resultBuffer = await gmToBuffer(data);
return message.channel.createMessage("", {
file: resultBuffer,

View File

@ -1,10 +1,14 @@
const sharp = require("sharp");
const gm = require("gm").subClass({
imageMagick: true
});
const gmToBuffer = require("../utils/gmbuffer.js");
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 resultBuffer = await sharp(image.data).flip().toBuffer();
const command = gm(image.data).flip();
const resultBuffer = await gmToBuffer(command);
return message.channel.createMessage("", {
file: resultBuffer,
name: `flip.${image.type}`

View File

@ -1,10 +1,14 @@
const sharp = require("sharp");
const gm = require("gm").subClass({
imageMagick: true
});
const gmToBuffer = require("../utils/gmbuffer.js");
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 resultBuffer = await sharp(image.data).flop().toBuffer();
const command = gm(image.data).flop();
const resultBuffer = await gmToBuffer(command);
return message.channel.createMessage("", {
file: resultBuffer,
name: `flop.${image.type}`

View File

@ -10,7 +10,7 @@ exports.run = async (message) => {
const watermark = "./assets/images/funky.png";
gm(image.data).size(async (error, size) => {
if (error) throw error;
const data = gm(image.data).composite(watermark).gravity("NorthEast").resize(null, size.height);
const data = gm(image.data).coalesce().out("null:").out(watermark).gravity("NorthEast").resize(null, size.height).out("-layers", "composite");
const resultBuffer = await gmToBuffer(data);
return message.channel.createMessage("", {
file: resultBuffer,

View File

@ -11,11 +11,11 @@ exports.run = async (message) => {
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).out("-background").out("white").out("-gravity").out("Center").out("(").out("-clone").out("0").out("(").out(path).out("-virtual-pixel").out("transparent").out("-resize").out("1181x571!").out(")").out("-geometry").out("+0+40").out("-composite").out(")").out("+swap").out("-composite");
const resultBuffer = await gmToBuffer(command);
const command = gm(template).background("white").out("null:").out("(").out(path).out("-virtual-pixel", "transparent").resize("1181x571!").coalesce().out(")").compose("over").gravity("Center").out("-geometry", "+0+40").out("-layers", "composite");
const resultBuffer = await gmToBuffer(command, image.type);
return message.channel.createMessage("", {
file: resultBuffer,
name: "gamexplain.png"
name: `gamexplain.${image.type}`
});
};

View File

@ -3,6 +3,7 @@
const gm = require("gm").subClass({
imageMagick: true
});
const gmToBuffer = require("../utils/gmbuffer.js");
exports.run = async (message) => {
message.channel.sendTyping();
@ -10,12 +11,14 @@ 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)}.${image.type}`;
const data2 = `/tmp/${Math.random().toString(36).substring(2, 15)}.${image.type}`;
gm(image.data).gravity("West").crop("50%", 0).strip().write(data2, (error) => {
gm(image.data).size((error, size) => {
if (error) throw error;
gm(data2).flop().strip().write(data, async (error) => {
gm(image.data).gravity("West").crop("50%", 0).out("+repage").write(data2, (error) => {
if (error) throw error;
gm(data2).append(data, true).toBuffer(image.type, (error, resultBuffer) => {
gm(data2).flop().write(data, async (error) => {
if (error) throw error;
const command = gm(data2).out("-repage", `${size.width}x${size.height}`).coalesce().out("null:").out("(").out(data).coalesce().out(")").geometry(`+${size.width / 2}+0`).out("-layers", "Composite");
const resultBuffer = await gmToBuffer(command);
return message.channel.createMessage("", {
file: resultBuffer,
name: `haah.${image.type}`

View File

@ -36,7 +36,7 @@ exports.run = async (message, args) => {
moderation: [],
tags: ["**Every command in this category is a subcommand of the tag command.**\n"],
fun: [],
images: ["**These commands support the PNG, JPEG, and WEBP formats.**\n"],
images: ["**These commands support the PNG, JPEG, WEBP, and GIF formats. (GIF support is experimental)**\n"],
soundboard: [],
admin: ["**These commands are only available to the bot owner.**\n"]
};

View File

@ -3,6 +3,7 @@
const gm = require("gm").subClass({
imageMagick: true
});
const gmToBuffer = require("../utils/gmbuffer.js");
exports.run = async (message) => {
message.channel.sendTyping();
@ -10,12 +11,14 @@ 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)}.${image.type}`;
const data2 = `/tmp/${Math.random().toString(36).substring(2, 15)}.${image.type}`;
gm(image.data).gravity("South").crop(0, "50%").strip().write(data2, (error) => {
gm(image.data).size((error, size) => {
if (error) throw error;
gm(data2).flip().strip().write(data, async (error) => {
gm(image.data).gravity("South").crop(0, "50%").out("+repage").write(data2, (error) => {
if (error) throw error;
gm(data).append(data2).toBuffer(image.type, (error, resultBuffer) => {
gm(data2).flip().write(data, async (error) => {
if (error) throw error;
const command = gm(data).out("-repage", `${size.width}x${size.height}`).coalesce().out("null:").out("(").out(data2).coalesce().out(")").geometry(`+0+${size.height / 2}`).out("-layers", "Composite");
const resultBuffer = await gmToBuffer(command);
return message.channel.createMessage("", {
file: resultBuffer,
name: `hooh.${image.type}`

View File

@ -10,7 +10,7 @@ exports.run = async (message) => {
const watermark = "./assets/images/hypercam.png";
gm(image.data).size(async (error, size) => {
if (error) throw error;
const data = gm(image.data).composite(watermark).gravity("NorthWest").resize(null, size.height);
const data = gm(image.data).coalesce().out("null:").out(watermark).gravity("NorthWest").resize(null, size.height).out("-layers", "composite");
const resultBuffer = await gmToBuffer(data);
return message.channel.createMessage("", {
file: resultBuffer,

View File

@ -10,7 +10,7 @@ exports.run = async (message) => {
const watermark = "./assets/images/ifunny.png";
gm(image.data).size(async (error, size) => {
if (error) throw error;
const data = gm(image.data).append(watermark).gravity("South").resize(size.width, null);
const data = gm(image.data).coalesce().out("null:").out(watermark).gravity("South").resize(size.width, null).out("-layers", "composite");
const resultBuffer = await gmToBuffer(data);
return message.channel.createMessage("", {
file: resultBuffer,

View File

@ -8,10 +8,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 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 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", "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 resultBuffer = await gmToBuffer(command, "png");
return message.channel.createMessage("", {
file: resultBuffer,

View File

@ -6,6 +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!`;
const processMessage = await message.channel.createMessage("<a:processing:479351417102925854> Processing... This might take a while");
gm(image.data).resize(800, 800).stream((error, stream) => {
if (error) throw error;

View File

@ -11,8 +11,8 @@ exports.run = async (message) => {
let resultBuffer;
gm(image.data).size(async (error, size) => {
if (error) throw error;
const command = gm(image.data).out(watermark).background("#FFFFFF").gravity("East").out("-smush").out("-9");
const output = await gmToBuffer(command, "png");
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");
const output = await gmToBuffer(command, image.type);
gm(output).size(async (error, size2) => {
if (error) throw error;
resultBuffer = output;

View File

@ -11,11 +11,11 @@ exports.run = async (message) => {
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("-gravity").out("Center").out("(").out(path).out("-virtual-pixel").out("transparent").out("-resize").out("415x234!").out("+distort").out("Perspective").out("0,0 129,187 415,0 517,182 415,234 517,465 0,234 132,418").out("-geometry").out("-110+83").out(")").out("-composite");
const resultBuffer = await gmToBuffer(command, "png");
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");
const resultBuffer = await gmToBuffer(command, image.type);
return message.channel.createMessage("", {
file: resultBuffer,
name: "scott.png"
name: `scott.${image.type}`
});
};

View File

@ -10,7 +10,7 @@ exports.run = async (message) => {
const watermark = "./assets/images/shutterstock.png";
gm(image.data).size(async (error, size) => {
if (error) throw error;
const command = gm(image.data).composite(watermark).gravity("Center").resize(null, size.height);
const command = gm(image.data).coalesce().out("null:").out(watermark).gravity("Center").resize(null, size.height).out("-layers", "composite");
const output = await gmToBuffer(command);
return message.channel.createMessage("", {
file: output,

View File

@ -11,11 +11,11 @@ exports.run = async (message) => {
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).out("-background").out("none").out("-gravity").out("South").out("(").out("-clone").out("0").out("(").out(path).out("-virtual-pixel").out("transparent").out("-resize").out("365x179!").out("+distort").out("Perspective").out("0,0 207,268 365,0 548,271 365,179 558,450 0,179 193,450").out(")").out("-geometry").out("-25-1").out("-composite").out(")").out("+swap").out("-composite");
const resultBuffer = await gmToBuffer(command, "png");
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");
const resultBuffer = await gmToBuffer(command, image.type);
return message.channel.createMessage("", {
file: resultBuffer,
name: "trump.png"
name: `trump.${image.type}`
});
};

View File

@ -3,6 +3,7 @@
const gm = require("gm").subClass({
imageMagick: true
});
const gmToBuffer = require("../utils/gmbuffer.js");
exports.run = async (message) => {
message.channel.sendTyping();
@ -10,12 +11,14 @@ 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)}.${image.type}`;
const data2 = `/tmp/${Math.random().toString(36).substring(2, 15)}.${image.type}`;
gm(image.data).gravity("East").crop("50%", 0).strip().write(data2, (error) => {
gm(image.data).size((error, size) => {
if (error) throw error;
gm(data2).flop().strip().write(data, async (error) => {
gm(image.data).gravity("East").crop("50%", 0).out("+repage").write(data2, (error) => {
if (error) throw error;
gm(data).append(data2, true).toBuffer(image.type, (error, resultBuffer) => {
gm(data2).flop().write(data, async (error) => {
if (error) throw error;
const command = gm(data).out("-repage", `${size.width}x${size.height}`).coalesce().out("null:").out("(").out(data2).coalesce().out(")").geometry(`+${size.width / 2}+0`).out("-layers", "Composite");
const resultBuffer = await gmToBuffer(command);
return message.channel.createMessage("", {
file: resultBuffer,
name: `waaw.${image.type}`

View File

@ -11,11 +11,11 @@ exports.run = async (message) => {
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).composite(path).gravity("Center").geometry("374x374+0+0");
const resultBuffer = await gmToBuffer(command, "png");
const command = gm(template).coalesce().out("null:").out(path).gravity("Center").resize("374x374>").out("-layers", "composite");
const resultBuffer = await gmToBuffer(command, image.type);
return message.channel.createMessage("", {
file: resultBuffer,
name: "wdt.png"
name: `wdt.${image.type}`
});
};

View File

@ -3,6 +3,7 @@
const gm = require("gm").subClass({
imageMagick: true
});
const gmToBuffer = require("../utils/gmbuffer.js");
exports.run = async (message) => {
message.channel.sendTyping();
@ -10,12 +11,14 @@ 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)}.${image.type}`;
const data2 = `/tmp/${Math.random().toString(36).substring(2, 15)}.${image.type}`;
gm(image.data).gravity("North").crop(0, "50%").strip().write(data2, (error) => {
gm(image.data).size((error, size) => {
if (error) throw error;
gm(data2).flip().strip().write(data, async (error) => {
gm(image.data).gravity("North").crop(0, "50%").out("+repage").write(data2, (error) => {
if (error) throw error;
gm(data2).append(data).toBuffer(image.type, (error, resultBuffer) => {
gm(data2).flip().write(data, async (error) => {
if (error) throw error;
const command = gm(data2).out("-repage", `${size.width}x${size.height}`).coalesce().out("null:").out("(").out(data).coalesce().out(")").geometry(`+0+${size.height / 2}`).out("-layers", "Composite");
const resultBuffer = await gmToBuffer(command);
return message.channel.createMessage("", {
file: resultBuffer,
name: `woow.${image.type}`