Frame Command

This commit is contained in:
Daniel Odendahl Jr
2018-03-24 15:50:09 +00:00
parent bb6319cd7e
commit a5ab2ee8d2
4 changed files with 48 additions and 1 deletions
+1
View File
@@ -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.
Binary file not shown.

After

Width:  |  Height:  |  Size: 362 KiB

+46
View File
@@ -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!`);
}
}
};
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "70.3.0",
"version": "70.4.0",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {