Added tolerance option to uncaption, fixed nogif return type
This commit is contained in:
parent
a82ae115f8
commit
ec6fb7de37
4 changed files with 19 additions and 3 deletions
|
@ -16,7 +16,7 @@ class SnapchatCommand extends ImageCommand {
|
||||||
static flags = [{
|
static flags = [{
|
||||||
name: "position",
|
name: "position",
|
||||||
type: "number",
|
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;
|
static requiresText = true;
|
||||||
|
|
|
@ -1,7 +1,19 @@
|
||||||
import ImageCommand from "../../classes/imageCommand.js";
|
import ImageCommand from "../../classes/imageCommand.js";
|
||||||
|
|
||||||
class UncaptionCommand extends ImageCommand {
|
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 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 noImage = "You need to provide an image/GIF to uncaption!";
|
||||||
static command = "uncaption";
|
static command = "uncaption";
|
||||||
|
|
|
@ -13,6 +13,7 @@ Napi::Value Uncaption(const Napi::CallbackInfo &info) {
|
||||||
try {
|
try {
|
||||||
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>>();
|
||||||
|
float tolerance = obj.Has("tolerance") ? obj.Get("tolerance").As<Napi::Number>().FloatValue() : 0.95;
|
||||||
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;
|
||||||
|
@ -37,7 +38,7 @@ Napi::Value Uncaption(const Napi::CallbackInfo &info) {
|
||||||
ssize_t row;
|
ssize_t row;
|
||||||
for (row = 0; row < rows; ++row) {
|
for (row = 0; row < rows; ++row) {
|
||||||
ColorGray color = firstImage.pixelColor(0, row);
|
ColorGray color = firstImage.pixelColor(0, row);
|
||||||
if (color.shade() < 0.95) {
|
if (color.shade() < tolerance) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -155,6 +155,9 @@ class ImageConnection {
|
||||||
case "image/webp":
|
case "image/webp":
|
||||||
type = "webp";
|
type = "webp";
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
type = contentType;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return { buffer: Buffer.from(await req.arrayBuffer()), type };
|
return { buffer: Buffer.from(await req.arrayBuffer()), type };
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue