diff --git a/assets/images/speechbubble.png b/assets/images/speechbubble.png new file mode 100644 index 0000000..4ca27d2 Binary files /dev/null and b/assets/images/speechbubble.png differ diff --git a/commands/image-editing/speechbubble.js b/commands/image-editing/speechbubble.js new file mode 100644 index 0000000..16a1298 --- /dev/null +++ b/commands/image-editing/speechbubble.js @@ -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; diff --git a/natives/watermark.cc b/natives/watermark.cc index 93649d3..ed78c3f 100644 --- a/natives/watermark.cc +++ b/natives/watermark.cc @@ -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().Int64Value()); - }else if (gravity.IsString()) { - string grav = gravity.As().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::Buffer data = obj.Get("data").As>(); string water = obj.Get("water").As().Utf8Value(); - Magick::GravityType gravity = NapiToGravity(obj.Get("gravity")); + Magick::GravityType gravity = Magick::GravityType(obj.Get("gravity").As().Int64Value()); bool resize = obj.Has("resize") ? obj.Get("resize").As().Value() : false; diff --git a/utils/image-runner.js b/utils/image-runner.js index 6679636..197f3f7 100644 --- a/utils/image-runner.js +++ b/utils/image-runner.js @@ -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 = {