Small tweaks

This commit is contained in:
Essem 2022-03-09 13:30:18 -06:00
parent 3232e6fc72
commit 5b2b3549b4
No known key found for this signature in database
GPG key ID: 7D497397CC3A2A8C
3 changed files with 37 additions and 36 deletions

View file

@ -1,18 +1,18 @@
import ImageCommand from "../../classes/imageCommand.js"; import ImageCommand from "../../classes/imageCommand.js";
class SpeechbubbleCommand extends ImageCommand { class SpeechBubbleCommand extends ImageCommand {
params = { params = {
water: "./assets/images/speechbubble.png", water: "./assets/images/speechbubble.png",
gravity: "north", gravity: "north",
resize: true, resize: true,
yscale: 0.2, yscale: 0.2,
}; };
static description = "Adds a speech bubble to the image."; static description = "Adds a speech bubble to an image";
static aliases = ["speech","speechbubble"]; static aliases = ["speech", "sb"];
static noImage = "You need to provide an image/GIF to add a speech bubble." static noImage = "You need to provide an image/GIF to add a speech bubble!";
static command = "watermark"; static command = "watermark";
} }
export default SpeechbubbleCommand; export default SpeechBubbleCommand;

View file

@ -14,12 +14,14 @@ Napi::Value Watermark(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 water = obj.Get("water").As<Napi::String>().Utf8Value(); string water = obj.Get("water").As<Napi::String>().Utf8Value();
Magick::GravityType gravity = Magick::GravityType(obj.Get("gravity").As<Napi::Number>().Int64Value()); Magick::GravityType gravity =
Magick::GravityType(obj.Get("gravity").As<Napi::Number>().Int64Value());
bool resize = obj.Has("resize") bool resize = obj.Has("resize")
? obj.Get("resize").As<Napi::Boolean>().Value() ? obj.Get("resize").As<Napi::Boolean>().Value()
: false; : false;
float yscale = obj.Has("yscale") float yscale = obj.Has("yscale")
? obj.Get("yscale").As<Napi::Number>().FloatValue() : false; ? obj.Get("yscale").As<Napi::Number>().FloatValue()
: false;
bool append = obj.Has("append") bool append = obj.Has("append")
? obj.Get("append").As<Napi::Boolean>().Value() ? obj.Get("append").As<Napi::Boolean>().Value()
: false; : false;
@ -45,11 +47,12 @@ Napi::Value Watermark(const Napi::CallbackInfo &info) {
if (resize && append) { if (resize && append) {
string query(to_string(frames.front().baseColumns()) + "x"); string query(to_string(frames.front().baseColumns()) + "x");
watermark.scale(Geometry(query)); watermark.scale(Geometry(query));
} else if (resize&&yscale) { } else if (resize && yscale) {
string query(to_string(frames.front().baseColumns())+"x"+to_string(frames.front().baseRows()*yscale)+"!"); string query(to_string(frames.front().baseColumns()) + "x" +
watermark.resize(Geometry(query)); to_string(frames.front().baseRows() * yscale) + "!");
watermark.resize(Geometry(query));
} else if (resize) { } else if (resize) {
string query("x"+to_string(frames.front().baseRows())); string query("x" + to_string(frames.front().baseRows()));
watermark.scale(Geometry(query)); watermark.scale(Geometry(query));
} }
coalesceImages(&coalesced, frames.begin(), frames.end()); coalesceImages(&coalesced, frames.begin(), frames.end());
@ -65,12 +68,10 @@ Napi::Value Watermark(const Napi::CallbackInfo &info) {
} else if (mc) { } else if (mc) {
image.backgroundColor("white"); image.backgroundColor("white");
image.extent(Geometry(image.columns(), image.rows() + 15)); image.extent(Geometry(image.columns(), image.rows() + 15));
image.composite(watermark, gravity, image.composite(watermark, gravity, Magick::OverCompositeOp);
Magick::OverCompositeOp);
final = image; final = image;
} else { } else {
image.composite(watermark, gravity, image.composite(watermark, gravity, Magick::OverCompositeOp);
Magick::OverCompositeOp);
final = image; final = image;
} }
image.magick(type); image.magick(type);

View file

@ -7,17 +7,17 @@ const nodeRequire = createRequire(import.meta.url);
const magick = nodeRequire(`../build/${process.env.DEBUG && process.env.DEBUG === "true" ? "Debug" : "Release"}/image.node`); const magick = nodeRequire(`../build/${process.env.DEBUG && process.env.DEBUG === "true" ? "Debug" : "Release"}/image.node`);
const enumMap = { const enumMap = {
"forget":0, "forget": 0,
"northwest":1, "northwest": 1,
"north":2, "north": 2,
"northeast":3, "northeast": 3,
"west":4, "west": 4,
"center":5, "center": 5,
"east":6, "east": 6,
"southwest":7, "southwest": 7,
"south":8, "south": 8,
"southeast":9 "southeast": 9
} };
export default function run(object) { export default function run(object) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@ -36,10 +36,10 @@ export default function run(object) {
const fileExtension = object.params.type ? object.params.type.split("/")[1] : "png"; const fileExtension = object.params.type ? object.params.type.split("/")[1] : "png";
promise.then(buf => { promise.then(buf => {
object.params.data = buf; object.params.data = buf;
const objectWithFixedType = Object.assign({}, object.params, {type: fileExtension}); const objectWithFixedType = Object.assign({}, object.params, { type: fileExtension });
if (objectWithFixedType.gravity) { if (objectWithFixedType.gravity) {
if (isNaN(Number(objectWithFixedType.gravity))){ if (isNaN(objectWithFixedType.gravity)) {
objectWithFixedType.gravity=enumMap[objectWithFixedType.gravity]; objectWithFixedType.gravity = enumMap[objectWithFixedType.gravity];
} }
} }
try { try {