diff --git a/README.md b/README.md index c05bcbfa..f5b0a1b1 100644 --- a/README.md +++ b/README.md @@ -222,6 +222,7 @@ served over 10,000 servers with a uniquely devoted fanbase. * **contrast**: Draws an image or a user's avatar but with contrast. * **demotivational-poster**: Draws an image or a user's avatar and the text you specify as a demotivational poster. * **distort**: Draws an image or a user's avatar but distorted. +* **frame**: Draws a frame around an image or a user's avatar. * **glitch**: Draws an image or a user's avatar but glitched. * **greyscale**: Draws an image or a user's avatar in greyscale. * **ifunny**: Draws an image with the iFunny logo. diff --git a/assets/images/frame.png b/assets/images/frame.png new file mode 100644 index 00000000..a024fd7f Binary files /dev/null and b/assets/images/frame.png differ diff --git a/commands/image-edit/frame.js b/commands/image-edit/frame.js new file mode 100644 index 00000000..75b7f2e8 --- /dev/null +++ b/commands/image-edit/frame.js @@ -0,0 +1,46 @@ +const { Command } = require('discord.js-commando'); +const { createCanvas, loadImage } = require('canvas'); +const snekfetch = require('snekfetch'); +const path = require('path'); + +module.exports = class FrameCommand extends Command { + constructor(client) { + super(client, { + name: 'frame', + aliases: ['picture-frame', 'photo-frame'], + group: 'image-edit', + memberName: 'frame', + description: 'Draws a frame around an image or a user\'s avatar.', + throttling: { + usages: 1, + duration: 10 + }, + clientPermissions: ['ATTACH_FILES'], + args: [ + { + key: 'image', + prompt: 'What image would you like to edit?', + type: 'image|avatar', + default: msg => msg.author.displayAvatarURL({ format: 'png', size: 512 }) + } + ] + }); + } + + async run(msg, { image }) { + try { + const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'frame.png')); + const { body } = await snekfetch.get(image); + const data = await loadImage(body); + const canvas = createCanvas(data.width, data.height); + const ctx = canvas.getContext('2d'); + ctx.drawImage(data, 0, 0); + ctx.drawImage(base, 0, 0, data.width, data.height); + const attachment = canvas.toBuffer(); + if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.'); + return msg.say({ files: [{ attachment, name: 'frame.png' }] }); + } catch (err) { + return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } +}; diff --git a/package.json b/package.json index eed24689..ce3d868f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "70.3.0", + "version": "70.4.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {