Added reddit, catch any errors in native functions
This commit is contained in:
parent
6cecd4b9d6
commit
b7fe04c82b
41 changed files with 1630 additions and 1386 deletions
|
@ -46,6 +46,7 @@ WORKDIR /home/esmBot/.internal
|
||||||
COPY ./assets/caption.otf /usr/share/fonts/caption.otf
|
COPY ./assets/caption.otf /usr/share/fonts/caption.otf
|
||||||
COPY ./assets/caption2.ttf /usr/share/fonts/caption2.ttf
|
COPY ./assets/caption2.ttf /usr/share/fonts/caption2.ttf
|
||||||
COPY ./assets/hbc.ttf /usr/share/fonts/hbc.ttf
|
COPY ./assets/hbc.ttf /usr/share/fonts/hbc.ttf
|
||||||
|
COPY ./assets/reddit.ttf /usr/share/fonts/reddit.ttf
|
||||||
RUN fc-cache -fv
|
RUN fc-cache -fv
|
||||||
|
|
||||||
COPY --chown=node:node ./package.json package.json
|
COPY --chown=node:node ./package.json package.json
|
||||||
|
|
|
@ -46,6 +46,7 @@ WORKDIR /home/esmBot/.internal
|
||||||
COPY ./assets/caption.otf /usr/share/fonts/caption.otf
|
COPY ./assets/caption.otf /usr/share/fonts/caption.otf
|
||||||
COPY ./assets/caption2.ttf /usr/share/fonts/caption2.ttf
|
COPY ./assets/caption2.ttf /usr/share/fonts/caption2.ttf
|
||||||
COPY ./assets/hbc.ttf /usr/share/fonts/hbc.ttf
|
COPY ./assets/hbc.ttf /usr/share/fonts/hbc.ttf
|
||||||
|
COPY ./assets/reddit.ttf /usr/share/fonts/reddit.ttf
|
||||||
RUN fc-cache -fv
|
RUN fc-cache -fv
|
||||||
|
|
||||||
COPY --chown=node:node ./package.json package.json
|
COPY --chown=node:node ./package.json package.json
|
||||||
|
|
BIN
assets/images/reddit.png
Normal file
BIN
assets/images/reddit.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 20 KiB |
BIN
assets/reddit.ttf
Normal file
BIN
assets/reddit.ttf
Normal file
Binary file not shown.
19
commands/image-editing/reddit.js
Normal file
19
commands/image-editing/reddit.js
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
const ImageCommand = require("../../classes/imageCommand.js");
|
||||||
|
const { random } = require("../../utils/misc.js");
|
||||||
|
const names = ["esmBot", "me_irl", "dankmemes", "hmmm", "gaming", "wholesome", "chonkers", "memes", "funny", "pcmasterrace", "bellybros"];
|
||||||
|
|
||||||
|
class RedditCommand extends ImageCommand {
|
||||||
|
params(args) {
|
||||||
|
return {
|
||||||
|
caption: args.length === 0 ? random(names) : args.join(" ").replaceAll("\n", "").replaceAll(" ", "")
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
static description = "Adds a Reddit watermark to an image";
|
||||||
|
static arguments = ["{text}"];
|
||||||
|
|
||||||
|
static noText = "you need to provide some text to add a Reddit watermark!";
|
||||||
|
static command = "reddit";
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = RedditCommand;
|
|
@ -9,6 +9,7 @@ using namespace Magick;
|
||||||
Napi::Value Blur(const Napi::CallbackInfo &info) {
|
Napi::Value Blur(const Napi::CallbackInfo &info) {
|
||||||
Napi::Env env = info.Env();
|
Napi::Env env = info.Env();
|
||||||
|
|
||||||
|
try {
|
||||||
Napi::Object obj = info[0].As<Napi::Object>();
|
Napi::Object obj = info[0].As<Napi::Object>();
|
||||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||||
bool sharp = obj.Get("sharp").As<Napi::Boolean>().Value();
|
bool sharp = obj.Get("sharp").As<Napi::Boolean>().Value();
|
||||||
|
@ -44,8 +45,11 @@ Napi::Value Blur(const Napi::CallbackInfo &info) {
|
||||||
writeImages(coalesced.begin(), coalesced.end(), &blob);
|
writeImages(coalesced.begin(), coalesced.end(), &blob);
|
||||||
|
|
||||||
Napi::Object result = Napi::Object::New(env);
|
Napi::Object result = Napi::Object::New(env);
|
||||||
result.Set("data",
|
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
|
||||||
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
|
blob.length()));
|
||||||
result.Set("type", type);
|
result.Set("type", type);
|
||||||
return result;
|
return result;
|
||||||
|
} catch (std::exception const &err) {
|
||||||
|
throw Napi::Error::New(env, err.what());
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -9,6 +9,7 @@ using namespace Magick;
|
||||||
Napi::Value Blurple(const Napi::CallbackInfo &info) {
|
Napi::Value Blurple(const Napi::CallbackInfo &info) {
|
||||||
Napi::Env env = info.Env();
|
Napi::Env env = info.Env();
|
||||||
|
|
||||||
|
try {
|
||||||
Napi::Object obj = info[0].As<Napi::Object>();
|
Napi::Object obj = info[0].As<Napi::Object>();
|
||||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||||
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
||||||
|
@ -43,8 +44,11 @@ Napi::Value Blurple(const Napi::CallbackInfo &info) {
|
||||||
writeImages(blurpled.begin(), blurpled.end(), &blob);
|
writeImages(blurpled.begin(), blurpled.end(), &blob);
|
||||||
|
|
||||||
Napi::Object result = Napi::Object::New(env);
|
Napi::Object result = Napi::Object::New(env);
|
||||||
result.Set("data",
|
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
|
||||||
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
|
blob.length()));
|
||||||
result.Set("type", type);
|
result.Set("type", type);
|
||||||
return result;
|
return result;
|
||||||
|
} catch (std::exception const &err) {
|
||||||
|
throw Napi::Error::New(env, err.what());
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -9,6 +9,7 @@ using namespace Magick;
|
||||||
Napi::Value Caption(const Napi::CallbackInfo &info) {
|
Napi::Value Caption(const Napi::CallbackInfo &info) {
|
||||||
Napi::Env env = info.Env();
|
Napi::Env env = info.Env();
|
||||||
|
|
||||||
|
try {
|
||||||
Napi::Object obj = info[0].As<Napi::Object>();
|
Napi::Object obj = info[0].As<Napi::Object>();
|
||||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||||
string caption = obj.Get("caption").As<Napi::String>().Utf8Value();
|
string caption = obj.Get("caption").As<Napi::String>().Utf8Value();
|
||||||
|
@ -63,8 +64,11 @@ Napi::Value Caption(const Napi::CallbackInfo &info) {
|
||||||
writeImages(captioned.begin(), captioned.end(), &blob);
|
writeImages(captioned.begin(), captioned.end(), &blob);
|
||||||
|
|
||||||
Napi::Object result = Napi::Object::New(env);
|
Napi::Object result = Napi::Object::New(env);
|
||||||
result.Set("data",
|
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
|
||||||
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
|
blob.length()));
|
||||||
result.Set("type", type);
|
result.Set("type", type);
|
||||||
return result;
|
return result;
|
||||||
|
} catch (std::exception const &err) {
|
||||||
|
throw Napi::Error::New(env, err.what());
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -9,6 +9,7 @@ using namespace Magick;
|
||||||
Napi::Value CaptionTwo(const Napi::CallbackInfo &info) {
|
Napi::Value CaptionTwo(const Napi::CallbackInfo &info) {
|
||||||
Napi::Env env = info.Env();
|
Napi::Env env = info.Env();
|
||||||
|
|
||||||
|
try {
|
||||||
Napi::Object obj = info[0].As<Napi::Object>();
|
Napi::Object obj = info[0].As<Napi::Object>();
|
||||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||||
string caption = obj.Get("caption").As<Napi::String>().Utf8Value();
|
string caption = obj.Get("caption").As<Napi::String>().Utf8Value();
|
||||||
|
@ -61,8 +62,11 @@ Napi::Value CaptionTwo(const Napi::CallbackInfo &info) {
|
||||||
writeImages(captioned.begin(), captioned.end(), &blob);
|
writeImages(captioned.begin(), captioned.end(), &blob);
|
||||||
|
|
||||||
Napi::Object result = Napi::Object::New(env);
|
Napi::Object result = Napi::Object::New(env);
|
||||||
result.Set("data",
|
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
|
||||||
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
|
blob.length()));
|
||||||
result.Set("type", type);
|
result.Set("type", type);
|
||||||
return result;
|
return result;
|
||||||
|
} catch (std::exception const &err) {
|
||||||
|
throw Napi::Error::New(env, err.what());
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -9,6 +9,7 @@ using namespace Magick;
|
||||||
Napi::Value Circle(const Napi::CallbackInfo &info) {
|
Napi::Value Circle(const Napi::CallbackInfo &info) {
|
||||||
Napi::Env env = info.Env();
|
Napi::Env env = info.Env();
|
||||||
|
|
||||||
|
try {
|
||||||
Napi::Object obj = info[0].As<Napi::Object>();
|
Napi::Object obj = info[0].As<Napi::Object>();
|
||||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||||
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
||||||
|
@ -42,8 +43,11 @@ Napi::Value Circle(const Napi::CallbackInfo &info) {
|
||||||
writeImages(blurred.begin(), blurred.end(), &blob);
|
writeImages(blurred.begin(), blurred.end(), &blob);
|
||||||
|
|
||||||
Napi::Object result = Napi::Object::New(env);
|
Napi::Object result = Napi::Object::New(env);
|
||||||
result.Set("data",
|
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
|
||||||
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
|
blob.length()));
|
||||||
result.Set("type", type);
|
result.Set("type", type);
|
||||||
return result;
|
return result;
|
||||||
|
} catch (std::exception const &err) {
|
||||||
|
throw Napi::Error::New(env, err.what());
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -9,6 +9,7 @@ using namespace Magick;
|
||||||
Napi::Value Crop(const Napi::CallbackInfo &info) {
|
Napi::Value Crop(const Napi::CallbackInfo &info) {
|
||||||
Napi::Env env = info.Env();
|
Napi::Env env = info.Env();
|
||||||
|
|
||||||
|
try {
|
||||||
Napi::Object obj = info[0].As<Napi::Object>();
|
Napi::Object obj = info[0].As<Napi::Object>();
|
||||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||||
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
||||||
|
@ -50,8 +51,11 @@ Napi::Value Crop(const Napi::CallbackInfo &info) {
|
||||||
writeImages(mid.begin(), mid.end(), &blob);
|
writeImages(mid.begin(), mid.end(), &blob);
|
||||||
|
|
||||||
Napi::Object result = Napi::Object::New(env);
|
Napi::Object result = Napi::Object::New(env);
|
||||||
result.Set("data",
|
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
|
||||||
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
|
blob.length()));
|
||||||
result.Set("type", type);
|
result.Set("type", type);
|
||||||
return result;
|
return result;
|
||||||
|
} catch (std::exception const &err) {
|
||||||
|
throw Napi::Error::New(env, err.what());
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -9,6 +9,7 @@ using namespace Magick;
|
||||||
Napi::Value Explode(const Napi::CallbackInfo &info) {
|
Napi::Value Explode(const Napi::CallbackInfo &info) {
|
||||||
Napi::Env env = info.Env();
|
Napi::Env env = info.Env();
|
||||||
|
|
||||||
|
try {
|
||||||
Napi::Object obj = info[0].As<Napi::Object>();
|
Napi::Object obj = info[0].As<Napi::Object>();
|
||||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||||
int amount = obj.Get("amount").As<Napi::Number>().Int32Value();
|
int amount = obj.Get("amount").As<Napi::Number>().Int32Value();
|
||||||
|
@ -43,8 +44,11 @@ Napi::Value Explode(const Napi::CallbackInfo &info) {
|
||||||
writeImages(blurred.begin(), blurred.end(), &blob);
|
writeImages(blurred.begin(), blurred.end(), &blob);
|
||||||
|
|
||||||
Napi::Object result = Napi::Object::New(env);
|
Napi::Object result = Napi::Object::New(env);
|
||||||
result.Set("data",
|
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
|
||||||
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
|
blob.length()));
|
||||||
result.Set("type", type);
|
result.Set("type", type);
|
||||||
return result;
|
return result;
|
||||||
|
} catch (std::exception const &err) {
|
||||||
|
throw Napi::Error::New(env, err.what());
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -9,6 +9,7 @@ using namespace Magick;
|
||||||
Napi::Value Flag(const Napi::CallbackInfo &info) {
|
Napi::Value Flag(const Napi::CallbackInfo &info) {
|
||||||
Napi::Env env = info.Env();
|
Napi::Env env = info.Env();
|
||||||
|
|
||||||
|
try {
|
||||||
Napi::Object obj = info[0].As<Napi::Object>();
|
Napi::Object obj = info[0].As<Napi::Object>();
|
||||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||||
string overlay = obj.Get("overlay").As<Napi::String>().Utf8Value();
|
string overlay = obj.Get("overlay").As<Napi::String>().Utf8Value();
|
||||||
|
@ -51,8 +52,11 @@ Napi::Value Flag(const Napi::CallbackInfo &info) {
|
||||||
writeImages(mid.begin(), mid.end(), &blob);
|
writeImages(mid.begin(), mid.end(), &blob);
|
||||||
|
|
||||||
Napi::Object result = Napi::Object::New(env);
|
Napi::Object result = Napi::Object::New(env);
|
||||||
result.Set("data",
|
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
|
||||||
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
|
blob.length()));
|
||||||
result.Set("type", type);
|
result.Set("type", type);
|
||||||
return result;
|
return result;
|
||||||
|
} catch (std::exception const &err) {
|
||||||
|
throw Napi::Error::New(env, err.what());
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -9,6 +9,7 @@ using namespace Magick;
|
||||||
Napi::Value Flip(const Napi::CallbackInfo &info) {
|
Napi::Value Flip(const Napi::CallbackInfo &info) {
|
||||||
Napi::Env env = info.Env();
|
Napi::Env env = info.Env();
|
||||||
|
|
||||||
|
try {
|
||||||
Napi::Object obj = info[0].As<Napi::Object>();
|
Napi::Object obj = info[0].As<Napi::Object>();
|
||||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||||
bool flop =
|
bool flop =
|
||||||
|
@ -44,8 +45,11 @@ Napi::Value Flip(const Napi::CallbackInfo &info) {
|
||||||
writeImages(mid.begin(), mid.end(), &blob);
|
writeImages(mid.begin(), mid.end(), &blob);
|
||||||
|
|
||||||
Napi::Object result = Napi::Object::New(env);
|
Napi::Object result = Napi::Object::New(env);
|
||||||
result.Set("data",
|
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
|
||||||
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
|
blob.length()));
|
||||||
result.Set("type", type);
|
result.Set("type", type);
|
||||||
return result;
|
return result;
|
||||||
|
} catch (std::exception const &err) {
|
||||||
|
throw Napi::Error::New(env, err.what());
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -9,6 +9,7 @@ using namespace Magick;
|
||||||
Napi::Value Freeze(const Napi::CallbackInfo &info) {
|
Napi::Value Freeze(const Napi::CallbackInfo &info) {
|
||||||
Napi::Env env = info.Env();
|
Napi::Env env = info.Env();
|
||||||
|
|
||||||
|
try {
|
||||||
Napi::Object obj = info[0].As<Napi::Object>();
|
Napi::Object obj = info[0].As<Napi::Object>();
|
||||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||||
bool loop =
|
bool loop =
|
||||||
|
@ -16,8 +17,9 @@ Napi::Value Freeze(const Napi::CallbackInfo &info) {
|
||||||
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;
|
||||||
int frame =
|
int frame = obj.Has("frame")
|
||||||
obj.Has("frame") ? obj.Get("frame").As<Napi::Number>().Int32Value() : -1;
|
? obj.Get("frame").As<Napi::Number>().Int32Value()
|
||||||
|
: -1;
|
||||||
|
|
||||||
Blob blob;
|
Blob blob;
|
||||||
|
|
||||||
|
@ -38,8 +40,11 @@ Napi::Value Freeze(const Napi::CallbackInfo &info) {
|
||||||
writeImages(frames.begin(), frames.end(), &blob);
|
writeImages(frames.begin(), frames.end(), &blob);
|
||||||
|
|
||||||
Napi::Object result = Napi::Object::New(env);
|
Napi::Object result = Napi::Object::New(env);
|
||||||
result.Set("data",
|
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
|
||||||
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
|
blob.length()));
|
||||||
result.Set("type", type);
|
result.Set("type", type);
|
||||||
return result;
|
return result;
|
||||||
|
} catch (std::exception const &err) {
|
||||||
|
throw Napi::Error::New(env, err.what());
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -9,6 +9,7 @@ using namespace Magick;
|
||||||
Napi::Value Gamexplain(const Napi::CallbackInfo &info) {
|
Napi::Value Gamexplain(const Napi::CallbackInfo &info) {
|
||||||
Napi::Env env = info.Env();
|
Napi::Env env = info.Env();
|
||||||
|
|
||||||
|
try {
|
||||||
Napi::Object obj = info[0].As<Napi::Object>();
|
Napi::Object obj = info[0].As<Napi::Object>();
|
||||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||||
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
||||||
|
@ -47,8 +48,11 @@ Napi::Value Gamexplain(const Napi::CallbackInfo &info) {
|
||||||
writeImages(mid.begin(), mid.end(), &blob);
|
writeImages(mid.begin(), mid.end(), &blob);
|
||||||
|
|
||||||
Napi::Object result = Napi::Object::New(env);
|
Napi::Object result = Napi::Object::New(env);
|
||||||
result.Set("data",
|
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
|
||||||
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
|
blob.length()));
|
||||||
result.Set("type", type);
|
result.Set("type", type);
|
||||||
return result;
|
return result;
|
||||||
|
} catch (std::exception const &err) {
|
||||||
|
throw Napi::Error::New(env, err.what());
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -9,6 +9,7 @@ using namespace Magick;
|
||||||
Napi::Value Globe(const Napi::CallbackInfo &info) {
|
Napi::Value Globe(const Napi::CallbackInfo &info) {
|
||||||
Napi::Env env = info.Env();
|
Napi::Env env = info.Env();
|
||||||
|
|
||||||
|
try {
|
||||||
Napi::Object obj = info[0].As<Napi::Object>();
|
Napi::Object obj = info[0].As<Napi::Object>();
|
||||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||||
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
||||||
|
@ -42,7 +43,8 @@ Napi::Value Globe(const Napi::CallbackInfo &info) {
|
||||||
image.roll(Geometry("+" + to_string(width * i / coalesced.size())));
|
image.roll(Geometry("+" + to_string(width * i / coalesced.size())));
|
||||||
image.composite(overlay, Magick::CenterGravity,
|
image.composite(overlay, Magick::CenterGravity,
|
||||||
Magick::HardLightCompositeOp);
|
Magick::HardLightCompositeOp);
|
||||||
image.composite(distort, Magick::CenterGravity, Magick::DistortCompositeOp);
|
image.composite(distort, Magick::CenterGravity,
|
||||||
|
Magick::DistortCompositeOp);
|
||||||
image.magick("GIF");
|
image.magick("GIF");
|
||||||
mid.push_back(image);
|
mid.push_back(image);
|
||||||
i++;
|
i++;
|
||||||
|
@ -63,8 +65,11 @@ Napi::Value Globe(const Napi::CallbackInfo &info) {
|
||||||
writeImages(mid.begin(), mid.end(), &blob);
|
writeImages(mid.begin(), mid.end(), &blob);
|
||||||
|
|
||||||
Napi::Object result = Napi::Object::New(env);
|
Napi::Object result = Napi::Object::New(env);
|
||||||
result.Set("data",
|
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
|
||||||
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
|
blob.length()));
|
||||||
result.Set("type", type);
|
result.Set("type", type);
|
||||||
return result;
|
return result;
|
||||||
|
} catch (std::exception const &err) {
|
||||||
|
throw Napi::Error::New(env, err.what());
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -9,6 +9,7 @@ using namespace Magick;
|
||||||
Napi::Value Homebrew(const Napi::CallbackInfo &info) {
|
Napi::Value Homebrew(const Napi::CallbackInfo &info) {
|
||||||
Napi::Env env = info.Env();
|
Napi::Env env = info.Env();
|
||||||
|
|
||||||
|
try {
|
||||||
Napi::Object obj = info[0].As<Napi::Object>();
|
Napi::Object obj = info[0].As<Napi::Object>();
|
||||||
string caption = obj.Get("caption").As<Napi::String>().Utf8Value();
|
string caption = obj.Get("caption").As<Napi::String>().Utf8Value();
|
||||||
|
|
||||||
|
@ -26,8 +27,11 @@ Napi::Value Homebrew(const Napi::CallbackInfo &info) {
|
||||||
image.write(&blob);
|
image.write(&blob);
|
||||||
|
|
||||||
Napi::Object result = Napi::Object::New(env);
|
Napi::Object result = Napi::Object::New(env);
|
||||||
result.Set("data",
|
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
|
||||||
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
|
blob.length()));
|
||||||
result.Set("type", "png");
|
result.Set("type", "png");
|
||||||
return result;
|
return result;
|
||||||
|
} catch (std::exception const &err) {
|
||||||
|
throw Napi::Error::New(env, err.what());
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -21,6 +21,7 @@
|
||||||
#include "mirror.h"
|
#include "mirror.h"
|
||||||
#include "swirl.h"
|
#include "swirl.h"
|
||||||
#include "motivate.h"
|
#include "motivate.h"
|
||||||
|
#include "reddit.h"
|
||||||
#include "resize.h"
|
#include "resize.h"
|
||||||
#include "retro.h"
|
#include "retro.h"
|
||||||
#include "reverse.h"
|
#include "reverse.h"
|
||||||
|
@ -56,6 +57,7 @@ Napi::Object Init(Napi::Env env, Napi::Object exports)
|
||||||
exports.Set(Napi::String::New(env, "meme"), Napi::Function::New(env, Meme));
|
exports.Set(Napi::String::New(env, "meme"), Napi::Function::New(env, Meme));
|
||||||
exports.Set(Napi::String::New(env, "mirror"), Napi::Function::New(env, Mirror));
|
exports.Set(Napi::String::New(env, "mirror"), Napi::Function::New(env, Mirror));
|
||||||
exports.Set(Napi::String::New(env, "motivate"), Napi::Function::New(env, Motivate));
|
exports.Set(Napi::String::New(env, "motivate"), Napi::Function::New(env, Motivate));
|
||||||
|
exports.Set(Napi::String::New(env, "reddit"), Napi::Function::New(env, Reddit));
|
||||||
exports.Set(Napi::String::New(env, "resize"), Napi::Function::New(env, Resize));
|
exports.Set(Napi::String::New(env, "resize"), Napi::Function::New(env, Resize));
|
||||||
exports.Set(Napi::String::New(env, "retro"), Napi::Function::New(env, Retro));
|
exports.Set(Napi::String::New(env, "retro"), Napi::Function::New(env, Retro));
|
||||||
exports.Set(Napi::String::New(env, "reverse"), Napi::Function::New(env, Reverse));
|
exports.Set(Napi::String::New(env, "reverse"), Napi::Function::New(env, Reverse));
|
||||||
|
|
|
@ -9,6 +9,7 @@ using namespace Magick;
|
||||||
Napi::Value Invert(const Napi::CallbackInfo &info) {
|
Napi::Value Invert(const Napi::CallbackInfo &info) {
|
||||||
Napi::Env env = info.Env();
|
Napi::Env env = info.Env();
|
||||||
|
|
||||||
|
try {
|
||||||
Napi::Object obj = info[0].As<Napi::Object>();
|
Napi::Object obj = info[0].As<Napi::Object>();
|
||||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||||
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
||||||
|
@ -44,8 +45,11 @@ Napi::Value Invert(const Napi::CallbackInfo &info) {
|
||||||
writeImages(mid.begin(), mid.end(), &blob);
|
writeImages(mid.begin(), mid.end(), &blob);
|
||||||
|
|
||||||
Napi::Object result = Napi::Object::New(env);
|
Napi::Object result = Napi::Object::New(env);
|
||||||
result.Set("data",
|
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
|
||||||
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
|
blob.length()));
|
||||||
result.Set("type", type);
|
result.Set("type", type);
|
||||||
return result;
|
return result;
|
||||||
|
} catch (std::exception const &err) {
|
||||||
|
throw Napi::Error::New(env, err.what());
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -9,6 +9,7 @@ using namespace Magick;
|
||||||
Napi::Value Jpeg(const Napi::CallbackInfo &info) {
|
Napi::Value Jpeg(const Napi::CallbackInfo &info) {
|
||||||
Napi::Env env = info.Env();
|
Napi::Env env = info.Env();
|
||||||
|
|
||||||
|
try {
|
||||||
Napi::Object obj = info[0].As<Napi::Object>();
|
Napi::Object obj = info[0].As<Napi::Object>();
|
||||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||||
|
|
||||||
|
@ -21,8 +22,11 @@ Napi::Value Jpeg(const Napi::CallbackInfo &info) {
|
||||||
image.write(&blob);
|
image.write(&blob);
|
||||||
|
|
||||||
Napi::Object result = Napi::Object::New(env);
|
Napi::Object result = Napi::Object::New(env);
|
||||||
result.Set("data",
|
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
|
||||||
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
|
blob.length()));
|
||||||
result.Set("type", "jpg");
|
result.Set("type", "jpg");
|
||||||
return result;
|
return result;
|
||||||
|
} catch (std::exception const &err) {
|
||||||
|
throw Napi::Error::New(env, err.what());
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -9,6 +9,7 @@ using namespace Magick;
|
||||||
Napi::Value Leak(const Napi::CallbackInfo &info) {
|
Napi::Value Leak(const Napi::CallbackInfo &info) {
|
||||||
Napi::Env env = info.Env();
|
Napi::Env env = info.Env();
|
||||||
|
|
||||||
|
try {
|
||||||
Napi::Object obj = info[0].As<Napi::Object>();
|
Napi::Object obj = info[0].As<Napi::Object>();
|
||||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||||
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
||||||
|
@ -48,8 +49,11 @@ Napi::Value Leak(const Napi::CallbackInfo &info) {
|
||||||
writeImages(mid.begin(), mid.end(), &blob);
|
writeImages(mid.begin(), mid.end(), &blob);
|
||||||
|
|
||||||
Napi::Object result = Napi::Object::New(env);
|
Napi::Object result = Napi::Object::New(env);
|
||||||
result.Set("data",
|
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
|
||||||
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
|
blob.length()));
|
||||||
result.Set("type", type);
|
result.Set("type", type);
|
||||||
return result;
|
return result;
|
||||||
|
} catch (std::exception const &err) {
|
||||||
|
throw Napi::Error::New(env, err.what());
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -9,6 +9,7 @@ using namespace Magick;
|
||||||
Napi::Value Magik(const Napi::CallbackInfo &info) {
|
Napi::Value Magik(const Napi::CallbackInfo &info) {
|
||||||
Napi::Env env = info.Env();
|
Napi::Env env = info.Env();
|
||||||
|
|
||||||
|
try {
|
||||||
Napi::Object obj = info[0].As<Napi::Object>();
|
Napi::Object obj = info[0].As<Napi::Object>();
|
||||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||||
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
||||||
|
@ -44,8 +45,11 @@ Napi::Value Magik(const Napi::CallbackInfo &info) {
|
||||||
writeImages(blurred.begin(), blurred.end(), &blob);
|
writeImages(blurred.begin(), blurred.end(), &blob);
|
||||||
|
|
||||||
Napi::Object result = Napi::Object::New(env);
|
Napi::Object result = Napi::Object::New(env);
|
||||||
result.Set("data",
|
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
|
||||||
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
|
blob.length()));
|
||||||
result.Set("type", type);
|
result.Set("type", type);
|
||||||
return result;
|
return result;
|
||||||
|
} catch (std::exception const &err) {
|
||||||
|
throw Napi::Error::New(env, err.what());
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -9,6 +9,7 @@ using namespace Magick;
|
||||||
Napi::Value Meme(const Napi::CallbackInfo &info) {
|
Napi::Value Meme(const Napi::CallbackInfo &info) {
|
||||||
Napi::Env env = info.Env();
|
Napi::Env env = info.Env();
|
||||||
|
|
||||||
|
try {
|
||||||
Napi::Object obj = info[0].As<Napi::Object>();
|
Napi::Object obj = info[0].As<Napi::Object>();
|
||||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||||
string top = obj.Get("top").As<Napi::String>().Utf8Value();
|
string top = obj.Get("top").As<Napi::String>().Utf8Value();
|
||||||
|
@ -26,7 +27,8 @@ Napi::Value Meme(const Napi::CallbackInfo &info) {
|
||||||
Image bottom_text;
|
Image bottom_text;
|
||||||
readImages(&frames, path);
|
readImages(&frames, path);
|
||||||
coalesceImages(&coalesced, frames.begin(), frames.end());
|
coalesceImages(&coalesced, frames.begin(), frames.end());
|
||||||
for_each(coalesced.begin(), coalesced.end(), scaleImage(Geometry(600, 600)));
|
for_each(coalesced.begin(), coalesced.end(),
|
||||||
|
scaleImage(Geometry(600, 600)));
|
||||||
|
|
||||||
top_text.size(Geometry(to_string(coalesced.front().columns())));
|
top_text.size(Geometry(to_string(coalesced.front().columns())));
|
||||||
top_text.backgroundColor("none");
|
top_text.backgroundColor("none");
|
||||||
|
@ -80,8 +82,11 @@ Napi::Value Meme(const Napi::CallbackInfo &info) {
|
||||||
writeImages(mid.begin(), mid.end(), &blob);
|
writeImages(mid.begin(), mid.end(), &blob);
|
||||||
|
|
||||||
Napi::Object result = Napi::Object::New(env);
|
Napi::Object result = Napi::Object::New(env);
|
||||||
result.Set("data",
|
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
|
||||||
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
|
blob.length()));
|
||||||
result.Set("type", type);
|
result.Set("type", type);
|
||||||
return result;
|
return result;
|
||||||
|
} catch (std::exception const &err) {
|
||||||
|
throw Napi::Error::New(env, err.what());
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -9,6 +9,7 @@ using namespace Magick;
|
||||||
Napi::Value Mirror(const Napi::CallbackInfo &info) {
|
Napi::Value Mirror(const Napi::CallbackInfo &info) {
|
||||||
Napi::Env env = info.Env();
|
Napi::Env env = info.Env();
|
||||||
|
|
||||||
|
try {
|
||||||
Napi::Object obj = info[0].As<Napi::Object>();
|
Napi::Object obj = info[0].As<Napi::Object>();
|
||||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||||
bool vertical = obj.Has("vertical")
|
bool vertical = obj.Has("vertical")
|
||||||
|
@ -42,11 +43,11 @@ Napi::Value Mirror(const Napi::CallbackInfo &info) {
|
||||||
for (Image &image : coalesced) {
|
for (Image &image : coalesced) {
|
||||||
list<Image> mirrored;
|
list<Image> mirrored;
|
||||||
Image final;
|
Image final;
|
||||||
image.extent(
|
image.extent(Geometry(to_string(vertical ? image.baseColumns()
|
||||||
Geometry(to_string(vertical ? image.baseColumns()
|
|
||||||
: image.baseColumns() / 2) +
|
: image.baseColumns() / 2) +
|
||||||
"x" +
|
"x" +
|
||||||
to_string(vertical ? image.baseRows() / 2 : image.baseRows())),
|
to_string(vertical ? image.baseRows() / 2
|
||||||
|
: image.baseRows())),
|
||||||
gravity);
|
gravity);
|
||||||
mirrored.push_back(image);
|
mirrored.push_back(image);
|
||||||
Image mirror = image;
|
Image mirror = image;
|
||||||
|
@ -79,8 +80,11 @@ Napi::Value Mirror(const Napi::CallbackInfo &info) {
|
||||||
writeImages(mid.begin(), mid.end(), &blob);
|
writeImages(mid.begin(), mid.end(), &blob);
|
||||||
|
|
||||||
Napi::Object result = Napi::Object::New(env);
|
Napi::Object result = Napi::Object::New(env);
|
||||||
result.Set("data",
|
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
|
||||||
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
|
blob.length()));
|
||||||
result.Set("type", type);
|
result.Set("type", type);
|
||||||
return result;
|
return result;
|
||||||
|
} catch (std::exception const &err) {
|
||||||
|
throw Napi::Error::New(env, err.what());
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -9,6 +9,7 @@ using namespace Magick;
|
||||||
Napi::Value Motivate(const Napi::CallbackInfo &info) {
|
Napi::Value Motivate(const Napi::CallbackInfo &info) {
|
||||||
Napi::Env env = info.Env();
|
Napi::Env env = info.Env();
|
||||||
|
|
||||||
|
try {
|
||||||
Napi::Object obj = info[0].As<Napi::Object>();
|
Napi::Object obj = info[0].As<Napi::Object>();
|
||||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||||
string top_text = obj.Get("top").As<Napi::String>().Utf8Value();
|
string top_text = obj.Get("top").As<Napi::String>().Utf8Value();
|
||||||
|
@ -84,8 +85,11 @@ Napi::Value Motivate(const Napi::CallbackInfo &info) {
|
||||||
writeImages(mid.begin(), mid.end(), &blob);
|
writeImages(mid.begin(), mid.end(), &blob);
|
||||||
|
|
||||||
Napi::Object result = Napi::Object::New(env);
|
Napi::Object result = Napi::Object::New(env);
|
||||||
result.Set("data",
|
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
|
||||||
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
|
blob.length()));
|
||||||
result.Set("type", type);
|
result.Set("type", type);
|
||||||
return result;
|
return result;
|
||||||
|
} catch (std::exception const &err) {
|
||||||
|
throw Napi::Error::New(env, err.what());
|
||||||
|
}
|
||||||
}
|
}
|
74
natives/reddit.cc
Normal file
74
natives/reddit.cc
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
#include <Magick++.h>
|
||||||
|
#include <napi.h>
|
||||||
|
|
||||||
|
#include <list>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace Magick;
|
||||||
|
|
||||||
|
Napi::Value Reddit(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 text = obj.Get("caption").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;
|
||||||
|
Image watermark;
|
||||||
|
Image text_image;
|
||||||
|
readImages(&frames, path);
|
||||||
|
|
||||||
|
watermark.read("./assets/images/reddit.png");
|
||||||
|
text_image.textGravity(Magick::WestGravity);
|
||||||
|
text_image.font("Roboto");
|
||||||
|
text_image.fontPointsize(47);
|
||||||
|
text_image.backgroundColor("none");
|
||||||
|
text_image.read("pango:<span foreground='white'>" + text + "</span>");
|
||||||
|
|
||||||
|
watermark.composite(text_image, Geometry("+375+46"),
|
||||||
|
Magick::OverCompositeOp);
|
||||||
|
|
||||||
|
string query(to_string(frames.front().baseColumns()) + "x");
|
||||||
|
watermark.scale(Geometry(query));
|
||||||
|
|
||||||
|
coalesceImages(&coalesced, frames.begin(), frames.end());
|
||||||
|
|
||||||
|
for (Image &image : coalesced) {
|
||||||
|
Image final;
|
||||||
|
list<Image> to_append;
|
||||||
|
to_append.push_back(image);
|
||||||
|
to_append.push_back(watermark);
|
||||||
|
appendImages(&final, to_append.begin(), to_append.end(), true);
|
||||||
|
final.repage();
|
||||||
|
image.magick(type);
|
||||||
|
final.animationDelay(delay == 0 ? image.animationDelay() : delay);
|
||||||
|
mid.push_back(final);
|
||||||
|
}
|
||||||
|
|
||||||
|
optimizeTransparency(mid.begin(), mid.end());
|
||||||
|
|
||||||
|
if (type == "gif") {
|
||||||
|
for (Image &image : mid) {
|
||||||
|
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
|
||||||
|
image.quantize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 (std::exception const &err) {
|
||||||
|
throw Napi::Error::New(env, err.what());
|
||||||
|
}
|
||||||
|
}
|
8
natives/reddit.h
Normal file
8
natives/reddit.h
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
#ifndef ESMBOT_NATIVES_REDDIT_H_
|
||||||
|
#define ESMBOT_NATIVES_REDDIT_H_
|
||||||
|
|
||||||
|
#include <napi.h>
|
||||||
|
|
||||||
|
Napi::Value Reddit(const Napi::CallbackInfo& info);
|
||||||
|
|
||||||
|
#endif
|
|
@ -9,6 +9,7 @@ using namespace Magick;
|
||||||
Napi::Value Resize(const Napi::CallbackInfo &info) {
|
Napi::Value Resize(const Napi::CallbackInfo &info) {
|
||||||
Napi::Env env = info.Env();
|
Napi::Env env = info.Env();
|
||||||
|
|
||||||
|
try {
|
||||||
Napi::Object obj = info[0].As<Napi::Object>();
|
Napi::Object obj = info[0].As<Napi::Object>();
|
||||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||||
bool stretch = obj.Has("stretch")
|
bool stretch = obj.Has("stretch")
|
||||||
|
@ -55,8 +56,11 @@ Napi::Value Resize(const Napi::CallbackInfo &info) {
|
||||||
writeImages(blurred.begin(), blurred.end(), &blob);
|
writeImages(blurred.begin(), blurred.end(), &blob);
|
||||||
|
|
||||||
Napi::Object result = Napi::Object::New(env);
|
Napi::Object result = Napi::Object::New(env);
|
||||||
result.Set("data",
|
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
|
||||||
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
|
blob.length()));
|
||||||
result.Set("type", type);
|
result.Set("type", type);
|
||||||
return result;
|
return result;
|
||||||
|
} catch (std::exception const &err) {
|
||||||
|
throw Napi::Error::New(env, err.what());
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -9,6 +9,7 @@ using namespace Magick;
|
||||||
Napi::Value Retro(const Napi::CallbackInfo &info) {
|
Napi::Value Retro(const Napi::CallbackInfo &info) {
|
||||||
Napi::Env env = info.Env();
|
Napi::Env env = info.Env();
|
||||||
|
|
||||||
|
try {
|
||||||
Napi::Object obj = info[0].As<Napi::Object>();
|
Napi::Object obj = info[0].As<Napi::Object>();
|
||||||
string line1 = obj.Get("line1").As<Napi::String>().Utf8Value();
|
string line1 = obj.Get("line1").As<Napi::String>().Utf8Value();
|
||||||
string line2 = obj.Get("line2").As<Napi::String>().Utf8Value();
|
string line2 = obj.Get("line2").As<Napi::String>().Utf8Value();
|
||||||
|
@ -77,8 +78,11 @@ Napi::Value Retro(const Napi::CallbackInfo &info) {
|
||||||
image.write(&blob);
|
image.write(&blob);
|
||||||
|
|
||||||
Napi::Object result = Napi::Object::New(env);
|
Napi::Object result = Napi::Object::New(env);
|
||||||
result.Set("data",
|
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
|
||||||
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
|
blob.length()));
|
||||||
result.Set("type", "png");
|
result.Set("type", "png");
|
||||||
return result;
|
return result;
|
||||||
|
} catch (std::exception const &err) {
|
||||||
|
throw Napi::Error::New(env, err.what());
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -9,6 +9,7 @@ using namespace Magick;
|
||||||
Napi::Value Reverse(const Napi::CallbackInfo &info) {
|
Napi::Value Reverse(const Napi::CallbackInfo &info) {
|
||||||
Napi::Env env = info.Env();
|
Napi::Env env = info.Env();
|
||||||
|
|
||||||
|
try {
|
||||||
Napi::Object obj = info[0].As<Napi::Object>();
|
Napi::Object obj = info[0].As<Napi::Object>();
|
||||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||||
bool soos =
|
bool soos =
|
||||||
|
@ -44,8 +45,11 @@ Napi::Value Reverse(const Napi::CallbackInfo &info) {
|
||||||
writeImages(coalesced.begin(), coalesced.end(), &blob);
|
writeImages(coalesced.begin(), coalesced.end(), &blob);
|
||||||
|
|
||||||
Napi::Object result = Napi::Object::New(env);
|
Napi::Object result = Napi::Object::New(env);
|
||||||
result.Set("data",
|
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
|
||||||
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
|
blob.length()));
|
||||||
result.Set("type", "gif");
|
result.Set("type", "gif");
|
||||||
return result;
|
return result;
|
||||||
|
} catch (std::exception const &err) {
|
||||||
|
throw Napi::Error::New(env, err.what());
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -9,6 +9,7 @@ using namespace Magick;
|
||||||
Napi::Value Scott(const Napi::CallbackInfo &info) {
|
Napi::Value Scott(const Napi::CallbackInfo &info) {
|
||||||
Napi::Env env = info.Env();
|
Napi::Env env = info.Env();
|
||||||
|
|
||||||
|
try {
|
||||||
Napi::Object obj = info[0].As<Napi::Object>();
|
Napi::Object obj = info[0].As<Napi::Object>();
|
||||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||||
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
||||||
|
@ -53,8 +54,11 @@ Napi::Value Scott(const Napi::CallbackInfo &info) {
|
||||||
writeImages(mid.begin(), mid.end(), &blob);
|
writeImages(mid.begin(), mid.end(), &blob);
|
||||||
|
|
||||||
Napi::Object result = Napi::Object::New(env);
|
Napi::Object result = Napi::Object::New(env);
|
||||||
result.Set("data",
|
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
|
||||||
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
|
blob.length()));
|
||||||
result.Set("type", type);
|
result.Set("type", type);
|
||||||
return result;
|
return result;
|
||||||
|
} catch (std::exception const &err) {
|
||||||
|
throw Napi::Error::New(env, err.what());
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -9,6 +9,7 @@ using namespace Magick;
|
||||||
Napi::Value Sonic(const Napi::CallbackInfo &info) {
|
Napi::Value Sonic(const Napi::CallbackInfo &info) {
|
||||||
Napi::Env env = info.Env();
|
Napi::Env env = info.Env();
|
||||||
|
|
||||||
|
try {
|
||||||
Napi::Object obj = info[0].As<Napi::Object>();
|
Napi::Object obj = info[0].As<Napi::Object>();
|
||||||
string text = obj.Get("text").As<Napi::String>().Utf8Value();
|
string text = obj.Get("text").As<Napi::String>().Utf8Value();
|
||||||
|
|
||||||
|
@ -29,8 +30,11 @@ Napi::Value Sonic(const Napi::CallbackInfo &info) {
|
||||||
image.write(&blob);
|
image.write(&blob);
|
||||||
|
|
||||||
Napi::Object result = Napi::Object::New(env);
|
Napi::Object result = Napi::Object::New(env);
|
||||||
result.Set("data",
|
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
|
||||||
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
|
blob.length()));
|
||||||
result.Set("type", "png");
|
result.Set("type", "png");
|
||||||
return result;
|
return result;
|
||||||
|
} catch (std::exception const &err) {
|
||||||
|
throw Napi::Error::New(env, err.what());
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -9,6 +9,7 @@ using namespace Magick;
|
||||||
Napi::Value Speed(const Napi::CallbackInfo &info) {
|
Napi::Value Speed(const Napi::CallbackInfo &info) {
|
||||||
Napi::Env env = info.Env();
|
Napi::Env env = info.Env();
|
||||||
|
|
||||||
|
try {
|
||||||
Napi::Object obj = info[0].As<Napi::Object>();
|
Napi::Object obj = info[0].As<Napi::Object>();
|
||||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||||
bool slow =
|
bool slow =
|
||||||
|
@ -50,16 +51,18 @@ Napi::Value Speed(const Napi::CallbackInfo &info) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < speed - 1; ++i) {
|
for (int i = 0; i < speed - 1; ++i) {
|
||||||
frames.remove_if(
|
frames.remove_if([counter = 0](const auto x) mutable {
|
||||||
[counter = 0](const auto x) mutable { return ++counter % 2 == 0; });
|
return ++counter % 2 == 0;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
int new_delay = slow ? delay * speed : delay / speed;
|
int new_delay = slow ? delay * speed : delay / speed;
|
||||||
if (!slow && new_delay <= 1) {
|
if (!slow && new_delay <= 1) {
|
||||||
for (int i = 0; i < speed - 1; ++i) {
|
for (int i = 0; i < speed - 1; ++i) {
|
||||||
frames.remove_if(
|
frames.remove_if([counter = 0](const auto x) mutable {
|
||||||
[counter = 0](const auto x) mutable { return ++counter % 2 == 0; });
|
return ++counter % 2 == 0;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for_each(frames.begin(), frames.end(), animationDelayImage(new_delay));
|
for_each(frames.begin(), frames.end(), animationDelayImage(new_delay));
|
||||||
|
@ -71,8 +74,11 @@ Napi::Value Speed(const Napi::CallbackInfo &info) {
|
||||||
writeImages(frames.begin(), frames.end(), &blob);
|
writeImages(frames.begin(), frames.end(), &blob);
|
||||||
|
|
||||||
Napi::Object result = Napi::Object::New(env);
|
Napi::Object result = Napi::Object::New(env);
|
||||||
result.Set("data",
|
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
|
||||||
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
|
blob.length()));
|
||||||
result.Set("type", type);
|
result.Set("type", type);
|
||||||
return result;
|
return result;
|
||||||
|
} catch (std::exception const &err) {
|
||||||
|
throw Napi::Error::New(env, err.what());
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -9,6 +9,7 @@ using namespace Magick;
|
||||||
Napi::Value Spin(const Napi::CallbackInfo &info) {
|
Napi::Value Spin(const Napi::CallbackInfo &info) {
|
||||||
Napi::Env env = info.Env();
|
Napi::Env env = info.Env();
|
||||||
|
|
||||||
|
try {
|
||||||
Napi::Object obj = info[0].As<Napi::Object>();
|
Napi::Object obj = info[0].As<Napi::Object>();
|
||||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||||
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
||||||
|
@ -60,8 +61,11 @@ Napi::Value Spin(const Napi::CallbackInfo &info) {
|
||||||
writeImages(mid.begin(), mid.end(), &blob);
|
writeImages(mid.begin(), mid.end(), &blob);
|
||||||
|
|
||||||
Napi::Object result = Napi::Object::New(env);
|
Napi::Object result = Napi::Object::New(env);
|
||||||
result.Set("data",
|
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
|
||||||
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
|
blob.length()));
|
||||||
result.Set("type", "gif");
|
result.Set("type", "gif");
|
||||||
return result;
|
return result;
|
||||||
|
} catch (std::exception const &err) {
|
||||||
|
throw Napi::Error::New(env, err.what());
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -9,6 +9,7 @@ using namespace Magick;
|
||||||
Napi::Value Swirl(const Napi::CallbackInfo &info) {
|
Napi::Value Swirl(const Napi::CallbackInfo &info) {
|
||||||
Napi::Env env = info.Env();
|
Napi::Env env = info.Env();
|
||||||
|
|
||||||
|
try {
|
||||||
Napi::Object obj = info[0].As<Napi::Object>();
|
Napi::Object obj = info[0].As<Napi::Object>();
|
||||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||||
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
||||||
|
@ -42,8 +43,11 @@ Napi::Value Swirl(const Napi::CallbackInfo &info) {
|
||||||
writeImages(mid.begin(), mid.end(), &blob);
|
writeImages(mid.begin(), mid.end(), &blob);
|
||||||
|
|
||||||
Napi::Object result = Napi::Object::New(env);
|
Napi::Object result = Napi::Object::New(env);
|
||||||
result.Set("data",
|
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
|
||||||
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
|
blob.length()));
|
||||||
result.Set("type", type);
|
result.Set("type", type);
|
||||||
return result;
|
return result;
|
||||||
|
} catch (std::exception const &err) {
|
||||||
|
throw Napi::Error::New(env, err.what());
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -9,6 +9,7 @@ using namespace Magick;
|
||||||
Napi::Value Tile(const Napi::CallbackInfo &info) {
|
Napi::Value Tile(const Napi::CallbackInfo &info) {
|
||||||
Napi::Env env = info.Env();
|
Napi::Env env = info.Env();
|
||||||
|
|
||||||
|
try {
|
||||||
Napi::Object obj = info[0].As<Napi::Object>();
|
Napi::Object obj = info[0].As<Napi::Object>();
|
||||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||||
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
||||||
|
@ -56,8 +57,11 @@ Napi::Value Tile(const Napi::CallbackInfo &info) {
|
||||||
writeImages(mid.begin(), mid.end(), &blob);
|
writeImages(mid.begin(), mid.end(), &blob);
|
||||||
|
|
||||||
Napi::Object result = Napi::Object::New(env);
|
Napi::Object result = Napi::Object::New(env);
|
||||||
result.Set("data",
|
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
|
||||||
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
|
blob.length()));
|
||||||
result.Set("type", type);
|
result.Set("type", type);
|
||||||
return result;
|
return result;
|
||||||
|
} catch (std::exception const &err) {
|
||||||
|
throw Napi::Error::New(env, err.what());
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -9,6 +9,7 @@ using namespace Magick;
|
||||||
Napi::Value Trump(const Napi::CallbackInfo &info) {
|
Napi::Value Trump(const Napi::CallbackInfo &info) {
|
||||||
Napi::Env env = info.Env();
|
Napi::Env env = info.Env();
|
||||||
|
|
||||||
|
try {
|
||||||
Napi::Object obj = info[0].As<Napi::Object>();
|
Napi::Object obj = info[0].As<Napi::Object>();
|
||||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||||
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
||||||
|
@ -53,8 +54,11 @@ Napi::Value Trump(const Napi::CallbackInfo &info) {
|
||||||
writeImages(mid.begin(), mid.end(), &blob);
|
writeImages(mid.begin(), mid.end(), &blob);
|
||||||
|
|
||||||
Napi::Object result = Napi::Object::New(env);
|
Napi::Object result = Napi::Object::New(env);
|
||||||
result.Set("data",
|
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
|
||||||
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
|
blob.length()));
|
||||||
result.Set("type", type);
|
result.Set("type", type);
|
||||||
return result;
|
return result;
|
||||||
|
} catch (std::exception const &err) {
|
||||||
|
throw Napi::Error::New(env, err.what());
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -9,6 +9,7 @@ using namespace Magick;
|
||||||
Napi::Value Wall(const Napi::CallbackInfo &info) {
|
Napi::Value Wall(const Napi::CallbackInfo &info) {
|
||||||
Napi::Env env = info.Env();
|
Napi::Env env = info.Env();
|
||||||
|
|
||||||
|
try {
|
||||||
Napi::Object obj = info[0].As<Napi::Object>();
|
Napi::Object obj = info[0].As<Napi::Object>();
|
||||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||||
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
||||||
|
@ -50,8 +51,11 @@ Napi::Value Wall(const Napi::CallbackInfo &info) {
|
||||||
writeImages(mid.begin(), mid.end(), &blob);
|
writeImages(mid.begin(), mid.end(), &blob);
|
||||||
|
|
||||||
Napi::Object result = Napi::Object::New(env);
|
Napi::Object result = Napi::Object::New(env);
|
||||||
result.Set("data",
|
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
|
||||||
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
|
blob.length()));
|
||||||
result.Set("type", type);
|
result.Set("type", type);
|
||||||
return result;
|
return result;
|
||||||
|
} catch (std::exception const &err) {
|
||||||
|
throw Napi::Error::New(env, err.what());
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -10,14 +10,17 @@ using namespace Magick;
|
||||||
Napi::Value Watermark(const Napi::CallbackInfo &info) {
|
Napi::Value Watermark(const Napi::CallbackInfo &info) {
|
||||||
Napi::Env env = info.Env();
|
Napi::Env env = info.Env();
|
||||||
|
|
||||||
|
try {
|
||||||
Napi::Object obj = info[0].As<Napi::Object>();
|
Napi::Object obj = info[0].As<Napi::Object>();
|
||||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||||
string water = obj.Get("water").As<Napi::String>().Utf8Value();
|
string water = obj.Get("water").As<Napi::String>().Utf8Value();
|
||||||
int gravity = obj.Get("gravity").As<Napi::Number>().Int32Value();
|
int gravity = obj.Get("gravity").As<Napi::Number>().Int32Value();
|
||||||
bool resize =
|
bool resize = obj.Has("resize")
|
||||||
obj.Has("resize") ? obj.Get("resize").As<Napi::Boolean>().Value() : false;
|
? obj.Get("resize").As<Napi::Boolean>().Value()
|
||||||
bool append =
|
: false;
|
||||||
obj.Has("append") ? obj.Get("append").As<Napi::Boolean>().Value() : false;
|
bool append = obj.Has("append")
|
||||||
|
? obj.Get("append").As<Napi::Boolean>().Value()
|
||||||
|
: false;
|
||||||
bool mc = obj.Has("mc") ? obj.Get("mc").As<Napi::Boolean>().Value() : false;
|
bool mc = obj.Has("mc") ? obj.Get("mc").As<Napi::Boolean>().Value() : false;
|
||||||
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
||||||
int delay =
|
int delay =
|
||||||
|
@ -76,8 +79,11 @@ Napi::Value Watermark(const Napi::CallbackInfo &info) {
|
||||||
writeImages(mid.begin(), mid.end(), &blob);
|
writeImages(mid.begin(), mid.end(), &blob);
|
||||||
|
|
||||||
Napi::Object result = Napi::Object::New(env);
|
Napi::Object result = Napi::Object::New(env);
|
||||||
result.Set("data",
|
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
|
||||||
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
|
blob.length()));
|
||||||
result.Set("type", type);
|
result.Set("type", type);
|
||||||
return result;
|
return result;
|
||||||
|
} catch (std::exception const &err) {
|
||||||
|
throw Napi::Error::New(env, err.what());
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -9,6 +9,7 @@ using namespace Magick;
|
||||||
Napi::Value Wdt(const Napi::CallbackInfo &info) {
|
Napi::Value Wdt(const Napi::CallbackInfo &info) {
|
||||||
Napi::Env env = info.Env();
|
Napi::Env env = info.Env();
|
||||||
|
|
||||||
|
try {
|
||||||
Napi::Object obj = info[0].As<Napi::Object>();
|
Napi::Object obj = info[0].As<Napi::Object>();
|
||||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||||
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
||||||
|
@ -47,8 +48,11 @@ Napi::Value Wdt(const Napi::CallbackInfo &info) {
|
||||||
writeImages(mid.begin(), mid.end(), &blob);
|
writeImages(mid.begin(), mid.end(), &blob);
|
||||||
|
|
||||||
Napi::Object result = Napi::Object::New(env);
|
Napi::Object result = Napi::Object::New(env);
|
||||||
result.Set("data",
|
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
|
||||||
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
|
blob.length()));
|
||||||
result.Set("type", type);
|
result.Set("type", type);
|
||||||
return result;
|
return result;
|
||||||
|
} catch (std::exception const &err) {
|
||||||
|
throw Napi::Error::New(env, err.what());
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue