forked from Supositware/Haha-Yes
various image manipulation command
This commit is contained in:
parent
fc577e814a
commit
b424b0f69d
4 changed files with 213 additions and 0 deletions
53
commands/images/autocrop.js
Normal file
53
commands/images/autocrop.js
Normal 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;
|
51
commands/images/jpegify.js
Normal file
51
commands/images/jpegify.js
Normal 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
52
commands/images/mirror.js
Normal 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
57
commands/images/rotate.js
Normal 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;
|
Loading…
Reference in a new issue