2020-01-27 21:27:33 +00:00
|
|
|
const gm = require("gm").subClass({
|
|
|
|
imageMagick: true
|
|
|
|
});
|
|
|
|
const gmToBuffer = require("../utils/gmbuffer.js");
|
2019-09-13 20:02:41 +00:00
|
|
|
|
|
|
|
exports.run = async (message, args) => {
|
2019-12-02 20:47:22 +00:00
|
|
|
message.channel.sendTyping();
|
2019-09-13 20:02:41 +00:00
|
|
|
const image = await require("../utils/imagedetect.js")(message);
|
|
|
|
if (image === undefined) return `${message.author.mention}, you need to provide an image to generate a meme!`;
|
|
|
|
if (args.length === 0) return `${message.author.mention}, you need to provide some text to generate a meme!`;
|
|
|
|
const [topText, bottomText] = args.join(" ").split(",").map(elem => elem.trim());
|
2020-01-28 16:03:22 +00:00
|
|
|
const file = `/tmp/${Math.random().toString(36).substring(2, 15)}.miff`;
|
2020-01-27 21:27:33 +00:00
|
|
|
const file2 = `/tmp/${Math.random().toString(36).substring(2, 15)}.png`;
|
|
|
|
const file3 = `/tmp/${Math.random().toString(36).substring(2, 15)}.png`;
|
2020-02-18 20:44:39 +00:00
|
|
|
gm(image.path).coalesce().resize(600, 600).noProfile().write(file, (error) => {
|
2019-12-10 15:53:43 +00:00
|
|
|
if (error) throw error;
|
2020-01-27 21:27:33 +00:00
|
|
|
gm(file).size((error, size) => {
|
|
|
|
if (error) throw error;
|
2020-01-27 22:04:10 +00:00
|
|
|
gm().out("-size", size.width).background("none").gravity("Center").out("(", "(").font("Impact").out("-pointsize", 40).out(`pango:<span foreground='white'>${topText.toUpperCase().replace(/&/g, "\\&").replace(/>/g, "\\>").replace(/</g, "\\<").replace(/"/g, "\\"").replace(/'/g, "\\'")}</span>`).out(")", "(", "+clone").out("-channel", "A").out("-morphology", "EdgeOut", "Octagon", "+channel", "+level-colors", "black", ")").compose("DstOver").out(")", "-composite").write(file2, (error) => {
|
2020-01-27 21:27:33 +00:00
|
|
|
if (error) throw error;
|
2020-01-27 22:04:10 +00:00
|
|
|
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, "\\&").replace(/>/g, "\\>").replace(/</g, "\\<").replace(/"/g, "\\"").replace(/'/g, "\\'") : " "}</span>`).out(")", "(", "+clone").out("-channel", "A").out("-morphology", "EdgeOut", "Octagon", "+channel", "+level-colors", "black", ")").compose("DstOver").out(")", "-composite").write(file3, async (error) => {
|
2020-01-27 21:27:33 +00:00
|
|
|
if (error) throw error;
|
2020-01-28 16:03:22 +00:00
|
|
|
const data = gm(file).out("-coalesce").out("null:").gravity("North").out(file2).out("-layers", "composite").out("null:").gravity("South").out(file3).out("-layers", "composite").out("-layers", "optimize");
|
2020-02-19 14:25:45 +00:00
|
|
|
const buffer = await gmToBuffer(data, image.outputType);
|
2020-01-27 21:27:33 +00:00
|
|
|
return message.channel.createMessage("", {
|
2020-02-19 14:25:45 +00:00
|
|
|
file: buffer,
|
2020-02-18 20:44:39 +00:00
|
|
|
name: `meme.${image.outputType}`
|
2020-01-27 21:27:33 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2019-09-13 20:02:41 +00:00
|
|
|
});
|
|
|
|
});
|
2019-12-02 20:47:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.category = 5;
|
2019-12-05 16:58:46 +00:00
|
|
|
exports.help = "Generates a meme from an image (separate top/bottom text with a comma)";
|
|
|
|
exports.params = "[top text], {bottom text}";
|