1
0
Fork 0

various image manipulation command

akairo
loicbersier 5 years ago
parent fc577e814a
commit b424b0f69d

@ -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;

@ -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;

@ -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;

@ -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;
Loading…
Cancel
Save