diff --git a/commands/image-editing/snapchat.js b/commands/image-editing/snapchat.js index 0147699..60f83a5 100644 --- a/commands/image-editing/snapchat.js +++ b/commands/image-editing/snapchat.js @@ -16,7 +16,7 @@ class SnapchatCommand extends ImageCommand { static flags = [{ name: "position", type: "number", - description: "Set the position of the caption as a decimal (0.0 is top, 1.0 is bottom)" + description: "Set the position of the caption as a decimal (0.0 is top, 1.0 is bottom, default is 0.5)" }]; static requiresText = true; diff --git a/commands/image-editing/uncaption.js b/commands/image-editing/uncaption.js index 9ad8d9a..a979673 100644 --- a/commands/image-editing/uncaption.js +++ b/commands/image-editing/uncaption.js @@ -1,7 +1,19 @@ import ImageCommand from "../../classes/imageCommand.js"; class UncaptionCommand extends ImageCommand { + params() { + const tolerance = parseFloat(this.specialArgs.tolerance); + return { + tolerance: isNaN(tolerance) ? 0.95 : tolerance + }; + } + static description = "Removes the caption from an image"; + static flags = [{ + name: "tolerance", + type: "number", + description: "Set the shade tolerance for the caption detection (0.0 is highest, 1.0 is lowest, default is 0.95)" + }]; static noImage = "You need to provide an image/GIF to uncaption!"; static command = "uncaption"; diff --git a/natives/uncaption.cc b/natives/uncaption.cc index 4a30b90..4ba6597 100644 --- a/natives/uncaption.cc +++ b/natives/uncaption.cc @@ -13,6 +13,7 @@ Napi::Value Uncaption(const Napi::CallbackInfo &info) { try { Napi::Object obj = info[0].As(); Napi::Buffer data = obj.Get("data").As>(); + float tolerance = obj.Has("tolerance") ? obj.Get("tolerance").As().FloatValue() : 0.95; string type = obj.Get("type").As().Utf8Value(); int delay = obj.Has("delay") ? obj.Get("delay").As().Int32Value() : 0; @@ -37,7 +38,7 @@ Napi::Value Uncaption(const Napi::CallbackInfo &info) { ssize_t row; for (row = 0; row < rows; ++row) { ColorGray color = firstImage.pixelColor(0, row); - if (color.shade() < 0.95) { + if (color.shade() < tolerance) { break; } } @@ -74,4 +75,4 @@ Napi::Value Uncaption(const Napi::CallbackInfo &info) { } catch (...) { throw Napi::Error::New(env, "Unknown error"); } -} \ No newline at end of file +} diff --git a/utils/imageConnection.js b/utils/imageConnection.js index 49f98cc..ce2bdc0 100644 --- a/utils/imageConnection.js +++ b/utils/imageConnection.js @@ -155,6 +155,9 @@ class ImageConnection { case "image/webp": type = "webp"; break; + default: + type = contentType; + break; } return { buffer: Buffer.from(await req.arrayBuffer()), type }; }