mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Motion Blur Command
This commit is contained in:
@@ -261,7 +261,7 @@ in the appropriate channel's topic to use it.
|
||||
|
||||
## Commands
|
||||
|
||||
Total: 585
|
||||
Total: 586
|
||||
|
||||
### Utility:
|
||||
|
||||
@@ -682,6 +682,7 @@ Total: 585
|
||||
* **liquid-rescale:** Draws an image or a user's avatar but with liquid rescale from ImageMagick.
|
||||
* **minecraft-skin:** Sends the Minecraft skin for a user.
|
||||
* **mirror:** Draws an image or a user's avatar but mirrored on the X/Y axis (or both).
|
||||
* **motion-blur:** Draws an image or a user's avatar with motion blur.
|
||||
* **needs-more-jpeg:** Draws an image or a user's avatar as a low quality JPEG.
|
||||
* **newspaper:** Creates a fake newspaper with the headline and body of your choice.
|
||||
* **noise:** Draws an image or a user's avatar but with noise.
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const { createCanvas, loadImage } = require('canvas');
|
||||
const request = require('node-superfetch');
|
||||
const { motionBlur } = require('../../util/Canvas');
|
||||
|
||||
module.exports = class MotionBlurCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'motion-blur',
|
||||
aliases: ['m-blur', 'motion'],
|
||||
group: 'edit-image',
|
||||
memberName: 'motion-blur',
|
||||
description: 'Draws an image or a user\'s avatar with motion blur.',
|
||||
throttling: {
|
||||
usages: 1,
|
||||
duration: 10
|
||||
},
|
||||
clientPermissions: ['ATTACH_FILES'],
|
||||
args: [
|
||||
{
|
||||
key: 'image',
|
||||
prompt: 'What image would you like to edit?',
|
||||
type: 'image',
|
||||
default: msg => msg.author.displayAvatarURL({ format: 'png', size: 512 })
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg, { image }) {
|
||||
try {
|
||||
const { body } = await request.get(image);
|
||||
const data = await loadImage(body);
|
||||
const canvas = createCanvas(data.width, data.height);
|
||||
const ctx = canvas.getContext('2d');
|
||||
motionBlur(ctx, data, 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: 'motion-blur.png' }] });
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
};
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiao",
|
||||
"version": "128.0.2",
|
||||
"version": "128.1.0",
|
||||
"description": "Your personal server companion.",
|
||||
"main": "Xiao.js",
|
||||
"scripts": {
|
||||
|
||||
@@ -125,6 +125,13 @@ module.exports = class CanvasUtil {
|
||||
return ctx;
|
||||
}
|
||||
|
||||
static motionBlur(ctx, image, x, y, width, height) {
|
||||
ctx.globalAlpha = 0.1;
|
||||
for (let i = 0; i < 10; ++i) ctx.drawImage(image, x, y + i, width, height);
|
||||
ctx.globalAlpha = 1;
|
||||
return ctx;
|
||||
}
|
||||
|
||||
static hasAlpha(image) {
|
||||
const canvas = createCanvas(image.width, image.height);
|
||||
const ctx = canvas.getContext('2d');
|
||||
@@ -148,6 +155,7 @@ module.exports = class CanvasUtil {
|
||||
ctx.fillRect(x, y, width, height);
|
||||
ctx.fillStyle = fillStyle;
|
||||
ctx.globalAlpha = globalAlpha;
|
||||
return ctx;
|
||||
}
|
||||
|
||||
static shortenText(ctx, text, maxWidth) {
|
||||
|
||||
Reference in New Issue
Block a user