Removed duplicate type parameter, made image commands use a promisified version of the default toBuffer method

This commit is contained in:
TheEssem 2020-02-25 14:45:47 -06:00
parent 3513245fda
commit 5455b2682c
44 changed files with 104 additions and 174 deletions

View File

@ -1,18 +1,16 @@
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 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");
const buffer = await gmToBuffer(data, image.outputType);
const buffer = await gm(image.path).coalesce().out("null:").out(watermark).gravity("East").out("-layers", "composite").bufferPromise(image.type);
return message.channel.createMessage("", {
file: buffer,
name: `9gag.${image.outputType}`
name: `9gag.${image.type}`
});
};

View File

@ -1,7 +1,6 @@
const gm = require("gm").subClass({
imageMagick: true
});
const gmToBuffer = require("../utils/gmbuffer.js");
exports.run = async (message) => {
message.channel.sendTyping();
@ -9,11 +8,10 @@ exports.run = async (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 size = await gm(image.path).sizePromise();
const data = gm(image.path).coalesce().out("null:").out(watermark).gravity("North").resize(null, size.height).out("-layers", "composite");
const buffer = await gmToBuffer(data, image.outputType);
const buffer = await gm(image.path).coalesce().out("null:").out(watermark).gravity("North").resize(null, size.height).out("-layers", "composite").bufferPromise(image.type);
return message.channel.createMessage("", {
file: buffer,
name: `bandicam.${image.outputType}`
name: `bandicam.${image.type}`
});
};

View File

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

View File

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

View File

@ -1,7 +1,6 @@
const gm = require("gm").subClass({
imageMagick: true
});
const gmToBuffer = require("../utils/gmbuffer.js");
//const upload = require("../utils/upload.js");
exports.run = async (message, args) => {
@ -10,17 +9,15 @@ exports.run = async (message, args) => {
if (args.length === 0) return `${message.author.mention}, you need to provide some text to add a caption!`;
const processMessage = await message.channel.createMessage("<a:processing:479351417102925854> Processing... This might take a while");
const size = await gm(image.path).sizePromise();
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");
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 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");
const outputFinal = await gmToBuffer(command3, image.outputType);
const outputFinal = await 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").bufferPromise(image.type);
await processMessage.delete();
//return upload(message, outputFinal, `caption.${image.type}`);
return message.channel.createMessage("", {
file: outputFinal,
name: `caption.${image.outputType}`
name: `caption.${image.type}`
});
};

View File

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

View File

@ -1,7 +1,6 @@
const gm = require("gm").subClass({
imageMagick: true
});
const gmToBuffer = require("../utils/gmbuffer.js");
exports.run = async (message) => {
message.channel.sendTyping();
@ -9,11 +8,10 @@ exports.run = async (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 size = await gm(image.path).sizePromise();
const data = gm(image.path).coalesce().out("null:").out(watermark).gravity("Center").resize(null, size.height).out("-layers", "composite");
const buffer = await gmToBuffer(data, image.outputType);
const buffer = await gm(image.path).coalesce().out("null:").out(watermark).gravity("Center").resize(null, size.height).out("-layers", "composite").bufferPromise(image.type);
return message.channel.createMessage("", {
file: buffer,
name: `deviantart.${image.outputType}`
name: `deviantart.${image.type}`
});
};

View File

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

View File

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

View File

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

View File

@ -1,7 +1,6 @@
const gm = require("gm").subClass({
imageMagick: true
});
const gmToBuffer = require("../utils/gmbuffer.js");
exports.run = async (message) => {
message.channel.sendTyping();
@ -9,11 +8,10 @@ exports.run = async (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 size = await gm(image.path).sizePromise();
const data = gm(image.path).coalesce().out("null:").out(watermark).gravity("NorthEast").resize(null, size.height).out("-layers", "composite");
const buffer = await gmToBuffer(data, image.outputType);
const buffer = await gm(image.path).coalesce().out("null:").out(watermark).gravity("NorthEast").resize(null, size.height).out("-layers", "composite").bufferPromise(image.type);
return message.channel.createMessage("", {
file: buffer,
name: `funky.${image.outputType}`
name: `funky.${image.type}`
});
};

View File

@ -1,18 +1,16 @@
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 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");
const buffer = await gmToBuffer(command, image.outputType);
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);
return message.channel.createMessage("", {
file: buffer,
name: `gamexplain.${image.outputType}`
name: `gamexplain.${image.type}`
});
};

View File

@ -1,7 +1,6 @@
const gm = require("gm").subClass({
imageMagick: true
});
const gmToBuffer = require("../utils/gmbuffer.js");
exports.run = async (message) => {
message.channel.sendTyping();
@ -12,11 +11,10 @@ exports.run = async (message) => {
const size = await gm(image.path).sizePromise();
await gm(image.path).coalesce().gravity("West").crop("50%", 0).out("+repage").writePromise(data2);
await gm(data2).flop().writePromise(data);
const command = gm(data2).extent(size.width, size.height).out("null:").out(data).geometry(`+${size.width / 2}+0`).out("-layers", "Composite");
const buffer = await gmToBuffer(command, image.outputType);
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);
return message.channel.createMessage("", {
file: buffer,
name: `haah.${image.outputType}`
name: `haah.${image.type}`
});
};

View File

@ -1,15 +1,13 @@
const gm = require("gm").subClass({
imageMagick: true
});
const gmToBuffer = require("../utils/gmbuffer.js");
exports.run = async (message, args) => {
if (args.length === 0) return `${message.author.mention}, you need to provide some text to make a Homebrew Channel edit!`;
message.channel.sendTyping();
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);
const buffer = await gm(template).gravity("Center").font("./assets/hbc.ttf").out("-kerning", "-5").fill("white").pointSize(96).drawText(0, 0, cleanedMessage).bufferPromise("png");
return message.channel.createMessage("", {
file: buffer,
name: "homebrew.png"

View File

@ -1,7 +1,6 @@
const gm = require("gm").subClass({
imageMagick: true
});
const gmToBuffer = require("../utils/gmbuffer.js");
exports.run = async (message) => {
message.channel.sendTyping();
@ -12,11 +11,10 @@ exports.run = async (message) => {
const size = await gm(image.path).sizePromise();
await gm(image.path).coalesce().gravity("South").crop(0, "50%").out("+repage").writePromise(data2);
await gm(data2).flip().writePromise(data);
const command = gm(data2).extent(size.width, size.height).out("null:").out(data).geometry(`+0+${size.height / 2}`).out("-layers", "Composite");
const buffer = await gmToBuffer(command, image.outputType);
const buffer = await gm(data2).extent(size.width, size.height).out("null:").out(data).geometry(`+0+${size.height / 2}`).out("-layers", "Composite").bufferPromise(image.type);
return message.channel.createMessage("", {
file: buffer,
name: `hooh.${image.outputType}`
name: `hooh.${image.type}`
});
};

View File

@ -1,7 +1,6 @@
const gm = require("gm").subClass({
imageMagick: true
});
const gmToBuffer = require("../utils/gmbuffer.js");
exports.run = async (message) => {
message.channel.sendTyping();
@ -9,11 +8,10 @@ exports.run = async (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 size = await gm(image.path).sizePromise();
const data = gm(image.path).coalesce().out("null:").out(watermark).gravity("NorthWest").resize(null, size.height).out("-layers", "composite");
const buffer = await gmToBuffer(data, image.outputType);
const buffer = await gm(image.path).coalesce().out("null:").out(watermark).gravity("NorthWest").resize(null, size.height).out("-layers", "composite").bufferPromse(image.type);
return message.channel.createMessage("", {
file: buffer,
name: `hypercam.${image.outputType}`
name: `hypercam.${image.type}`
});
};

View File

@ -1,7 +1,6 @@
const gm = require("gm").subClass({
imageMagick: true
});
const gmToBuffer = require("../utils/gmbuffer.js");
exports.run = async (message) => {
message.channel.sendTyping();
@ -9,11 +8,10 @@ exports.run = async (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 size = await gm(image.path).sizePromise();
const data = gm(image.path).coalesce().out("null:").out(watermark).gravity("South").resize(size.width, null).out("-layers", "composite");
const buffer = await gmToBuffer(data, image.outputType);
const buffer = await gm(image.path).coalesce().out("null:").out(watermark).gravity("South").resize(size.width, null).out("-layers", "composite").bufferPromise(image.type);
return message.channel.createMessage("", {
file: buffer,
name: `ifunny.${image.outputType}`
name: `ifunny.${image.type}`
});
};

View File

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

View File

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

View File

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

View File

@ -1,20 +1,18 @@
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 make a Super Smash Bros. leak meme!`;
if (image.type === "gif" || image.type === "mp4") return `${message.author.mention}, this command doesn't work with GIFs!`;
if (image.type === "gif") return `${message.author.mention}, this command doesn't work with GIFs!`;
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 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 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: buffer,
name: `leak.${image.outputType}`
name: `leak.${image.type}`
});
};

View File

@ -1,21 +1,19 @@
const gm = require("gm").subClass({
imageMagick: true
});
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" || image.type === "mp4") return `${message.author.mention}, this command doesn't work with GIFs!`;
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");
const stream = await gm(image.path).coalesce().resize(600, 600).streamPromise("miff");
const stream2 = await gm(stream).out("-liquid-rescale", "300x300").streamPromise();
const data = gm(stream2).out("-liquid-rescale", "800x800");
const resultBuffer = await gmToBuffer(data, image.outputType);
const resultBuffer = await gm(stream2).out("-liquid-rescale", "800x800").bufferPromise(image.type);
await processMessage.delete();
return message.channel.createMessage("", {
file: resultBuffer,
name: `magik.${image.outputType}`
name: `magik.${image.type}`
});
};

View File

@ -1,7 +1,6 @@
const gm = require("gm").subClass({
imageMagick: true
});
const gmToBuffer = require("../utils/gmbuffer.js");
exports.run = async (message, args) => {
message.channel.sendTyping();
@ -16,11 +15,10 @@ exports.run = async (message, args) => {
const size = await gm(file).sizePromise();
await gm().out("-size", size.width).background("none").gravity("Center").out("(", "(").font("Impact").out("-pointsize", 40).out(`pango:<span foreground='white'>${topText.toUpperCase().replace(/&/g, "\\&amp;").replace(/>/g, "\\&gt;").replace(/</g, "\\&lt;").replace(/"/g, "\\&quot;").replace(/'/g, "\\&apos;")}</span>`).out(")", "(", "+clone").out("-channel", "A").out("-morphology", "EdgeOut", "Octagon", "+channel", "+level-colors", "black", ")").compose("DstOver").out(")", "-composite").writePromise(file2);
if (bottomText) await gm().out("-size", size.width).background("none").gravity("Center").out("(", "(").font("Impact").out("-pointsize", 40).out(`pango:<span foreground='white'>${bottomText.toUpperCase().replace(/&/g, "\\&amp;").replace(/>/g, "\\&gt;").replace(/</g, "\\&lt;").replace(/"/g, "\\&quot;").replace(/'/g, "\\&apos;")}</span>`).out(")", "(", "+clone").out("-channel", "A").out("-morphology", "EdgeOut", "Octagon", "+channel", "+level-colors", "black", ")").compose("DstOver").out(")", "-composite").writePromise(file3);
const data = gm(file).out("-coalesce").out("null:").gravity("North").out(file2).out("-layers", "composite").out("null:").gravity("South").out(bottomText ? file3 : "null:").out("-layers", "composite");
const buffer = await gmToBuffer(data, image.outputType);
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);
return message.channel.createMessage("", {
file: buffer,
name: `meme.${image.outputType}`
name: `meme.${image.type}`
});
};

View File

@ -1,7 +1,6 @@
const gm = require("gm").subClass({
imageMagick: true
});
const gmToBuffer = require("../utils/gmbuffer.js");
exports.run = async (message) => {
message.channel.sendTyping();
@ -10,17 +9,15 @@ exports.run = async (message) => {
const watermark = "./assets/images/memecenter.png";
let resultBuffer;
const size = await gm(image.path).sizePromise();
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");
const output = await gmToBuffer(command, image.outputType);
const output = await gm(image.path).coalesce().background("white").extent(size.width, size.height + 15).out("null:").out(watermark).gravity("SouthEast").compose("over").out("-layers", "composite").bufferPromise(image.type);
const size2 = await gm(output).sizePromise();
resultBuffer = output;
if (size.width !== size2.width) {
const command2 = gm(output).gravity("West").chop(size2.width - size.width, 0);
resultBuffer = await gmToBuffer(command2);
resultBuffer = await gm(output).gravity("West").chop(size2.width - size.width, 0).bufferPromise(image.type);
}
return message.channel.createMessage("", {
file: resultBuffer,
name: `memecenter.${image.outputType}`
name: `memecenter.${image.type}`
});
};

View File

@ -1,7 +1,6 @@
const gm = require("gm").subClass({
imageMagick: true
});
const gmToBuffer = require("../utils/gmbuffer.js");
exports.run = async (message, args) => {
const image = await require("../utils/imagedetect.js")(message);
@ -12,8 +11,7 @@ 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 command = gm().in("(").in(image.path).coalesce().resize(500, 500).borderColor("black").border(5, 5).out(")").borderColor("white").border(3, 3);
const buffer = await gmToBuffer(command, "miff");
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");
const size = await gm(buffer).sizePromise();
await gm(buffer).coalesce().background("black").gravity("Center").extent(600, size.height + 50).writePromise(file);
const size2 = await gm(file).sizePromise();
@ -24,15 +22,14 @@ exports.run = async (message, args) => {
if (bottomText) {
await gm().background("black").out("-size", "600").fill("white").font("Times").pointSize(28).gravity("Center").out(`pango:${bottomText}`).gravity("South").out("-splice", "0x20").writePromise(text2);
const size4 = await gm(text2).sizePromise();
const command3 = gm(await gmToBuffer(command2, 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");
resultBuffer = await gmToBuffer(command3, image.outputType);
resultBuffer = await gm(await command2.bufferPromise(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").bufferPromise(image.type);
} else {
resultBuffer = await gmToBuffer(command2, image.outputType);
resultBuffer = await command2.bufferPromise(image.type);
}
processMessage.delete();
return message.channel.createMessage("", {
file: resultBuffer,
name: `motivate.${image.outputType}`
name: `motivate.${image.type}`
});
};

View File

@ -1,15 +1,13 @@
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 a GIF to reverse!`;
if (image.type !== "gif" && image.type !== "mp4") return `${message.author.mention}, that isn't a GIF!`;
const data = gm(image.path).coalesce().out("-reverse");
const buffer = await gmToBuffer(data, image.outputType);
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);
return message.channel.createMessage("", {
file: buffer,
name: "reverse.gif"

View File

@ -1,18 +1,16 @@
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 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");
const buffer = await gmToBuffer(command, image.outputType);
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);
return message.channel.createMessage("", {
file: buffer,
name: `scott.${image.outputType}`
name: `scott.${image.type}`
});
};

View File

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

View File

@ -1,7 +1,6 @@
const gm = require("gm").subClass({
imageMagick: true
});
const gmToBuffer = require("../utils/gmbuffer.js");
exports.run = async (message) => {
message.channel.sendTyping();
@ -9,11 +8,10 @@ exports.run = async (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 size = await gm(image.path).sizePromise();
const command = gm(image.path).coalesce().out("null:").out(watermark).gravity("Center").resize(null, size.height).out("-layers", "composite");
const buffer = await gmToBuffer(command, image.outputType);
const buffer = await gm(image.path).coalesce().out("null:").out(watermark).gravity("Center").resize(null, size.height).out("-layers", "composite").bufferPromise(image.type);
return message.channel.createMessage("", {
file: buffer,
name: `shutterstock.${image.outputType}`
name: `shutterstock.${image.type}`
});
};

View File

@ -1,7 +1,6 @@
const gm = require("gm").subClass({
imageMagick: true
});
const gmToBuffer = require("../utils/gmbuffer.js");
const wrap = require("../utils/wrap.js");
exports.run = async (message, args) => {
@ -11,8 +10,7 @@ exports.run = async (message, args) => {
const file = `/tmp/${Math.random().toString(36).substring(2, 15)}.png`;
const cleanedMessage = args.join(" ").replace(/&/g, "\\&amp;").replace(/>/g, "\\&gt;").replace(/</g, "\\&lt;").replace(/"/g, "\\&quot;").replace(/'/g, "\\&apos;");
await gm(474, 332).out("+size").background("none").gravity("Center").out("-pointsize", 72).out("-font", "Bitstream Vera Sans").out(`pango:<span foreground="white">${wrap(cleanedMessage, {width: 15, indent: ""})}</span>`).writePromise(file);
const command = gm(template).composite(file).gravity("Center").geometry("474x332+160+10");
const buffer = await gmToBuffer(command, "png", "sonic");
const buffer = await gm(template).composite(file).gravity("Center").geometry("474x332+160+10").bufferPromise("png");
return message.channel.createMessage("", {
file: buffer,
name: "sonic.png"

View File

@ -5,26 +5,23 @@ const util = require("util");
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 a GIF to speed up!`;
if (image.type !== "gif" && image.type !== "mp4") return `${message.author.mention}, that isn't a GIF!`;
if (image.type !== "gif") return `${message.author.mention}, that isn't a GIF!`;
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 data = gm().delay(`${parseInt(delay[0]) / 2}x${delay[1]}`).out(image.path);
const buffer = await gmToBuffer(data, image.outputType);
const buffer = await gm().delay(`${parseInt(delay[0]) / 2}x${delay[1]}`).out(image.path).bufferPromise(image.type);
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 data = gm().out("(").out(image.path).coalesce().out(")").out("-delete", numbers);
const buffer = await gmToBuffer(data, image.outputType);
const buffer = await gm().out("(").out(image.path).coalesce().out(")").out("-delete", numbers).bufferPromise(image.type);
return message.channel.createMessage("", {
file: buffer,
name: "speed.gif"

View File

@ -1,14 +1,12 @@
const gm = require("gm").subClass({
imageMagick: true
});
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 spin!`;
const processMessage = await message.channel.createMessage("<a:processing:479351417102925854> Processing... This might take a while");
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);
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);
await processMessage.delete();
return message.channel.createMessage("", {
file: resultBuffer,

View File

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

View File

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

View File

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

View File

@ -1,18 +1,16 @@
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 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");
const buffer = await gmToBuffer(command, image.outputType);
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);
return message.channel.createMessage("", {
file: buffer,
name: `trump.${image.outputType}`
name: `trump.${image.type}`
});
};

View File

@ -1,7 +1,6 @@
const gm = require("gm").subClass({
imageMagick: true
});
const gmToBuffer = require("../utils/gmbuffer.js");
exports.run = async (message) => {
message.channel.sendTyping();
@ -12,11 +11,10 @@ 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 command = gm(data2).extent(size.width, size.height).out("null:").out(data).geometry(`+${size.width / 2}+0`).out("-layers", "Composite");
const buffer = await gmToBuffer(command, image.outputType);
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);
return message.channel.createMessage("", {
file: buffer,
name: `waaw.${image.outputType}`
name: `waaw.${image.type}`
});
};

View File

@ -1,18 +1,16 @@
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 make a wall from!`;
const output = await gm(image.path).coalesce().resize(128).streamPromise("miff");
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);
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);
return message.channel.createMessage("", {
file: buffer,
name: `wall.${image.outputType}`
name: `wall.${image.type}`
});
};

View File

@ -1,18 +1,16 @@
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 make a "who did this" meme!`;
const template = "./assets/images/whodidthis.png";
const command = gm(template).out("null:").out("(").out(image.path).coalesce().out(")").gravity("Center").resize("374x374>").out("-layers", "composite");
const buffer = await gmToBuffer(command, image.outputType);
const buffer = await gm(template).out("null:").out("(").out(image.path).coalesce().out(")").gravity("Center").resize("374x374>").out("-layers", "composite").bufferPromise(image.type);
return message.channel.createMessage("", {
file: buffer,
name: `wdt.${image.outputType}`
name: `wdt.${image.type}`
});
};

View File

@ -1,7 +1,6 @@
const gm = require("gm").subClass({
imageMagick: true
});
const gmToBuffer = require("../utils/gmbuffer.js");
exports.run = async (message) => {
message.channel.sendTyping();
@ -9,11 +8,10 @@ exports.run = async (message) => {
if (image === undefined) return `${message.author.mention}, you need to provide an image to stretch!`;
const size = await gm(image.path).sizePromise();
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);
const buffer = await gm(image.path).coalesce().resize(`${(size.width * 19) / 2}x${size.height / 2}!`).bufferPromise(image.type);
return message.channel.createMessage("", {
file: buffer,
name: `wide.${image.outputType}`
name: `wide.${image.type}`
});
};

View File

@ -1,7 +1,6 @@
const gm = require("gm").subClass({
imageMagick: true
});
const gmToBuffer = require("../utils/gmbuffer.js");
exports.run = async (message) => {
message.channel.sendTyping();
@ -12,11 +11,10 @@ exports.run = async (message) => {
const size = await gm(image.path).sizePromise();
await gm(image.path).coalesce().gravity("North").crop(0, "50%").out("+repage").writePromise(data2);
await gm(data2).flip().writePromise(data);
const command = gm(data2).extent(size.width, size.height).out("null:").out(data).geometry(`+0+${size.height / 2}`).out("-layers", "Composite");
const buffer = await gmToBuffer(command, image.outputType);
const buffer = await gm(data2).extent(size.width, size.height).out("null:").out(data).geometry(`+0+${size.height / 2}`).out("-layers", "Composite").bufferPromise(image.type);
return message.channel.createMessage("", {
file: buffer,
name: `woow.${image.outputType}`
name: `woow.${image.type}`
});
};

View File

@ -40,6 +40,23 @@ module.exports = async () => {
gm.prototype.streamPromise = promisify(gm.prototype.stream);
gm.prototype.sizePromise = promisify(gm.prototype.size);
gm.prototype.identifyPromise = promisify(gm.prototype.identify);
gm.prototype.bufferPromise = promisify(gm.prototype.toBuffer);
/*gm.prototype.bufferPromise = async (format, type) => {
console.log(this);
const stream = await this.out(type !== "sonic" ? "-layers" : "", type !== "sonic" ? "optimize" : "").streamPromise(format);
const chunks = [];
stream.stdout.on("data", (chunk) => {
chunks.push(chunk);
});
// these are 'once' because they can and do fire multiple times for multiple errors,
// but this is an async function so you'll have to deal with them one at a time
stream.stdout.once("end", () => {
return Buffer.concat(chunks);
});
stream.stderr.once("data", (data) => {
data.toString();
});
};*/
// tweet stuff
if (twitter !== null && twitter.active === false) {

View File

@ -19,9 +19,8 @@ const typeCheck = async (image, gifv = false) => {
const path = `/tmp/${Math.random().toString(36).substring(2, 15)}.${imageType.ext}`;
await writeFile(path, imageBuffer);
return {
type: imageType.ext,
data: imageBuffer,
outputType: imageType.ext === "mp4" ? "gif" : imageType.ext,
type: imageType.ext === "mp4" ? "gif" : imageType.ext,
path: path
};
} else {

View File

@ -4,7 +4,7 @@
FROM alpine:edge
RUN apk --no-cache upgrade && apk add --no-cache chromium && apk add --no-cache squid && apk add --no-cache sudo
RUN apk --no-cache upgrade && apk add --no-cache chromium squid sudo
ENV ALL_PROXY "http://localhost:3128"
RUN echo -e "\nvisible_hostname esmBot\nforwarded_for delete\nvia off\nfollow_x_forwarded_for deny all \