mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Make squish use imagemagick
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const { createCanvas, loadImage } = require('canvas');
|
||||
const gm = require('gm').subClass({ imageMagick: true });
|
||||
const request = require('node-superfetch');
|
||||
|
||||
module.exports = class SquishCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'squish',
|
||||
aliases: ['stretch'],
|
||||
aliases: ['stretch', 'flatten', 'flat'],
|
||||
group: 'edit-image',
|
||||
memberName: 'squish',
|
||||
description: 'Draws an image or a user\'s avatar but squished across the X or Y axis.',
|
||||
@@ -34,19 +34,30 @@ module.exports = class SquishCommand extends Command {
|
||||
}
|
||||
|
||||
async run(msg, { axis, image }) {
|
||||
const flipX = axis === 'x';
|
||||
const flipY = axis === 'y';
|
||||
let command;
|
||||
if (axis === 'x') command = '15%x100%';
|
||||
if (axis === 'y') command = '100%x15%';
|
||||
try {
|
||||
const { body } = await request.get(image);
|
||||
const data = await loadImage(body);
|
||||
const canvas = createCanvas(flipX ? data.width / 2 : data.width, flipY ? data.height / 2 : data.height);
|
||||
const ctx = canvas.getContext('2d');
|
||||
ctx.drawImage(data, 0, 0, canvas.width, canvas.height);
|
||||
const attachment = canvas.toBuffer();
|
||||
const magik = gm(body);
|
||||
magik.out('-liquid-rescale');
|
||||
magik.out(command);
|
||||
magik.setFormat('png');
|
||||
const attachment = await this.toBuffer(magik);
|
||||
if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
|
||||
return msg.say({ files: [{ attachment, name: 'squish.png' }] });
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
|
||||
toBuffer(magik) {
|
||||
return new Promise((res, rej) => {
|
||||
magik.toBuffer((err, buffer) => {
|
||||
if (err) return rej(err);
|
||||
return res(buffer);
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiao",
|
||||
"version": "117.8.0",
|
||||
"version": "117.8.1",
|
||||
"description": "Your personal server companion.",
|
||||
"main": "Xiao.js",
|
||||
"scripts": {
|
||||
|
||||
Reference in New Issue
Block a user