Added support for GIFs in image commands, added caption
This commit is contained in:
parent
d97496ef25
commit
4fb8eb4989
5 changed files with 39 additions and 3 deletions
BIN
assets/caption.otf
Normal file
BIN
assets/caption.otf
Normal file
Binary file not shown.
35
commands/caption.js
Normal file
35
commands/caption.js
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
const fs = require("fs");
|
||||||
|
const gm = require("gm").subClass({
|
||||||
|
imageMagick: true
|
||||||
|
});
|
||||||
|
const gmToBuffer = require("../utils/gmbuffer.js");
|
||||||
|
|
||||||
|
exports.run = async (message, args) => {
|
||||||
|
const image = await require("../utils/imagedetect.js")(message);
|
||||||
|
if (image === undefined) return `${message.author.mention}, you need to provide an image/GIF to add a caption!`;
|
||||||
|
const path = `/tmp/${Math.random().toString(36).substring(2, 15)}.${image.type}`;
|
||||||
|
const processMessage = await message.channel.createMessage("<a:processing:479351417102925854> Processing... This might take a while");
|
||||||
|
require("util").promisify(fs.writeFile)(path, image.data);
|
||||||
|
gm(image.data).size(async (error, size) => {
|
||||||
|
if (error) throw error;
|
||||||
|
const command = gm().out("-size", `${size.width}x`).background("white").fill("black").font("./assets/caption.otf", size.width / 10).gravity("Center").out(`caption:${args.join(" ")}`);
|
||||||
|
const output = await gmToBuffer(command, "png");
|
||||||
|
gm(output).size(async (error, size2) => {
|
||||||
|
if (error) throw error;
|
||||||
|
gm(output).gravity("Center").trim().out("+repage").extent(size.width, size2.height + (size.width / 10)).stream(async (error, output2) => {
|
||||||
|
if (error) throw error;
|
||||||
|
const command3 = gm(output2).out("-alpha", "set").background("none").out("(").out(path).out("-coalesce").out(")").out("-set", "page", "%[fx:u.w]x%[fx:u.h+v.h]+%[fx:t?(u.w-v.w)/2:0]+%[fx:t?u.h:0]").out("-coalesce").out("null:").out("-insert", 1).out("-layers", "composite").out("-loop", "0");
|
||||||
|
const outputFinal = await gmToBuffer(command3, image.type);
|
||||||
|
await processMessage.delete();
|
||||||
|
return message.channel.createMessage("", {
|
||||||
|
file: outputFinal,
|
||||||
|
name: `caption.${image.type}`
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.aliases = ["gifc", "gcaption", "ifcaption", "ifunnycaption"];
|
||||||
|
exports.category = 5;
|
||||||
|
exports.help = "Adds a caption to an image/GIF";
|
|
@ -4,6 +4,7 @@ exports.run = async (message, args) => {
|
||||||
message.channel.sendTyping();
|
message.channel.sendTyping();
|
||||||
const image = await require("../utils/imagedetect.js")(message);
|
const image = await require("../utils/imagedetect.js")(message);
|
||||||
if (image === undefined) return `${message.author.mention}, you need to provide an image to generate a meme!`;
|
if (image === undefined) return `${message.author.mention}, you need to provide an image to generate a meme!`;
|
||||||
|
if (image.type === "gif") return `${message.author.mention}, this command doesn't work with GIFs!`;
|
||||||
if (args.length === 0) return `${message.author.mention}, you need to provide some text to generate a meme!`;
|
if (args.length === 0) return `${message.author.mention}, you need to provide some text to generate a meme!`;
|
||||||
const [topText, bottomText] = args.join(" ").split(",").map(elem => elem.trim());
|
const [topText, bottomText] = args.join(" ").split(",").map(elem => elem.trim());
|
||||||
const child = spawn("./utils/meme.sh", [topText.toUpperCase().replace(/\\/g, "\\\\"), bottomText ? bottomText.toUpperCase().replace(/\\/g, "\\\\") : ""]);
|
const child = spawn("./utils/meme.sh", [topText.toUpperCase().replace(/\\/g, "\\\\"), bottomText ? bottomText.toUpperCase().replace(/\\/g, "\\\\") : ""]);
|
||||||
|
|
|
@ -7,7 +7,7 @@ ${process.env.NODE_ENV === "development" ? "\n**You are currently using esmBot D
|
||||||
|
|
||||||
Default prefix is \`&\`.
|
Default prefix is \`&\`.
|
||||||
|
|
||||||
> Tip: Use Ctrl+F to find the command you want!
|
> Tip: You can get more info about a command by using \`help [command]\`.
|
||||||
|
|
||||||
## Table of Contents
|
## Table of Contents
|
||||||
+ [**General**](#💻-general)
|
+ [**General**](#💻-general)
|
||||||
|
@ -25,7 +25,7 @@ module.exports = async (output) => {
|
||||||
moderation: ["## 🔨 Moderation"],
|
moderation: ["## 🔨 Moderation"],
|
||||||
tags: ["## 🏷️ Tags"],
|
tags: ["## 🏷️ Tags"],
|
||||||
fun: ["## 👌 Fun"],
|
fun: ["## 👌 Fun"],
|
||||||
images: ["## 🖼️ Image Editing", "> These commands support the PNG, JPEG, and WEBP formats."],
|
images: ["## 🖼️ Image Editing", "> These commands support the PNG, JPEG, WEBP, and GIF formats. (GIF support is currently experimental)"],
|
||||||
soundboard: ["## 🔊 Soundboard"]
|
soundboard: ["## 🔊 Soundboard"]
|
||||||
};
|
};
|
||||||
for (const command of commands) {
|
for (const command of commands) {
|
||||||
|
|
|
@ -11,7 +11,7 @@ const typeCheck = async (image) => {
|
||||||
// get the file type
|
// get the file type
|
||||||
const imageType = fileType(imageBuffer);
|
const imageType = fileType(imageBuffer);
|
||||||
// check if the file is a jpeg, png, or webp
|
// check if the file is a jpeg, png, or webp
|
||||||
if (imageType && ["image/jpeg", "image/png", "image/webp"].includes(imageType.mime)) {
|
if (imageType && ["image/jpeg", "image/png", "image/webp", "image/gif"].includes(imageType.mime)) {
|
||||||
// if it is, then return the url with the file type
|
// if it is, then return the url with the file type
|
||||||
return {
|
return {
|
||||||
type: imageType.ext,
|
type: imageType.ext,
|
||||||
|
|
Loading…
Reference in a new issue