various image manipulation command

This commit is contained in:
loicbersier 2019-10-13 16:54:07 +02:00
parent fc577e814a
commit b424b0f69d
4 changed files with 213 additions and 0 deletions

View file

@ -0,0 +1,53 @@
const { Command } = require('discord-akairo');
const jimp = require('jimp');
const os = require('os');
class autocropCommand extends Command {
constructor() {
super('autocrop', {
aliases: ['autocrop', 'crop'],
category: 'images',
args: [
{
id: 'link',
type: 'string',
}
],
description: {
content: 'autocrop image border of the same color',
usage: '[link to image]',
examples: ['']
}
});
}
async exec(message, args) {
let output = `${os.tmpdir()}/cropped${message.id}.jpg`;
let Attachment = (message.attachments).array();
let url = args.link;
// Get attachment link
if (Attachment[0] && !args.link) {
url = Attachment[0].url;
}
jimp.read({
url: url
})
.then(image => {
return image
.autocrop()
.write(output);
})
.then(() => {
return message.channel.send({files: [output]});
});
}
}
module.exports = autocropCommand;

View file

@ -0,0 +1,51 @@
const { Command } = require('discord-akairo');
const jimp = require('jimp');
const os = require('os');
class jpegifyCommand extends Command {
constructor() {
super('jpegify', {
aliases: ['jpegify'],
category: 'images',
args: [
{
id: 'link',
type: 'string',
}
],
description: {
content: 'jpegify your image',
usage: '[link to image]',
examples: ['']
}
});
}
async exec(message, args) {
let output = `${os.tmpdir()}/jpegified${message.id}.jpg`;
let Attachment = (message.attachments).array();
let url = args.link;
// Get attachment link
if (Attachment[0] && !args.link) {
url = Attachment[0].url;
}
jimp.read({
url: url
})
.then(image => {
return image
.quality(1)
.write(output);
})
.then(() => {
return message.channel.send({files: [output]});
});
}
}
module.exports = jpegifyCommand;

52
commands/images/mirror.js Normal file
View file

@ -0,0 +1,52 @@
const { Command } = require('discord-akairo');
const jimp = require('jimp');
const os = require('os');
class mirrorCommand extends Command {
constructor() {
super('mirror', {
aliases: ['mirror', 'flip'],
category: 'images',
args: [
{
id: 'link',
type: 'string',
}
],
description: {
content: 'mirror the image.',
usage: '[link to image]',
examples: ['']
}
});
}
async exec(message, args) {
let output = `${os.tmpdir()}/mirrored${message.id}.jpg`;
let Attachment = (message.attachments).array();
let url = args.link;
// Get attachment link
if (Attachment[0] && !args.link) {
url = Attachment[0].url;
}
jimp.read({
url: url
})
.then(image => {
return image
.mirror(true, false)
.write(output);
})
.then(() => {
return message.channel.send({files: [output]});
});
}
}
module.exports = mirrorCommand;

57
commands/images/rotate.js Normal file
View file

@ -0,0 +1,57 @@
const { Command } = require('discord-akairo');
const jimp = require('jimp');
const os = require('os');
class rotateCommand extends Command {
constructor() {
super('rotate', {
aliases: ['rotate'],
category: 'images',
args: [
{
id: 'link',
type: 'string',
},
{
id: 'rotate',
type: 'integer',
}
],
description: {
content: 'Make your vid shit quality.',
usage: '[link to image] [angle of rotation]',
examples: ['']
}
});
}
async exec(message, args) {
let output = `${os.tmpdir()}/rotated${message.id}.jpg`;
let Attachment = (message.attachments).array();
let url = args.link;
// Get attachment link
if (Attachment[0] && !args.link) {
url = Attachment[0].url;
}
jimp.read({
url: url
})
.then(image => {
return image
.rotate(args.rotate)
.write(output);
})
.then(() => {
return message.channel.send({files: [output]});
});
}
}
module.exports = rotateCommand;