const gm = require("gm").subClass({ imageMagick: true }); const gmToBuffer = require("../utils/gmbuffer.js"); exports.run = async (message, args) => { 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 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()); const file = `/tmp/${Math.random().toString(36).substring(2, 15)}.miff`; const file2 = `/tmp/${Math.random().toString(36).substring(2, 15)}.png`; const file3 = `/tmp/${Math.random().toString(36).substring(2, 15)}.png`; await gm(image.path).coalesce().resize(600, 600).noProfile().writePromise(file); const size = await gm(file).sizePromise(); await gm().out("-size", size.width).background("none").gravity("Center").out("(", "(").font("Impact").out("-pointsize", 40).out(`pango:${topText.toUpperCase().replace(/&/g, "\\&").replace(/>/g, "\\>").replace(/`).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:${bottomText.toUpperCase().replace(/&/g, "\\&").replace(/>/g, "\\>").replace(/`).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); return message.channel.createMessage("", { file: buffer, name: `meme.${image.outputType}` }); }; exports.category = 5; exports.help = "Generates a meme from an image (separate top/bottom text with a comma)"; exports.params = "[top text], {bottom text}";