From f6f88225a5d8cd8d20e826e98556ad47733180ed Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Thu, 2 Jul 2020 17:15:03 -0400 Subject: [PATCH] Resize Command --- README.md | 3 +- commands/edit-image/resize.js | 54 +++++++++++++++++++++++++++++++++++ package.json | 2 +- 3 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 commands/edit-image/resize.js diff --git a/README.md b/README.md index 95e037ec..9c4fbdac 100644 --- a/README.md +++ b/README.md @@ -243,7 +243,7 @@ in the appropriate channel's topic to use it. ## Commands -Total: 514 +Total: 515 ### Utility: @@ -615,6 +615,7 @@ Total: 514 * **police-tape:** Draws police tape over an image or a user's avatar. * **rainbow:** Draws a rainbow over an image or a user's avatar. * **rejected:** Draws a "rejected" stamp over an image or a user's avatar. +* **resize:** Draws an image or a user's avatar resized to the size you want. * **robohash:** Creates a robot based on the text you provide. * **sepia:** Draws an image or a user's avatar in sepia. * **shields-io-badge:** Creates a badge from shields.io. diff --git a/commands/edit-image/resize.js b/commands/edit-image/resize.js new file mode 100644 index 00000000..e0cf39b2 --- /dev/null +++ b/commands/edit-image/resize.js @@ -0,0 +1,54 @@ +const Command = require('../../structures/Command'); +const { createCanvas, loadImage } = require('canvas'); +const request = require('node-superfetch'); + +module.exports = class ResizeCommand extends Command { + constructor(client) { + super(client, { + name: 'resize', + group: 'edit-image', + memberName: 'resize', + description: 'Draws an image or a user\'s avatar resized to the size you want.', + throttling: { + usages: 1, + duration: 10 + }, + clientPermissions: ['ATTACH_FILES'], + args: [ + { + key: 'width', + prompt: 'What do you want the new width of the image to be?', + type: 'integer', + min: 1, + max: 2000 + }, + { + key: 'height', + prompt: 'What do you want the new height of the image to be?', + type: 'integer', + min: 1, + max: 2000 + }, + { + key: 'image', + prompt: 'Which image would you like to edit?', + type: 'image', + default: msg => msg.author.displayAvatarURL({ format: 'png', size: 2048 }) + } + ] + }); + } + + async run(msg, { width, height, image }) { + try { + const { body } = await request.get(image); + const data = await loadImage(body); + const canvas = createCanvas(width, height); + const ctx = canvas.getContext('2d'); + ctx.drawImage(data, 0, 0, width, height); + return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'resize.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 d8a8aa73..5364df7d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "119.1.0", + "version": "119.2.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {