diff --git a/README.md b/README.md index 6e20ffe8..ecf1f225 100644 --- a/README.md +++ b/README.md @@ -478,6 +478,7 @@ Total: 514 * **subtitle:** Adds subtitles to an image. * **swirl:** Draws an image or a user's avatar but swirled. * **tint:** Draws an image or a user's avatar but tinted a specific color. +* **trans:** Draws an image or a user's avatar but with a Transgender flag on it. * **vignette:** Draws an image or a user's avatar with a vignette. * **wanted:** Draws an image or a user's avatar over a wanted poster. * **wild-pokemon:** Draws an image or a user's avatar over a wild Pokémon appearance. diff --git a/assets/images/trans.png b/assets/images/trans.png new file mode 100644 index 00000000..72afc917 Binary files /dev/null and b/assets/images/trans.png differ diff --git a/commands/edit-image/trans.js b/commands/edit-image/trans.js new file mode 100644 index 00000000..ab2d2518 --- /dev/null +++ b/commands/edit-image/trans.js @@ -0,0 +1,43 @@ +const Command = require('../../framework/Command'); +const { PermissionFlagsBits } = require('discord.js'); +const { createCanvas, loadImage } = require('@napi-rs/canvas'); +const request = require('node-superfetch'); +const path = require('path'); + +module.exports = class TransCommand extends Command { + constructor(client) { + super(client, { + name: 'trans', + aliases: ['transgender'], + group: 'edit-image', + description: 'Draws an image or a user\'s avatar but with a Transgender flag on it.', + throttling: { + usages: 2, + duration: 10 + }, + clientPermissions: [PermissionFlagsBits.AttachFiles], + args: [ + { + key: 'image', + type: 'image-or-avatar', + avatarSize: 512, + default: msg => msg.author.displayAvatarURL({ extension: 'png', size: 512 }) + } + ] + }); + } + + async run(msg, { image }) { + const { body } = await request.get(image); + const data = await loadImage(body); + const transFlag = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'trans.png')); + const canvas = createCanvas(data.width, data.height); + const ctx = canvas.getContext('2d'); + ctx.drawImage(data, 0, 0); + ctx.globalAlpha = 0.5; + ctx.drawImage(transFlag, 0, 0, data.width, data.height); + const attachment = canvas.toBuffer('image/png'); + if (Buffer.byteLength(attachment) > 2.5e+7) return msg.reply('Resulting image was above 25 MB.'); + return msg.say({ files: [{ attachment, name: 'trans.png' }] }); + } +};