diff --git a/commands/image-edit/pixelize.js b/commands/image-edit/pixelize.js index 6f0e382f..aebc33fd 100644 --- a/commands/image-edit/pixelize.js +++ b/commands/image-edit/pixelize.js @@ -6,6 +6,7 @@ module.exports = class PixelizeCommand extends Command { constructor(client) { super(client, { name: 'pixelize', + aliases: ['pixel'], group: 'image-edit', memberName: 'pixelize', description: 'Draws an image or a user\'s avatar pixelized.', @@ -28,15 +29,17 @@ module.exports = class PixelizeCommand extends Command { async run(msg, { image }) { try { const { body } = await request.get(image); - const avatar = await loadImage(body); - const canvas = createCanvas(512, 512); + const data = await loadImage(body); + const canvas = createCanvas(data.width, data.height); const ctx = canvas.getContext('2d'); ctx.imageSmoothingEnabled = false; - const width = canvas.width * 0.25; - const height = canvas.height * 0.25; - ctx.drawImage(avatar, 0, 0, width, height); + const width = canvas.width * 0.15; + const height = canvas.height * 0.15; + ctx.drawImage(data, 0, 0, width, height); ctx.drawImage(canvas, 0, 0, width, height, 0, 0, canvas.width, canvas.height); - return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'pixelize.png' }] }); + 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: 'pixelize.png' }] }); } catch (err) { return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); } diff --git a/commands/image-edit/rainbow.js b/commands/image-edit/rainbow.js index 0e5cda5f..11ea1d26 100644 --- a/commands/image-edit/rainbow.js +++ b/commands/image-edit/rainbow.js @@ -31,12 +31,14 @@ module.exports = class RainbowCommand extends Command { try { const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'rainbow.png')); const { body } = await request.get(image); - const avatar = await loadImage(body); - const canvas = createCanvas(avatar.width, avatar.height); + const data = await loadImage(body); + const canvas = createCanvas(data.width, data.height); const ctx = canvas.getContext('2d'); - ctx.drawImage(avatar, 0, 0); - ctx.drawImage(base, 0, 0, avatar.width, avatar.height); - return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'rainbow.png' }] }); + 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: 'rainbow.png' }] }); } catch (err) { return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); }