Added uncaption, removed unncecessary log
This commit is contained in:
parent
9f7f4d21ba
commit
073c337d3d
5 changed files with 122 additions and 2 deletions
10
commands/image-editing/uncaption.js
Normal file
10
commands/image-editing/uncaption.js
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
const ImageCommand = require("../../classes/imageCommand.js");
|
||||||
|
|
||||||
|
class UncaptionCommand extends ImageCommand {
|
||||||
|
static description = "Removes the caption from an image";
|
||||||
|
|
||||||
|
static noImage = "you need to provide an image to uncaption!";
|
||||||
|
static command = "uncaption";
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = UncaptionCommand;
|
|
@ -31,6 +31,7 @@
|
||||||
#include "spin.h"
|
#include "spin.h"
|
||||||
#include "tile.h"
|
#include "tile.h"
|
||||||
#include "trump.h"
|
#include "trump.h"
|
||||||
|
#include "uncaption.h"
|
||||||
#include "wall.h"
|
#include "wall.h"
|
||||||
#include "wdt.h"
|
#include "wdt.h"
|
||||||
#include "watermark.h"
|
#include "watermark.h"
|
||||||
|
@ -68,6 +69,7 @@ Napi::Object Init(Napi::Env env, Napi::Object exports)
|
||||||
exports.Set(Napi::String::New(env, "swirl"), Napi::Function::New(env, Swirl));
|
exports.Set(Napi::String::New(env, "swirl"), Napi::Function::New(env, Swirl));
|
||||||
exports.Set(Napi::String::New(env, "tile"), Napi::Function::New(env, Tile));
|
exports.Set(Napi::String::New(env, "tile"), Napi::Function::New(env, Tile));
|
||||||
exports.Set(Napi::String::New(env, "trump"), Napi::Function::New(env, Trump));
|
exports.Set(Napi::String::New(env, "trump"), Napi::Function::New(env, Trump));
|
||||||
|
exports.Set(Napi::String::New(env, "uncaption"), Napi::Function::New(env, Uncaption));
|
||||||
exports.Set(Napi::String::New(env, "wall"), Napi::Function::New(env, Wall));
|
exports.Set(Napi::String::New(env, "wall"), Napi::Function::New(env, Wall));
|
||||||
exports.Set(Napi::String::New(env, "wdt"), Napi::Function::New(env, Wdt));
|
exports.Set(Napi::String::New(env, "wdt"), Napi::Function::New(env, Wdt));
|
||||||
exports.Set(Napi::String::New(env, "watermark"), Napi::Function::New(env, Watermark));
|
exports.Set(Napi::String::New(env, "watermark"), Napi::Function::New(env, Watermark));
|
||||||
|
|
101
natives/uncaption.cc
Normal file
101
natives/uncaption.cc
Normal file
|
@ -0,0 +1,101 @@
|
||||||
|
#include <Magick++.h>
|
||||||
|
#include <napi.h>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <list>
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace Magick;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr auto type_name() noexcept {
|
||||||
|
std::string_view name = "Error: unsupported compiler", prefix, suffix;
|
||||||
|
#ifdef __clang__
|
||||||
|
name = __PRETTY_FUNCTION__;
|
||||||
|
prefix = "auto type_name() [T = ";
|
||||||
|
suffix = "]";
|
||||||
|
#elif defined(__GNUC__)
|
||||||
|
name = __PRETTY_FUNCTION__;
|
||||||
|
prefix = "constexpr auto type_name() [with T = ";
|
||||||
|
suffix = "]";
|
||||||
|
#elif defined(_MSC_VER)
|
||||||
|
name = __FUNCSIG__;
|
||||||
|
prefix = "auto __cdecl type_name<";
|
||||||
|
suffix = ">(void) noexcept";
|
||||||
|
#endif
|
||||||
|
name.remove_prefix(prefix.size());
|
||||||
|
name.remove_suffix(suffix.size());
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
Napi::Value Uncaption(const Napi::CallbackInfo &info) {
|
||||||
|
Napi::Env env = info.Env();
|
||||||
|
|
||||||
|
try {
|
||||||
|
Napi::Object obj = info[0].As<Napi::Object>();
|
||||||
|
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||||
|
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
||||||
|
int delay =
|
||||||
|
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
|
||||||
|
|
||||||
|
Blob blob;
|
||||||
|
|
||||||
|
list<Image> frames;
|
||||||
|
list<Image> coalesced;
|
||||||
|
list<Image> mid;
|
||||||
|
readImages(&frames, path);
|
||||||
|
coalesceImages(&coalesced, frames.begin(), frames.end());
|
||||||
|
|
||||||
|
Image firstImage = coalesced.front();
|
||||||
|
ssize_t columns = firstImage.columns();
|
||||||
|
ssize_t rows = firstImage.rows();
|
||||||
|
//ssize_t column;
|
||||||
|
ssize_t row;
|
||||||
|
//bool found = false;
|
||||||
|
for (row = 0; row < rows; ++row) {
|
||||||
|
//for (column = 0; column < columns; ++column) {
|
||||||
|
ColorGray color = firstImage.pixelColor(0, row);
|
||||||
|
if (color.shade() < 0.9765625) {
|
||||||
|
//found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//}
|
||||||
|
//if (found) break;
|
||||||
|
}
|
||||||
|
Geometry geom = Geometry(columns, row == rows ? rows : rows - row, 0,
|
||||||
|
row == rows ? 0 : row);
|
||||||
|
|
||||||
|
for (Image &image : coalesced) {
|
||||||
|
image.virtualPixelMethod(Magick::TransparentVirtualPixelMethod);
|
||||||
|
image.backgroundColor("none");
|
||||||
|
image.extent(geom);
|
||||||
|
image.magick(type);
|
||||||
|
mid.push_back(image);
|
||||||
|
}
|
||||||
|
|
||||||
|
optimizeTransparency(mid.begin(), mid.end());
|
||||||
|
|
||||||
|
if (type == "gif") {
|
||||||
|
for (Image &image : mid) {
|
||||||
|
image.quantizeDither(false);
|
||||||
|
image.quantize();
|
||||||
|
if (delay != 0) image.animationDelay(delay);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
writeImages(mid.begin(), mid.end(), &blob);
|
||||||
|
|
||||||
|
Napi::Object result = Napi::Object::New(env);
|
||||||
|
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
|
||||||
|
blob.length()));
|
||||||
|
result.Set("type", type);
|
||||||
|
return result;
|
||||||
|
} catch (Napi::Error const &err) {
|
||||||
|
throw err;
|
||||||
|
} catch (std::exception const &err) {
|
||||||
|
throw Napi::Error::New(env, err.what());
|
||||||
|
} catch (...) {
|
||||||
|
throw Napi::Error::New(env, "Unknown error");
|
||||||
|
}
|
||||||
|
}
|
8
natives/uncaption.h
Normal file
8
natives/uncaption.h
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
#ifndef ESMBOT_NATIVES_UNCAPTION_H_
|
||||||
|
#define ESMBOT_NATIVES_UNCAPTION_H_
|
||||||
|
|
||||||
|
#include <napi.h>
|
||||||
|
|
||||||
|
Napi::Value Uncaption(const Napi::CallbackInfo& info);
|
||||||
|
|
||||||
|
#endif
|
3
shard.js
3
shard.js
|
@ -69,8 +69,7 @@ class Shard extends Base {
|
||||||
logger.log("info", "The help docs have been generated.");
|
logger.log("info", "The help docs have been generated.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.env.METRICS !== "") {
|
if (process.env.METRICS !== "" && process.env.METRICS !== undefined) {
|
||||||
logger.log("YES");
|
|
||||||
const httpServer = http.createServer(async (req, res) => {
|
const httpServer = http.createServer(async (req, res) => {
|
||||||
if (req.method !== "GET") {
|
if (req.method !== "GET") {
|
||||||
res.statusCode = 405;
|
res.statusCode = 405;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue