Removed node version check, promisified many gm calls

This commit is contained in:
TheEssem 2020-02-20 18:26:49 -06:00
parent 1c9d40041b
commit 1e259ab312
24 changed files with 187 additions and 276 deletions

3
app.js
View file

@ -1,6 +1,3 @@
// check if using node 10 or higher
if (process.version.slice(1).split(".")[0] < 10) throw new Error("Node 10.0.0 or higher is required. Update Node on your system.");
// load config from .env file // load config from .env file
require("dotenv").config(); require("dotenv").config();

View file

@ -8,14 +8,12 @@ exports.run = async (message) => {
const image = await require("../utils/imagedetect.js")(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!`; 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 watermark = "./assets/images/bandicam.png";
gm(image.path).size(async (error, size) => { const size = await gm(image.path).sizePromise();
if (error) throw error; const data = gm(image.path).coalesce().out("null:").out(watermark).gravity("North").resize(null, size.height).out("-layers", "composite");
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 gmToBuffer(data, image.outputType); return message.channel.createMessage("", {
return message.channel.createMessage("", { file: buffer,
file: buffer, name: `bandicam.${image.outputType}`
name: `bandicam.${image.outputType}`
});
}); });
}; };

View file

@ -9,24 +9,18 @@ exports.run = async (message, args) => {
if (image === undefined) return `${message.author.mention}, you need to provide an image/GIF to add a caption!`; 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!`; 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 processMessage = await message.channel.createMessage("<a:processing:479351417102925854> Processing... This might take a while");
gm(image.path).size(async (error, size) => { const size = await gm(image.path).sizePromise();
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 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 gmToBuffer(command, "png"); const size2 = await gm(output).sizePromise();
gm(output).size(async (error, size2) => { const output2 = await gm(output).gravity("Center").trim().out("+repage").extent(size.width, size2.height + (size.width / 10)).streamPromise();
if (error) throw error; 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");
gm(output).gravity("Center").trim().out("+repage").extent(size.width, size2.height + (size.width / 10)).stream(async (error, output2) => { const outputFinal = await gmToBuffer(command3, image.outputType);
if (error) throw error; await processMessage.delete();
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"); //return upload(message, outputFinal, `caption.${image.type}`);
const outputFinal = await gmToBuffer(command3, image.outputType); return message.channel.createMessage("", {
await processMessage.delete(); file: outputFinal,
//return upload(message, outputFinal, `caption.${image.type}`); name: `caption.${image.outputType}`
return message.channel.createMessage("", {
file: outputFinal,
name: `caption.${image.outputType}`
});
});
});
}); });
}; };

View file

@ -8,14 +8,12 @@ exports.run = async (message) => {
const image = await require("../utils/imagedetect.js")(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!`; 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 watermark = "./assets/images/deviantart.png";
gm(image.path).size(async (error, size) => { const size = await gm(image.path).sizePromise();
if (error) throw error; const data = gm(image.path).coalesce().out("null:").out(watermark).gravity("Center").resize(null, size.height).out("-layers", "composite");
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 gmToBuffer(data, image.outputType); return message.channel.createMessage("", {
return message.channel.createMessage("", { file: buffer,
file: buffer, name: `deviantart.${image.outputType}`
name: `deviantart.${image.outputType}`
});
}); });
}; };

View file

@ -8,14 +8,12 @@ exports.run = async (message) => {
const image = await require("../utils/imagedetect.js")(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!`; 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 watermark = "./assets/images/funky.png";
gm(image.path).size(async (error, size) => { const size = await gm(image.path).sizePromise();
if (error) throw error; const data = gm(image.path).coalesce().out("null:").out(watermark).gravity("NorthEast").resize(null, size.height).out("-layers", "composite");
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 gmToBuffer(data, image.outputType); return message.channel.createMessage("", {
return message.channel.createMessage("", { file: buffer,
file: buffer, name: `funky.${image.outputType}`
name: `funky.${image.outputType}`
});
}); });
}; };

View file

@ -1,5 +1,3 @@
// really don't like this file
const gm = require("gm").subClass({ const gm = require("gm").subClass({
imageMagick: true imageMagick: true
}); });
@ -11,20 +9,14 @@ exports.run = async (message) => {
if (image === undefined) return `${message.author.mention}, you need to provide an image to mirror!`; 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 data = `/tmp/${Math.random().toString(36).substring(2, 15)}.miff`;
const data2 = `/tmp/${Math.random().toString(36).substring(2, 15)}.miff`; const data2 = `/tmp/${Math.random().toString(36).substring(2, 15)}.miff`;
gm(image.path).size((error, size) => { const size = await gm(image.path).sizePromise();
if (error) throw error; await gm(image.path).coalesce().gravity("West").crop("50%", 0).out("+repage").writePromise(data2);
gm(image.path).coalesce().gravity("West").crop("50%", 0).out("+repage").write(data2, (error) => { await gm(data2).flop().writePromise(data);
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");
gm(data2).flop().write(data, async (error) => { const buffer = await gmToBuffer(command, image.outputType);
if (error) throw error; return message.channel.createMessage("", {
const command = gm(data2).extent(size.width, size.height).out("null:").out(data).geometry(`+${size.width / 2}+0`).out("-layers", "Composite"); file: buffer,
const buffer = await gmToBuffer(command, image.outputType); name: `haah.${image.outputType}`
return message.channel.createMessage("", {
file: buffer,
name: `haah.${image.outputType}`
});
});
});
}); });
}; };

View file

@ -1,5 +1,3 @@
// really don't like this file
const gm = require("gm").subClass({ const gm = require("gm").subClass({
imageMagick: true imageMagick: true
}); });
@ -11,20 +9,14 @@ exports.run = async (message) => {
if (image === undefined) return `${message.author.mention}, you need to provide an image to mirror!`; 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 data = `/tmp/${Math.random().toString(36).substring(2, 15)}.miff`;
const data2 = `/tmp/${Math.random().toString(36).substring(2, 15)}.miff`; const data2 = `/tmp/${Math.random().toString(36).substring(2, 15)}.miff`;
gm(image.path).size((error, size) => { const size = await gm(image.path).sizePromise();
if (error) throw error; await gm(image.path).coalesce().gravity("South").crop(0, "50%").out("+repage").writePromise(data2);
gm(image.path).coalesce().gravity("South").crop(0, "50%").out("+repage").write(data2, (error) => { await gm(data2).flip().writePromise(data);
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");
gm(data2).flip().write(data, async (error) => { const buffer = await gmToBuffer(command, image.outputType);
if (error) throw error; return message.channel.createMessage("", {
const command = gm(data2).extent(size.width, size.height).out("null:").out(data).geometry(`+0+${size.height / 2}`).out("-layers", "Composite"); file: buffer,
const buffer = await gmToBuffer(command, image.outputType); name: `hooh.${image.outputType}`
return message.channel.createMessage("", {
file: buffer,
name: `hooh.${image.outputType}`
});
});
});
}); });
}; };

View file

@ -8,14 +8,12 @@ exports.run = async (message) => {
const image = await require("../utils/imagedetect.js")(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!`; 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 watermark = "./assets/images/hypercam.png";
gm(image.path).size(async (error, size) => { const size = await gm(image.path).sizePromise();
if (error) throw error; const data = gm(image.path).coalesce().out("null:").out(watermark).gravity("NorthWest").resize(null, size.height).out("-layers", "composite");
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 gmToBuffer(data, image.outputType); return message.channel.createMessage("", {
return message.channel.createMessage("", { file: buffer,
file: buffer, name: `hypercam.${image.outputType}`
name: `hypercam.${image.outputType}`
});
}); });
}; };

View file

@ -8,14 +8,12 @@ exports.run = async (message) => {
const image = await require("../utils/imagedetect.js")(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!`; 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 watermark = "./assets/images/ifunny.png";
gm(image.path).size(async (error, size) => { const size = await gm(image.path).sizePromise();
if (error) throw error; const data = gm(image.path).coalesce().out("null:").out(watermark).gravity("South").resize(size.width, null).out("-layers", "composite");
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 gmToBuffer(data, image.outputType); return message.channel.createMessage("", {
return message.channel.createMessage("", { file: buffer,
file: buffer, name: `ifunny.${image.outputType}`
name: `ifunny.${image.outputType}`
});
}); });
}; };

View file

@ -8,18 +8,14 @@ exports.run = async (message) => {
if (image === undefined) return `${message.author.mention}, you need to provide an image to add some magik!`; 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" || 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"); 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) => { const stream = await gm(image.path).coalesce().resize(600, 600).streamPromise("miff");
if (error) throw error; const stream2 = await gm(stream).out("-liquid-rescale", "300x300").streamPromise();
gm(stream).out("-liquid-rescale", "400x400").stream(async (error, stream2) => { const data = gm(stream2).out("-liquid-rescale", "800x800");
if (error) throw error; const resultBuffer = await gmToBuffer(data, image.outputType);
const data = gm(stream2).out("-liquid-rescale", "1200x1200"); await processMessage.delete();
const resultBuffer = await gmToBuffer(data); return message.channel.createMessage("", {
await processMessage.delete(); file: resultBuffer,
return message.channel.createMessage("", { name: `magik.${image.outputType}`
file: resultBuffer,
name: `magik.${image.outputType}`
});
});
}); });
}; };

View file

@ -12,23 +12,15 @@ exports.run = async (message, args) => {
const file = `/tmp/${Math.random().toString(36).substring(2, 15)}.miff`; const file = `/tmp/${Math.random().toString(36).substring(2, 15)}.miff`;
const file2 = `/tmp/${Math.random().toString(36).substring(2, 15)}.png`; const file2 = `/tmp/${Math.random().toString(36).substring(2, 15)}.png`;
const file3 = `/tmp/${Math.random().toString(36).substring(2, 15)}.png`; const file3 = `/tmp/${Math.random().toString(36).substring(2, 15)}.png`;
gm(image.path).coalesce().resize(600, 600).noProfile().write(file, (error) => { await gm(image.path).coalesce().resize(600, 600).noProfile().writePromise(file);
if (error) throw error; const size = await gm(file).sizePromise();
gm(file).size((error, size) => { 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 (error) throw error; 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);
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").write(file2, (error) => { 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");
if (error) throw error; const buffer = await gmToBuffer(data, image.outputType);
gm().out("-size", size.width).background("none").gravity("Center").out("(", "(").font("Impact").out("-pointsize", 40).out(`pango:<span foreground='white'>${bottomText ? 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").write(file3, async (error) => { return message.channel.createMessage("", {
if (error) throw error; file: buffer,
const data = gm(file).out("-coalesce").out("null:").gravity("North").out(file2).out("-layers", "composite").out("null:").gravity("South").out(file3).out("-layers", "composite"); name: `meme.${image.outputType}`
const buffer = await gmToBuffer(data, image.outputType);
return message.channel.createMessage("", {
file: buffer,
name: `meme.${image.outputType}`
});
});
});
});
}); });
}; };

View file

@ -9,22 +9,18 @@ exports.run = async (message) => {
if (image === undefined) return `${message.author.mention}, you need to provide an image to add a MemeCenter watermark!`; if (image === undefined) return `${message.author.mention}, you need to provide an image to add a MemeCenter watermark!`;
const watermark = "./assets/images/memecenter.png"; const watermark = "./assets/images/memecenter.png";
let resultBuffer; let resultBuffer;
gm(image.path).size(async (error, size) => { const size = await gm(image.path).sizePromise();
if (error) throw error; 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 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 gmToBuffer(command, image.outputType); const size2 = await gm(output).sizePromise();
gm(output).size(async (error, size2) => { resultBuffer = output;
if (error) throw error; if (size.width !== size2.width) {
resultBuffer = output; const command2 = gm(output).gravity("West").chop(size2.width - size.width, 0);
if (size.width !== size2.width) { resultBuffer = await gmToBuffer(command2);
const command2 = gm(output).gravity("West").chop(size2.width - size.width, 0); }
resultBuffer = await gmToBuffer(command2); return message.channel.createMessage("", {
} file: resultBuffer,
return message.channel.createMessage("", { name: `memecenter.${image.outputType}`
file: resultBuffer,
name: `memecenter.${image.outputType}`
});
});
}); });
}; };

View file

@ -10,50 +10,29 @@ exports.run = async (message, args) => {
const processMessage = await message.channel.createMessage("<a:processing:479351417102925854> Processing... This might take a while"); 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 [topText, bottomText] = args.join(" ").split(",").map(elem => elem.trim());
const file = `/tmp/${Math.random().toString(36).substring(2, 15)}.miff`; 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 text = `/tmp/${Math.random().toString(36).substring(2, 15)}.png`;
const text2 = `/tmp/${Math.random().toString(36).substring(2, 15)}.png`; const text2 = `/tmp/${Math.random().toString(36).substring(2, 15)}.png`;
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) => { const command = gm().in("(").in(image.path).coalesce().resize(500, 500).borderColor("black").border(5, 5).out(")").borderColor("white").border(3, 3);
if (error) throw error; const buffer = await gmToBuffer(command, "miff");
gm(file).size((error, size) => { const size = await gm(buffer).sizePromise();
if (error) throw error; await gm(buffer).coalesce().background("black").gravity("Center").extent(600, size.height + 50).writePromise(file);
gm(file).coalesce().background("black").gravity("Center").extent(600, size.height + 50).out("+swap").write(file2, () => { const size2 = await gm(file).sizePromise();
// this is commented out because it was causing some issues and I couldn't find an elegant solution await gm().background("black").out("-size", "600").fill("white").font("Times").pointSize(56).gravity("Center").out(`pango:${topText}`).gravity("South").out("-splice", bottomText ? "0x0" : "0x20").writePromise(text);
// if (error) throw error; const size3 = await gm(text).sizePromise();
gm(file2).size((error, size2) => { const command2 = gm(file).gravity("North").coalesce().background("black").extent(600, size2.height + size3.height).out("null:", "(", text, "-set", "page", `+0+${size2.height}`, ")", "-layers", "composite", "-layers", "optimize");
if (error) throw error; let resultBuffer;
gm().background("black").out("-size", "600").fill("white").font("Times").pointSize(56).gravity("Center").out(`pango:${topText}`).gravity("South").out("-splice", bottomText ? "0x0" : "0x20").write(text, (error) => { if (bottomText) {
if (error) throw error; 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);
gm(text).size(async (error, size3) => { const size4 = await gm(text2).sizePromise();
if (error) throw error; 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");
const command = gm(file2).gravity("North").coalesce().background("black").extent(600, size2.height + size3.height).out("null:", "(", text, "-set", "page", `+0+${size2.height}`, ")", "-layers", "composite", "-layers", "optimize"); resultBuffer = await gmToBuffer(command3, image.outputType);
if (bottomText) { } else {
gm().background("black").out("-size", "600").fill("white").font("Times").pointSize(28).gravity("Center").out(`pango:${bottomText}`).gravity("South").out("-splice", "0x20").write(text2, (error) => { resultBuffer = await gmToBuffer(command2, image.outputType);
if (error) throw error; }
gm(text2).size(async (error, size4) => { processMessage.delete();
if (error) throw error; return message.channel.createMessage("", {
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"); file: resultBuffer,
const resultBuffer = await gmToBuffer(command2, image.outputType); name: `motivate.${image.outputType}`
processMessage.delete();
return message.channel.createMessage("", {
file: resultBuffer,
name: `motivate.${image.outputType}`
});
});
});
} else {
const resultBuffer = await gmToBuffer(command, image.outputType);
processMessage.delete();
return message.channel.createMessage("", {
file: resultBuffer,
name: `motivate.${image.outputType}`
});
}
});
});
});
});
});
}); });
}; };

View file

@ -8,14 +8,12 @@ exports.run = async (message) => {
const image = await require("../utils/imagedetect.js")(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!`; 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 watermark = "./assets/images/shutterstock.png";
gm(image.path).size(async (error, size) => { const size = await gm(image.path).sizePromise();
if (error) throw error; const command = gm(image.path).coalesce().out("null:").out(watermark).gravity("Center").resize(null, size.height).out("-layers", "composite");
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 gmToBuffer(command, image.outputType); return message.channel.createMessage("", {
return message.channel.createMessage("", { file: buffer,
file: buffer, name: `shutterstock.${image.outputType}`
name: `shutterstock.${image.outputType}`
});
}); });
}; };

View file

@ -10,14 +10,12 @@ exports.run = async (message, args) => {
const template = "./assets/images/sonic.jpg"; const template = "./assets/images/sonic.jpg";
const file = `/tmp/${Math.random().toString(36).substring(2, 15)}.png`; 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;"); const cleanedMessage = args.join(" ").replace(/&/g, "\\&amp;").replace(/>/g, "\\&gt;").replace(/</g, "\\&lt;").replace(/"/g, "\\&quot;").replace(/'/g, "\\&apos;");
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>`).write(file, async (error) => { 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);
if (error) throw error; const command = gm(template).composite(file).gravity("Center").geometry("474x332+160+10");
const command = gm(template).composite(file).gravity("Center").geometry("474x332+160+10"); const buffer = await gmToBuffer(command, "png", "sonic");
const buffer = await gmToBuffer(command, "png", "sonic"); return message.channel.createMessage("", {
return message.channel.createMessage("", { file: buffer,
file: buffer, name: "sonic.png"
name: "sonic.png"
});
}); });
}; };

View file

@ -1,4 +1,6 @@
const { exec } = require("child_process"); const {
exec
} = require("child_process");
const util = require("util"); const util = require("util");
const gm = require("gm").subClass({ const gm = require("gm").subClass({
imageMagick: true imageMagick: true
@ -10,25 +12,24 @@ exports.run = async (message) => {
const image = await require("../utils/imagedetect.js")(message); 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 === 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" && image.type !== "mp4") return `${message.author.mention}, that isn't a GIF!`;
gm(image.path).identify(async (error, value) => { const value = await gm(image.path).identifyPromise();
if (error) throw error; const delay = value.Delay ? value.Delay[0].split("x") : [0, 100];
const delay = value.Delay ? value.Delay[0].split("x") : [0, 100]; if (Math.round(parseInt(delay[0]) / 2) >= 2) {
if (Math.round(parseInt(delay[0]) / 2) >= 2) { const data = gm().delay(`${parseInt(delay[0]) / 2}x${delay[1]}`).out(image.path);
const data = gm().delay(`${parseInt(delay[0]) / 2}x${delay[1]}`).out(image.path); const buffer = await gmToBuffer(data, image.outputType);
return message.channel.createMessage("", { return message.channel.createMessage("", {
file: await gmToBuffer(data, image.outputType), file: buffer,
name: "speed.gif" name: "speed.gif"
}); });
} else { } else {
const numbers = (await util.promisify(exec)(`seq 0 2 ${value.Scene.length}`)).stdout.split("\n").join(","); 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 data = gm().out("(").out(image.path).coalesce().out(")").out("-delete", numbers);
const buffer = await gmToBuffer(data, image.outputType); const buffer = await gmToBuffer(data, image.outputType);
return message.channel.createMessage("", { return message.channel.createMessage("", {
file: buffer, file: buffer,
name: "speed.gif" name: "speed.gif"
}); });
} }
});
}; };
exports.aliases = ["speedup", "fast", "gifspeed"]; exports.aliases = ["speedup", "fast", "gifspeed"];

View file

@ -7,14 +7,12 @@ exports.run = async (message) => {
message.channel.sendTyping(); message.channel.sendTyping();
const image = await require("../utils/imagedetect.js")(message); const image = await require("../utils/imagedetect.js")(message);
if (image === undefined) return `${message.author.mention}, you need to provide an image to tile!`; if (image === undefined) return `${message.author.mention}, you need to provide an image to tile!`;
gm(image.path).coalesce().command("montage").out("-duplicate").out(24).tile("5x5").geometry("+0+0").stream("miff", async (error, output) => { const output = await gm(image.path).coalesce().command("montage").out("-duplicate").out(24).tile("5x5").geometry("+0+0").streamPromise("miff");
if (error) throw error; const data = gm(output).coalesce().resize("800x800>");
const data = gm(output).coalesce().resize("800x800>"); const buffer = await gmToBuffer(data, image.outputType);
const buffer = await gmToBuffer(data, image.outputType); return message.channel.createMessage("", {
return message.channel.createMessage("", { file: buffer,
file: buffer, name: `tile.${image.outputType}`
name: `tile.${image.outputType}`
});
}); });
}; };

View file

@ -1,5 +1,3 @@
// really don't like this file
const gm = require("gm").subClass({ const gm = require("gm").subClass({
imageMagick: true imageMagick: true
}); });
@ -11,23 +9,17 @@ exports.run = async (message) => {
if (image === undefined) return `${message.author.mention}, you need to provide an image to mirror!`; 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 data = `/tmp/${Math.random().toString(36).substring(2, 15)}.miff`;
const data2 = `/tmp/${Math.random().toString(36).substring(2, 15)}.miff`; const data2 = `/tmp/${Math.random().toString(36).substring(2, 15)}.miff`;
gm(image.path).size((error, size) => { const size = await gm(image.path).sizePromise();
if (error) throw error; await gm(image.path).coalesce().gravity("East").crop("50%", 0).out("+repage").writePromise(data2);
gm(image.path).coalesce().gravity("East").crop("50%", 0).out("+repage").write(data2, (error) => { await gm(data2).flop().writePromise(data);
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");
gm(data2).flop().write(data, async (error) => { const buffer = await gmToBuffer(command, image.outputType);
if (error) throw error; return message.channel.createMessage("", {
const command = gm(data2).extent(size.width, size.height).out("null:").out(data).geometry(`+${size.width / 2}+0`).out("-layers", "Composite"); file: buffer,
const buffer = await gmToBuffer(command, image.outputType); name: `waaw.${image.outputType}`
return message.channel.createMessage("", {
file: buffer,
name: `waaw.${image.outputType}`
});
});
});
}); });
}; };
exports.aliases = ["magik3", "mirror"]; exports.aliases = ["magik3", "mirror"];
exports.category = 5; exports.category = 5;
exports.help = "Mirrors the right side of an image onto the left"; exports.help = "Mirrors the right side of an image onto the left";

View file

@ -7,14 +7,12 @@ exports.run = async (message) => {
message.channel.sendTyping(); message.channel.sendTyping();
const image = await require("../utils/imagedetect.js")(message); const image = await require("../utils/imagedetect.js")(message);
if (image === undefined) return `${message.author.mention}, you need to provide an image to make a wall from!`; if (image === undefined) return `${message.author.mention}, you need to provide an image to make a wall from!`;
gm(image.path).coalesce().resize(128).stream("miff", async (error, output) => { const output = await gm(image.path).coalesce().resize(128).streamPromise("miff");
if (error) throw error; const data = gm(output).coalesce().virtualPixel("tile").matteColor("none").out("-background", "none").resize("512x512!").out("-distort").out("Perspective").out("0,0,57,42 0,128,63,130 128,0,140,60 128,128,140,140");
const 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 gmToBuffer(data, image.outputType); return message.channel.createMessage("", {
return message.channel.createMessage("", { file: buffer,
file: buffer, name: `wall.${image.outputType}`
name: `wall.${image.outputType}`
});
}); });
}; };

View file

@ -8,7 +8,7 @@ exports.run = async (message) => {
const image = await require("../utils/imagedetect.js")(message); const image = await require("../utils/imagedetect.js")(message);
if (image === undefined) return `${message.author.mention}, you need to provide an image to make a "who did this" meme!`; 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 template = "./assets/images/whodidthis.png";
const command = gm(template).coalesce().out("null:").out(image.path).gravity("Center").resize("374x374>").out("-layers", "composite"); 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 gmToBuffer(command, image.outputType);
return message.channel.createMessage("", { return message.channel.createMessage("", {
file: buffer, file: buffer,

View file

@ -7,15 +7,13 @@ exports.run = async (message) => {
message.channel.sendTyping(); message.channel.sendTyping();
const image = await require("../utils/imagedetect.js")(message); const image = await require("../utils/imagedetect.js")(message);
if (image === undefined) return `${message.author.mention}, you need to provide an image to stretch!`; if (image === undefined) return `${message.author.mention}, you need to provide an image to stretch!`;
gm(image.path).size(async (error, size) => { const size = await gm(image.path).sizePromise();
if (error) throw error; if (size.width > 10000) return `${message.author.mention}, this image is too wide!`;
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 data = gm(image.path).coalesce().resize(`${(size.width * 19) / 2}x${size.height / 2}!`); const buffer = await gmToBuffer(data, image.outputType);
const buffer = await gmToBuffer(data, image.outputType); return message.channel.createMessage("", {
return message.channel.createMessage("", { file: buffer,
file: buffer, name: `wide.${image.outputType}`
name: `wide.${image.outputType}`
});
}); });
}; };

View file

@ -1,5 +1,3 @@
// really don't like this file
const gm = require("gm").subClass({ const gm = require("gm").subClass({
imageMagick: true imageMagick: true
}); });
@ -11,20 +9,14 @@ exports.run = async (message) => {
if (image === undefined) return `${message.author.mention}, you need to provide an image to mirror!`; 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 data = `/tmp/${Math.random().toString(36).substring(2, 15)}.miff`;
const data2 = `/tmp/${Math.random().toString(36).substring(2, 15)}.miff`; const data2 = `/tmp/${Math.random().toString(36).substring(2, 15)}.miff`;
gm(image.path).size((error, size) => { const size = await gm(image.path).sizePromise();
if (error) throw error; await gm(image.path).coalesce().gravity("North").crop(0, "50%").out("+repage").writePromise(data2);
gm(image.path).coalesce().gravity("North").crop(0, "50%").out("+repage").write(data2, (error) => { await gm(data2).flip().writePromise(data);
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");
gm(data2).flip().write(data, async (error) => { const buffer = await gmToBuffer(command, image.outputType);
if (error) throw error; return message.channel.createMessage("", {
const command = gm(data2).extent(size.width, size.height).out("null:").out(data).geometry(`+0+${size.height / 2}`).out("-layers", "Composite"); file: buffer,
const buffer = await gmToBuffer(command, image.outputType); name: `woow.${image.outputType}`
return message.channel.createMessage("", {
file: buffer,
name: `woow.${image.outputType}`
});
});
});
}); });
}; };

View file

@ -1,3 +1,5 @@
const gm = require("gm");
const { promisify } = require("util");
const client = require("../utils/client.js"); const client = require("../utils/client.js");
const database = require("../utils/database.js"); const database = require("../utils/database.js");
const logger = require("../utils/logger.js"); const logger = require("../utils/logger.js");
@ -33,6 +35,12 @@ module.exports = async () => {
setTimeout(activityChanger, 900000); setTimeout(activityChanger, 900000);
})(); })();
// add gm extensions
gm.prototype.writePromise = promisify(gm.prototype.write);
gm.prototype.streamPromise = promisify(gm.prototype.stream);
gm.prototype.sizePromise = promisify(gm.prototype.size);
gm.prototype.identifyPromise = promisify(gm.prototype.identify);
// tweet stuff // tweet stuff
if (twitter !== null && twitter.active === false) { if (twitter !== null && twitter.active === false) {
const blocks = await twitter.client.get("blocks/ids", { stringify_ids: true }); const blocks = await twitter.client.get("blocks/ids", { stringify_ids: true });

View file

@ -33,7 +33,7 @@ const paginationEmbed = async (message, pages, timeout = 120000) => {
if (manageMessages) msg.removeReaction("🔢", userID); if (manageMessages) msg.removeReaction("🔢", userID);
}); });
}).catch(error => { }).catch(error => {
if (error) throw error; throw error;
}); });
break; break;
case "▶": case "▶":