Add support for string gravity + speechbubble command
This commit is contained in:
parent
f3f23ddbf2
commit
b17611917f
4 changed files with 37 additions and 42 deletions
BIN
assets/images/speechbubble.png
Normal file
BIN
assets/images/speechbubble.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 32 KiB |
18
commands/image-editing/speechbubble.js
Normal file
18
commands/image-editing/speechbubble.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
import ImageCommand from "../../classes/imageCommand.js";
|
||||
|
||||
class SpeechbubbleCommand extends ImageCommand {
|
||||
params = {
|
||||
water: "./assets/images/speechbubble.png",
|
||||
gravity: "north",
|
||||
resize: true,
|
||||
yscale: 0.2,
|
||||
};
|
||||
|
||||
static description = "Adds a speech bubble to the image.";
|
||||
static aliases = ["speech","speechbubble"];
|
||||
|
||||
static noImage = "You need to provide an image/GIF to add a speech bubble."
|
||||
static command = "watermark";
|
||||
}
|
||||
|
||||
export default SpeechbubbleCommand;
|
|
@ -7,47 +7,6 @@
|
|||
using namespace std;
|
||||
using namespace Magick;
|
||||
|
||||
Magick::GravityType NapiToGravity(const Napi::Value gravity) {
|
||||
Magick::GravityType g = Magick::GravityType();
|
||||
if (gravity.IsNumber()) {
|
||||
return Magick::GravityType(gravity.As<Napi::Number>().Int64Value());
|
||||
}else if (gravity.IsString()) {
|
||||
string grav = gravity.As<Napi::String>().Utf8Value();
|
||||
if (grav == "northwest") {
|
||||
g = Magick::NorthWestGravity;
|
||||
} else if (grav == "north") {
|
||||
g = Magick::NorthGravity;
|
||||
} else if (grav == "northeast") {
|
||||
g = Magick::NorthEastGravity;
|
||||
} else if (grav == "west") {
|
||||
g = Magick::WestGravity;
|
||||
} else if (grav == "center") {
|
||||
g = Magick::CenterGravity;
|
||||
} else if (grav == "east") {
|
||||
g = Magick::EastGravity;
|
||||
} else if (grav == "southwest") {
|
||||
g = Magick::SouthWestGravity;
|
||||
} else if (grav == "south") {
|
||||
g = Magick::SouthGravity;
|
||||
} else if (grav == "southeast") {
|
||||
g = Magick::SouthEastGravity;
|
||||
} else if (grav == "forget") {
|
||||
g = Magick::ForgetGravity;
|
||||
} else if (grav == "north_east") {
|
||||
g = Magick::NorthEastGravity;
|
||||
} else if (grav == "north_west") {
|
||||
g = Magick::NorthWestGravity;
|
||||
} else if (grav == "south_east") {
|
||||
g = Magick::SouthEastGravity;
|
||||
} else if (grav == "south_west") {
|
||||
g = Magick::SouthWestGravity;
|
||||
} else {
|
||||
g = Magick::CenterGravity;
|
||||
}
|
||||
}
|
||||
return g;
|
||||
}
|
||||
|
||||
Napi::Value Watermark(const Napi::CallbackInfo &info) {
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
|
@ -55,7 +14,7 @@ Napi::Value Watermark(const Napi::CallbackInfo &info) {
|
|||
Napi::Object obj = info[0].As<Napi::Object>();
|
||||
Napi::Buffer<char> data = obj.Get("data").As<Napi::Buffer<char>>();
|
||||
string water = obj.Get("water").As<Napi::String>().Utf8Value();
|
||||
Magick::GravityType gravity = NapiToGravity(obj.Get("gravity"));
|
||||
Magick::GravityType gravity = Magick::GravityType(obj.Get("gravity").As<Napi::Number>().Int64Value());
|
||||
bool resize = obj.Has("resize")
|
||||
? obj.Get("resize").As<Napi::Boolean>().Value()
|
||||
: false;
|
||||
|
|
|
@ -6,6 +6,19 @@ const nodeRequire = createRequire(import.meta.url);
|
|||
|
||||
const magick = nodeRequire(`../build/${process.env.DEBUG && process.env.DEBUG === "true" ? "Debug" : "Release"}/image.node`);
|
||||
|
||||
const enumMap = {
|
||||
"forget":0,
|
||||
"northwest":1,
|
||||
"north":2,
|
||||
"northeast":3,
|
||||
"west":4,
|
||||
"center":5,
|
||||
"east":6,
|
||||
"southwest":7,
|
||||
"south":8,
|
||||
"southeast":9
|
||||
}
|
||||
|
||||
export default function run(object) {
|
||||
return new Promise((resolve, reject) => {
|
||||
// If the image has a path, it must also have a type
|
||||
|
@ -24,6 +37,11 @@ export default function run(object) {
|
|||
promise.then(buf => {
|
||||
object.params.data = buf;
|
||||
const objectWithFixedType = Object.assign({}, object.params, {type: fileExtension});
|
||||
if (objectWithFixedType.gravity) {
|
||||
if (isNaN(Number(objectWithFixedType.gravity))){
|
||||
objectWithFixedType.gravity=enumMap[objectWithFixedType.gravity];
|
||||
}
|
||||
}
|
||||
try {
|
||||
const result = magick[object.cmd](objectWithFixedType);
|
||||
const returnObject = {
|
||||
|
|
Loading…
Reference in a new issue