mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-12 08:14:47 +02:00
More Stoof
This commit is contained in:
@@ -32,12 +32,12 @@ module.exports = class InvertCommand extends Command {
|
||||
size: 512
|
||||
});
|
||||
try {
|
||||
const canvas = createCanvas(512, 512);
|
||||
const ctx = canvas.getContext('2d');
|
||||
const { body } = await snekfetch.get(avatarURL);
|
||||
const avatar = await loadImage(body);
|
||||
ctx.drawImage(avatar, 0, 0, 512, 512);
|
||||
const imgData = ctx.getImageData(0, 0, 512, 512);
|
||||
const canvas = createCanvas(avatar.width, avatar.height);
|
||||
const ctx = canvas.getContext('2d');
|
||||
ctx.drawImage(avatar, 0, 0);
|
||||
const imgData = ctx.getImageData(0, 0, avatar.width, avatar.height);
|
||||
const { data } = imgData;
|
||||
for (let i = 0; i < data.length; i += 4) {
|
||||
data[i] = 255 - data[i];
|
||||
@@ -45,7 +45,10 @@ module.exports = class InvertCommand extends Command {
|
||||
data[i + 2] = 255 - data[i + 2];
|
||||
}
|
||||
ctx.putImageData(imgData, 0, 0);
|
||||
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'invert.png' }] });
|
||||
return msg.say({ files: [{
|
||||
attachment: canvas.toBuffer(),
|
||||
name: 'invert.png'
|
||||
}] });
|
||||
} catch (err) {
|
||||
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user