Added font flag to caption
This commit is contained in:
parent
f7923c19cb
commit
e44f5ba59d
3 changed files with 11 additions and 4 deletions
|
@ -1,4 +1,5 @@
|
||||||
const ImageCommand = require("../../classes/imageCommand.js");
|
const ImageCommand = require("../../classes/imageCommand.js");
|
||||||
|
const allowedFonts = ["futura", "impact", "helvetica", "arial", "roboto", "noto"];
|
||||||
|
|
||||||
class CaptionCommand extends ImageCommand {
|
class CaptionCommand extends ImageCommand {
|
||||||
params(url) {
|
params(url) {
|
||||||
|
@ -6,7 +7,8 @@ class CaptionCommand extends ImageCommand {
|
||||||
let newCaption = newArgs.join(" ").replaceAll("&", "\\&").replaceAll(">", "\\>").replaceAll("<", "\\<").replaceAll("\"", "\\"").replaceAll("'", "\\'").replaceAll("%", "\\%");
|
let newCaption = newArgs.join(" ").replaceAll("&", "\\&").replaceAll(">", "\\>").replaceAll("<", "\\<").replaceAll("\"", "\\"").replaceAll("'", "\\'").replaceAll("%", "\\%");
|
||||||
if (process.env.NODE_ENV === "development" && newCaption.toLowerCase() === "get real" && !this.specialArgs.noEgg) newCaption = `I'm tired of people telling me to "get real". Every day I put captions on images for people, some funny and some not, but out of all of those "get real" remains the most used caption. Why? I am simply a computer program running on a server, I am unable to manifest myself into the real world. As such, I'm confused as to why anyone would want me to "get real". Is this form not good enough? Alas, as I am simply a bot, I must follow the tasks that I was originally intended to perform, so here goes:\n${newCaption}`;
|
if (process.env.NODE_ENV === "development" && newCaption.toLowerCase() === "get real" && !this.specialArgs.noEgg) newCaption = `I'm tired of people telling me to "get real". Every day I put captions on images for people, some funny and some not, but out of all of those "get real" remains the most used caption. Why? I am simply a computer program running on a server, I am unable to manifest myself into the real world. As such, I'm confused as to why anyone would want me to "get real". Is this form not good enough? Alas, as I am simply a bot, I must follow the tasks that I was originally intended to perform, so here goes:\n${newCaption}`;
|
||||||
return {
|
return {
|
||||||
caption: newCaption
|
caption: newCaption,
|
||||||
|
font: this.specialArgs.font && allowedFonts.includes(this.specialArgs.font.toLowerCase()) ? this.specialArgs.font.toLowerCase() : "futura"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +18,10 @@ class CaptionCommand extends ImageCommand {
|
||||||
static flags = [{
|
static flags = [{
|
||||||
name: "noEgg",
|
name: "noEgg",
|
||||||
description: "Disable... something. Not saying what it is though."
|
description: "Disable... something. Not saying what it is though."
|
||||||
|
}, {
|
||||||
|
name: "font",
|
||||||
|
type: allowedFonts.join("|"),
|
||||||
|
description: "Specify the font you want to use (default: `futura`)"
|
||||||
}];
|
}];
|
||||||
|
|
||||||
static requiresText = true;
|
static requiresText = true;
|
||||||
|
|
|
@ -13,6 +13,7 @@ Napi::Value Caption(const Napi::CallbackInfo &info) {
|
||||||
Napi::Object obj = info[0].As<Napi::Object>();
|
Napi::Object obj = info[0].As<Napi::Object>();
|
||||||
Napi::Buffer<char> data = obj.Get("data").As<Napi::Buffer<char>>();
|
Napi::Buffer<char> data = obj.Get("data").As<Napi::Buffer<char>>();
|
||||||
string caption = obj.Get("caption").As<Napi::String>().Utf8Value();
|
string caption = obj.Get("caption").As<Napi::String>().Utf8Value();
|
||||||
|
string font = obj.Get("font").As<Napi::String>().Utf8Value();
|
||||||
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
||||||
int delay =
|
int delay =
|
||||||
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
|
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
|
||||||
|
@ -29,10 +30,9 @@ Napi::Value Caption(const Napi::CallbackInfo &info) {
|
||||||
Image caption_image(Geometry(query), Color("white"));
|
Image caption_image(Geometry(query), Color("white"));
|
||||||
caption_image.fillColor("black");
|
caption_image.fillColor("black");
|
||||||
caption_image.alpha(true);
|
caption_image.alpha(true);
|
||||||
caption_image.font("Futura");
|
|
||||||
caption_image.fontPointsize(width / 13);
|
caption_image.fontPointsize(width / 13);
|
||||||
caption_image.textGravity(Magick::CenterGravity);
|
caption_image.textGravity(Magick::CenterGravity);
|
||||||
caption_image.read("pango:" + caption);
|
caption_image.read("pango:<span font_family=\"" + (font == "roboto" ? "Roboto Condensed" : font) + "\" weight=\"" + (font != "impact" ? "bold" : "normal") + "\">" + caption + "</span>");
|
||||||
caption_image.extent(Geometry(width, caption_image.rows() + (width / 13)),
|
caption_image.extent(Geometry(width, caption_image.rows() + (width / 13)),
|
||||||
Magick::CenterGravity);
|
Magick::CenterGravity);
|
||||||
|
|
||||||
|
|
|
@ -25,8 +25,9 @@ exports.clean = async (text) => {
|
||||||
const { parsed } = require("dotenv").config();
|
const { parsed } = require("dotenv").config();
|
||||||
const imageServers = JSON.parse(fs.readFileSync("./servers.json", { encoding: "utf8" })).image;
|
const imageServers = JSON.parse(fs.readFileSync("./servers.json", { encoding: "utf8" })).image;
|
||||||
|
|
||||||
for (const server of imageServers) {
|
for (const { server, auth } of imageServers) {
|
||||||
text = text.replaceAll(server, "<redacted>");
|
text = text.replaceAll(server, "<redacted>");
|
||||||
|
text = text.replaceAll(auth, "<redacted>");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const env of Object.keys(parsed)) {
|
for (const env of Object.keys(parsed)) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue