Pass an image buffer into the native functions instead of a URL
This commit is contained in:
parent
666f9b9912
commit
61758fa3bb
33 changed files with 81 additions and 75 deletions
|
@ -11,7 +11,7 @@ Napi::Value Blur(const Napi::CallbackInfo &info) {
|
|||
|
||||
try {
|
||||
Napi::Object obj = info[0].As<Napi::Object>();
|
||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||
Napi::Buffer<char> data = obj.Get("data").As<Napi::Buffer<char>>();
|
||||
bool sharp = obj.Get("sharp").As<Napi::Boolean>().Value();
|
||||
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
||||
int delay =
|
||||
|
@ -21,7 +21,7 @@ Napi::Value Blur(const Napi::CallbackInfo &info) {
|
|||
|
||||
list<Image> frames;
|
||||
list<Image> coalesced;
|
||||
readImages(&frames, path);
|
||||
readImages(&frames, Blob(data.Data(), data.Length()));
|
||||
coalesceImages(&coalesced, frames.begin(), frames.end());
|
||||
|
||||
if (sharp) {
|
||||
|
|
|
@ -11,7 +11,7 @@ Napi::Value Blurple(const Napi::CallbackInfo &info) {
|
|||
|
||||
try {
|
||||
Napi::Object obj = info[0].As<Napi::Object>();
|
||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||
Napi::Buffer<char> data = obj.Get("data").As<Napi::Buffer<char>>();
|
||||
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
||||
int delay =
|
||||
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
|
||||
|
@ -21,7 +21,7 @@ Napi::Value Blurple(const Napi::CallbackInfo &info) {
|
|||
list<Image> frames;
|
||||
list<Image> coalesced;
|
||||
list<Image> blurpled;
|
||||
readImages(&frames, path);
|
||||
readImages(&frames, Blob(data.Data(), data.Length()));
|
||||
coalesceImages(&coalesced, frames.begin(), frames.end());
|
||||
|
||||
for (Image &image : coalesced) {
|
||||
|
|
|
@ -11,7 +11,7 @@ Napi::Value Caption(const Napi::CallbackInfo &info) {
|
|||
|
||||
try {
|
||||
Napi::Object obj = info[0].As<Napi::Object>();
|
||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||
Napi::Buffer<char> data = obj.Get("data").As<Napi::Buffer<char>>();
|
||||
string caption = obj.Get("caption").As<Napi::String>().Utf8Value();
|
||||
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
||||
int delay =
|
||||
|
@ -22,7 +22,7 @@ Napi::Value Caption(const Napi::CallbackInfo &info) {
|
|||
list<Image> frames;
|
||||
list<Image> coalesced;
|
||||
list<Image> captioned;
|
||||
readImages(&frames, path);
|
||||
readImages(&frames, Blob(data.Data(), data.Length()));
|
||||
|
||||
size_t width = frames.front().baseColumns();
|
||||
string query(to_string(width - ((width / 25) * 2)) + "x");
|
||||
|
|
|
@ -11,7 +11,7 @@ Napi::Value CaptionTwo(const Napi::CallbackInfo &info) {
|
|||
|
||||
try {
|
||||
Napi::Object obj = info[0].As<Napi::Object>();
|
||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||
Napi::Buffer<char> data = obj.Get("data").As<Napi::Buffer<char>>();
|
||||
string caption = obj.Get("caption").As<Napi::String>().Utf8Value();
|
||||
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
||||
int delay =
|
||||
|
@ -23,7 +23,7 @@ Napi::Value CaptionTwo(const Napi::CallbackInfo &info) {
|
|||
list<Image> coalesced;
|
||||
list<Image> captioned;
|
||||
Blob caption_blob;
|
||||
readImages(&frames, path);
|
||||
readImages(&frames, Blob(data.Data(), data.Length()));
|
||||
|
||||
size_t width = frames.front().baseColumns();
|
||||
string query(to_string(width - ((width / 25) * 2)) + "x");
|
||||
|
|
|
@ -11,7 +11,7 @@ Napi::Value Circle(const Napi::CallbackInfo &info) {
|
|||
|
||||
try {
|
||||
Napi::Object obj = info[0].As<Napi::Object>();
|
||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||
Napi::Buffer<char> data = obj.Get("data").As<Napi::Buffer<char>>();
|
||||
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
||||
int delay =
|
||||
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
|
||||
|
@ -21,7 +21,7 @@ Napi::Value Circle(const Napi::CallbackInfo &info) {
|
|||
list<Image> frames;
|
||||
list<Image> coalesced;
|
||||
list<Image> blurred;
|
||||
readImages(&frames, path);
|
||||
readImages(&frames, Blob(data.Data(), data.Length()));
|
||||
coalesceImages(&coalesced, frames.begin(), frames.end());
|
||||
|
||||
for (Image &image : coalesced) {
|
||||
|
|
|
@ -11,7 +11,7 @@ Napi::Value Crop(const Napi::CallbackInfo &info) {
|
|||
|
||||
try {
|
||||
Napi::Object obj = info[0].As<Napi::Object>();
|
||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||
Napi::Buffer<char> data = obj.Get("data").As<Napi::Buffer<char>>();
|
||||
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
||||
int delay =
|
||||
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
|
||||
|
@ -21,7 +21,7 @@ Napi::Value Crop(const Napi::CallbackInfo &info) {
|
|||
list<Image> frames;
|
||||
list<Image> coalesced;
|
||||
list<Image> mid;
|
||||
readImages(&frames, path);
|
||||
readImages(&frames, Blob(data.Data(), data.Length()));
|
||||
coalesceImages(&coalesced, frames.begin(), frames.end());
|
||||
|
||||
for (Image &image : coalesced) {
|
||||
|
|
|
@ -11,7 +11,7 @@ Napi::Value Explode(const Napi::CallbackInfo &info) {
|
|||
|
||||
try {
|
||||
Napi::Object obj = info[0].As<Napi::Object>();
|
||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||
Napi::Buffer<char> data = obj.Get("data").As<Napi::Buffer<char>>();
|
||||
int amount = obj.Get("amount").As<Napi::Number>().Int32Value();
|
||||
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
||||
int delay =
|
||||
|
@ -22,7 +22,7 @@ Napi::Value Explode(const Napi::CallbackInfo &info) {
|
|||
list<Image> frames;
|
||||
list<Image> coalesced;
|
||||
list<Image> blurred;
|
||||
readImages(&frames, path);
|
||||
readImages(&frames, Blob(data.Data(), data.Length()));
|
||||
coalesceImages(&coalesced, frames.begin(), frames.end());
|
||||
|
||||
for (Image &image : coalesced) {
|
||||
|
|
|
@ -11,7 +11,7 @@ Napi::Value Flag(const Napi::CallbackInfo &info) {
|
|||
|
||||
try {
|
||||
Napi::Object obj = info[0].As<Napi::Object>();
|
||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||
Napi::Buffer<char> data = obj.Get("data").As<Napi::Buffer<char>>();
|
||||
string overlay = obj.Get("overlay").As<Napi::String>().Utf8Value();
|
||||
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
||||
int delay =
|
||||
|
@ -23,7 +23,7 @@ Napi::Value Flag(const Napi::CallbackInfo &info) {
|
|||
list<Image> coalesced;
|
||||
list<Image> mid;
|
||||
Image watermark;
|
||||
readImages(&frames, path);
|
||||
readImages(&frames, Blob(data.Data(), data.Length()));
|
||||
watermark.read(overlay);
|
||||
watermark.alphaChannel(Magick::SetAlphaChannel);
|
||||
watermark.evaluate(Magick::AlphaChannel, Magick::MultiplyEvaluateOperator,
|
||||
|
|
|
@ -11,7 +11,7 @@ Napi::Value Flip(const Napi::CallbackInfo &info) {
|
|||
|
||||
try {
|
||||
Napi::Object obj = info[0].As<Napi::Object>();
|
||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||
Napi::Buffer<char> data = obj.Get("data").As<Napi::Buffer<char>>();
|
||||
bool flop =
|
||||
obj.Has("flop") ? obj.Get("flop").As<Napi::Boolean>().Value() : false;
|
||||
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
||||
|
@ -23,7 +23,7 @@ Napi::Value Flip(const Napi::CallbackInfo &info) {
|
|||
list<Image> frames;
|
||||
list<Image> coalesced;
|
||||
list<Image> mid;
|
||||
readImages(&frames, path);
|
||||
readImages(&frames, Blob(data.Data(), data.Length()));
|
||||
coalesceImages(&coalesced, frames.begin(), frames.end());
|
||||
|
||||
for (Image &image : coalesced) {
|
||||
|
|
|
@ -11,7 +11,7 @@ Napi::Value Freeze(const Napi::CallbackInfo &info) {
|
|||
|
||||
try {
|
||||
Napi::Object obj = info[0].As<Napi::Object>();
|
||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||
Napi::Buffer<char> data = obj.Get("data").As<Napi::Buffer<char>>();
|
||||
bool loop =
|
||||
obj.Has("loop") ? obj.Get("loop").As<Napi::Boolean>().Value() : false;
|
||||
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
||||
|
@ -24,7 +24,7 @@ Napi::Value Freeze(const Napi::CallbackInfo &info) {
|
|||
Blob blob;
|
||||
|
||||
list<Image> frames;
|
||||
readImages(&frames, path);
|
||||
readImages(&frames, Blob(data.Data(), data.Length()));
|
||||
|
||||
if (frame >= 0 && !loop) {
|
||||
size_t frameSize = frames.size();
|
||||
|
|
|
@ -11,7 +11,7 @@ Napi::Value Gamexplain(const Napi::CallbackInfo &info) {
|
|||
|
||||
try {
|
||||
Napi::Object obj = info[0].As<Napi::Object>();
|
||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||
Napi::Buffer<char> data = obj.Get("data").As<Napi::Buffer<char>>();
|
||||
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
||||
int delay =
|
||||
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
|
||||
|
@ -22,7 +22,7 @@ Napi::Value Gamexplain(const Napi::CallbackInfo &info) {
|
|||
list<Image> coalesced;
|
||||
list<Image> mid;
|
||||
Image watermark;
|
||||
readImages(&frames, path);
|
||||
readImages(&frames, Blob(data.Data(), data.Length()));
|
||||
watermark.read("./assets/images/gamexplain.png");
|
||||
coalesceImages(&coalesced, frames.begin(), frames.end());
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ Napi::Value Globe(const Napi::CallbackInfo &info) {
|
|||
|
||||
try {
|
||||
Napi::Object obj = info[0].As<Napi::Object>();
|
||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||
Napi::Buffer<char> data = obj.Get("data").As<Napi::Buffer<char>>();
|
||||
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
||||
int delay =
|
||||
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
|
||||
|
@ -23,7 +23,7 @@ Napi::Value Globe(const Napi::CallbackInfo &info) {
|
|||
list<Image> mid;
|
||||
Image distort;
|
||||
Image overlay;
|
||||
readImages(&frames, path);
|
||||
readImages(&frames, Blob(data.Data(), data.Length()));
|
||||
distort.read("./assets/images/spheremap.png");
|
||||
overlay.read("./assets/images/sphere_overlay.png");
|
||||
coalesceImages(&coalesced, frames.begin(), frames.end());
|
||||
|
|
|
@ -11,7 +11,7 @@ Napi::Value Invert(const Napi::CallbackInfo &info) {
|
|||
|
||||
try {
|
||||
Napi::Object obj = info[0].As<Napi::Object>();
|
||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||
Napi::Buffer<char> data = obj.Get("data").As<Napi::Buffer<char>>();
|
||||
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
||||
int delay =
|
||||
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
|
||||
|
@ -21,7 +21,7 @@ Napi::Value Invert(const Napi::CallbackInfo &info) {
|
|||
list<Image> frames;
|
||||
list<Image> coalesced;
|
||||
list<Image> mid;
|
||||
readImages(&frames, path);
|
||||
readImages(&frames, Blob(data.Data(), data.Length()));
|
||||
coalesceImages(&coalesced, frames.begin(), frames.end());
|
||||
|
||||
for_each(coalesced.begin(), coalesced.end(), negateImage());
|
||||
|
|
|
@ -11,12 +11,12 @@ Napi::Value Jpeg(const Napi::CallbackInfo &info) {
|
|||
|
||||
try {
|
||||
Napi::Object obj = info[0].As<Napi::Object>();
|
||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||
Napi::Buffer<char> data = obj.Get("data").As<Napi::Buffer<char>>();
|
||||
|
||||
Blob blob;
|
||||
|
||||
Image image;
|
||||
image.read(path);
|
||||
image.read(Blob(data.Data(), data.Length()));
|
||||
image.quality(1);
|
||||
image.magick("JPEG");
|
||||
image.write(&blob);
|
||||
|
|
|
@ -11,7 +11,7 @@ Napi::Value Leak(const Napi::CallbackInfo &info) {
|
|||
|
||||
try {
|
||||
Napi::Object obj = info[0].As<Napi::Object>();
|
||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||
Napi::Buffer<char> data = obj.Get("data").As<Napi::Buffer<char>>();
|
||||
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
||||
int delay =
|
||||
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
|
||||
|
@ -22,7 +22,7 @@ Napi::Value Leak(const Napi::CallbackInfo &info) {
|
|||
list<Image> coalesced;
|
||||
list<Image> mid;
|
||||
Image watermark;
|
||||
readImages(&frames, path);
|
||||
readImages(&frames, Blob(data.Data(), data.Length()));
|
||||
watermark.read("./assets/images/leak.png");
|
||||
coalesceImages(&coalesced, frames.begin(), frames.end());
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ Napi::Value Magik(const Napi::CallbackInfo &info) {
|
|||
|
||||
try {
|
||||
Napi::Object obj = info[0].As<Napi::Object>();
|
||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||
Napi::Buffer<char> data = obj.Get("data").As<Napi::Buffer<char>>();
|
||||
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
||||
int delay =
|
||||
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
|
||||
|
@ -21,7 +21,7 @@ Napi::Value Magik(const Napi::CallbackInfo &info) {
|
|||
list<Image> frames;
|
||||
list<Image> coalesced;
|
||||
list<Image> blurred;
|
||||
readImages(&frames, path);
|
||||
readImages(&frames, Blob(data.Data(), data.Length()));
|
||||
coalesceImages(&coalesced, frames.begin(), frames.end());
|
||||
|
||||
for (Image &image : coalesced) {
|
||||
|
|
|
@ -11,7 +11,7 @@ Napi::Value Meme(const Napi::CallbackInfo &info) {
|
|||
|
||||
try {
|
||||
Napi::Object obj = info[0].As<Napi::Object>();
|
||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||
Napi::Buffer<char> data = obj.Get("data").As<Napi::Buffer<char>>();
|
||||
string top = obj.Get("top").As<Napi::String>().Utf8Value();
|
||||
string bottom = obj.Get("bottom").As<Napi::String>().Utf8Value();
|
||||
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
||||
|
@ -25,7 +25,7 @@ Napi::Value Meme(const Napi::CallbackInfo &info) {
|
|||
list<Image> mid;
|
||||
Image top_text;
|
||||
Image bottom_text;
|
||||
readImages(&frames, path);
|
||||
readImages(&frames, Blob(data.Data(), data.Length()));
|
||||
coalesceImages(&coalesced, frames.begin(), frames.end());
|
||||
for_each(coalesced.begin(), coalesced.end(),
|
||||
scaleImage(Geometry(600, 600)));
|
||||
|
|
|
@ -11,7 +11,7 @@ Napi::Value Mirror(const Napi::CallbackInfo &info) {
|
|||
|
||||
try {
|
||||
Napi::Object obj = info[0].As<Napi::Object>();
|
||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||
Napi::Buffer<char> data = obj.Get("data").As<Napi::Buffer<char>>();
|
||||
bool vertical = obj.Has("vertical")
|
||||
? obj.Get("vertical").As<Napi::Boolean>().Value()
|
||||
: false;
|
||||
|
@ -27,7 +27,7 @@ Napi::Value Mirror(const Napi::CallbackInfo &info) {
|
|||
list<Image> coalesced;
|
||||
list<Image> mid;
|
||||
MagickCore::GravityType gravity;
|
||||
readImages(&frames, path);
|
||||
readImages(&frames, Blob(data.Data(), data.Length()));
|
||||
coalesceImages(&coalesced, frames.begin(), frames.end());
|
||||
|
||||
if (vertical && first) {
|
||||
|
|
|
@ -11,7 +11,7 @@ Napi::Value Motivate(const Napi::CallbackInfo &info) {
|
|||
|
||||
try {
|
||||
Napi::Object obj = info[0].As<Napi::Object>();
|
||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||
Napi::Buffer<char> data = obj.Get("data").As<Napi::Buffer<char>>();
|
||||
string top_text = obj.Get("top").As<Napi::String>().Utf8Value();
|
||||
string bottom_text = obj.Get("bottom").As<Napi::String>().Utf8Value();
|
||||
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
||||
|
@ -25,7 +25,7 @@ Napi::Value Motivate(const Napi::CallbackInfo &info) {
|
|||
list<Image> mid;
|
||||
Image top;
|
||||
Image bottom;
|
||||
readImages(&frames, path);
|
||||
readImages(&frames, Blob(data.Data(), data.Length()));
|
||||
coalesceImages(&coalesced, frames.begin(), frames.end());
|
||||
|
||||
top.size(Geometry("600"));
|
||||
|
|
|
@ -10,7 +10,7 @@ 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();
|
||||
Napi::Buffer<char> data = obj.Get("data").As<Napi::Buffer<char>>();
|
||||
string text = obj.Get("caption").As<Napi::String>().Utf8Value();
|
||||
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
||||
int delay =
|
||||
|
@ -23,7 +23,7 @@ Napi::Value Reddit(const Napi::CallbackInfo &info) {
|
|||
list<Image> mid;
|
||||
Image watermark;
|
||||
Image text_image;
|
||||
readImages(&frames, path);
|
||||
readImages(&frames, Blob(data.Data(), data.Length()));
|
||||
|
||||
watermark.read("./assets/images/reddit.png");
|
||||
text_image.textGravity(Magick::WestGravity);
|
||||
|
|
|
@ -11,7 +11,7 @@ Napi::Value Resize(const Napi::CallbackInfo &info) {
|
|||
|
||||
try {
|
||||
Napi::Object obj = info[0].As<Napi::Object>();
|
||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||
Napi::Buffer<char> data = obj.Get("data").As<Napi::Buffer<char>>();
|
||||
bool stretch = obj.Has("stretch")
|
||||
? obj.Get("stretch").As<Napi::Boolean>().Value()
|
||||
: false;
|
||||
|
@ -26,7 +26,7 @@ Napi::Value Resize(const Napi::CallbackInfo &info) {
|
|||
list<Image> frames;
|
||||
list<Image> coalesced;
|
||||
list<Image> blurred;
|
||||
readImages(&frames, path);
|
||||
readImages(&frames, Blob(data.Data(), data.Length()));
|
||||
coalesceImages(&coalesced, frames.begin(), frames.end());
|
||||
|
||||
for (Image &image : coalesced) {
|
||||
|
|
|
@ -11,7 +11,7 @@ Napi::Value Reverse(const Napi::CallbackInfo &info) {
|
|||
|
||||
try {
|
||||
Napi::Object obj = info[0].As<Napi::Object>();
|
||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||
Napi::Buffer<char> data = obj.Get("data").As<Napi::Buffer<char>>();
|
||||
bool soos =
|
||||
obj.Has("soos") ? obj.Get("soos").As<Napi::Boolean>().Value() : false;
|
||||
int delay =
|
||||
|
@ -21,7 +21,7 @@ Napi::Value Reverse(const Napi::CallbackInfo &info) {
|
|||
|
||||
list<Image> frames;
|
||||
list<Image> coalesced;
|
||||
readImages(&frames, path);
|
||||
readImages(&frames, Blob(data.Data(), data.Length()));
|
||||
coalesceImages(&coalesced, frames.begin(), frames.end());
|
||||
|
||||
if (soos) {
|
||||
|
|
|
@ -11,7 +11,7 @@ Napi::Value Scott(const Napi::CallbackInfo &info) {
|
|||
|
||||
try {
|
||||
Napi::Object obj = info[0].As<Napi::Object>();
|
||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||
Napi::Buffer<char> data = obj.Get("data").As<Napi::Buffer<char>>();
|
||||
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
||||
int delay =
|
||||
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
|
||||
|
@ -22,7 +22,7 @@ Napi::Value Scott(const Napi::CallbackInfo &info) {
|
|||
list<Image> coalesced;
|
||||
list<Image> mid;
|
||||
Image watermark;
|
||||
readImages(&frames, path);
|
||||
readImages(&frames, Blob(data.Data(), data.Length()));
|
||||
watermark.read("./assets/images/scott.png");
|
||||
coalesceImages(&coalesced, frames.begin(), frames.end());
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ Napi::Value Speed(const Napi::CallbackInfo &info) {
|
|||
|
||||
try {
|
||||
Napi::Object obj = info[0].As<Napi::Object>();
|
||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||
Napi::Buffer<char> data = obj.Get("data").As<Napi::Buffer<char>>();
|
||||
bool slow =
|
||||
obj.Has("slow") ? obj.Get("slow").As<Napi::Boolean>().Value() : false;
|
||||
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
||||
|
@ -23,7 +23,7 @@ Napi::Value Speed(const Napi::CallbackInfo &info) {
|
|||
Blob blob;
|
||||
|
||||
list<Image> frames;
|
||||
readImages(&frames, path);
|
||||
readImages(&frames, Blob(data.Data(), data.Length()));
|
||||
|
||||
// if passed a delay, use that. otherwise use the average frame delay.
|
||||
if (delay == 0) {
|
||||
|
|
|
@ -11,7 +11,7 @@ Napi::Value Spin(const Napi::CallbackInfo &info) {
|
|||
|
||||
try {
|
||||
Napi::Object obj = info[0].As<Napi::Object>();
|
||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||
Napi::Buffer<char> data = obj.Get("data").As<Napi::Buffer<char>>();
|
||||
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
||||
int delay =
|
||||
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
|
||||
|
@ -21,7 +21,7 @@ Napi::Value Spin(const Napi::CallbackInfo &info) {
|
|||
list<Image> frames;
|
||||
list<Image> coalesced;
|
||||
list<Image> mid;
|
||||
readImages(&frames, path);
|
||||
readImages(&frames, Blob(data.Data(), data.Length()));
|
||||
coalesceImages(&coalesced, frames.begin(), frames.end());
|
||||
|
||||
if (type != "gif") {
|
||||
|
|
|
@ -11,7 +11,7 @@ Napi::Value Swirl(const Napi::CallbackInfo &info) {
|
|||
|
||||
try {
|
||||
Napi::Object obj = info[0].As<Napi::Object>();
|
||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||
Napi::Buffer<char> data = obj.Get("data").As<Napi::Buffer<char>>();
|
||||
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
||||
int delay =
|
||||
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
|
||||
|
@ -21,7 +21,7 @@ Napi::Value Swirl(const Napi::CallbackInfo &info) {
|
|||
list<Image> frames;
|
||||
list<Image> coalesced;
|
||||
list<Image> mid;
|
||||
readImages(&frames, path);
|
||||
readImages(&frames, Blob(data.Data(), data.Length()));
|
||||
coalesceImages(&coalesced, frames.begin(), frames.end());
|
||||
|
||||
for (Image &image : coalesced) {
|
||||
|
|
|
@ -11,7 +11,7 @@ Napi::Value Tile(const Napi::CallbackInfo &info) {
|
|||
|
||||
try {
|
||||
Napi::Object obj = info[0].As<Napi::Object>();
|
||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||
Napi::Buffer<char> data = obj.Get("data").As<Napi::Buffer<char>>();
|
||||
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
||||
int delay =
|
||||
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
|
||||
|
@ -21,7 +21,7 @@ Napi::Value Tile(const Napi::CallbackInfo &info) {
|
|||
list<Image> frames;
|
||||
list<Image> coalesced;
|
||||
list<Image> mid;
|
||||
readImages(&frames, path);
|
||||
readImages(&frames, Blob(data.Data(), data.Length()));
|
||||
coalesceImages(&coalesced, frames.begin(), frames.end());
|
||||
|
||||
for (Image &image : coalesced) {
|
||||
|
|
|
@ -11,7 +11,7 @@ Napi::Value Trump(const Napi::CallbackInfo &info) {
|
|||
|
||||
try {
|
||||
Napi::Object obj = info[0].As<Napi::Object>();
|
||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||
Napi::Buffer<char> data = obj.Get("data").As<Napi::Buffer<char>>();
|
||||
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
||||
int delay =
|
||||
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
|
||||
|
@ -22,7 +22,7 @@ Napi::Value Trump(const Napi::CallbackInfo &info) {
|
|||
list<Image> coalesced;
|
||||
list<Image> mid;
|
||||
Image watermark;
|
||||
readImages(&frames, path);
|
||||
readImages(&frames, Blob(data.Data(), data.Length()));
|
||||
watermark.read("./assets/images/trump.png");
|
||||
coalesceImages(&coalesced, frames.begin(), frames.end());
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ Napi::Value Uncaption(const Napi::CallbackInfo &info) {
|
|||
|
||||
try {
|
||||
Napi::Object obj = info[0].As<Napi::Object>();
|
||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||
Napi::Buffer<char> data = obj.Get("data").As<Napi::Buffer<char>>();
|
||||
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
||||
int delay =
|
||||
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
|
||||
|
@ -44,7 +44,7 @@ Napi::Value Uncaption(const Napi::CallbackInfo &info) {
|
|||
list<Image> frames;
|
||||
list<Image> coalesced;
|
||||
list<Image> mid;
|
||||
readImages(&frames, path);
|
||||
readImages(&frames, Blob(data.Data(), data.Length()));
|
||||
coalesceImages(&coalesced, frames.begin(), frames.end());
|
||||
|
||||
Image firstImage = coalesced.front();
|
||||
|
|
|
@ -11,7 +11,7 @@ Napi::Value Wall(const Napi::CallbackInfo &info) {
|
|||
|
||||
try {
|
||||
Napi::Object obj = info[0].As<Napi::Object>();
|
||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||
Napi::Buffer<char> data = obj.Get("data").As<Napi::Buffer<char>>();
|
||||
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
||||
int delay =
|
||||
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
|
||||
|
@ -21,7 +21,7 @@ Napi::Value Wall(const Napi::CallbackInfo &info) {
|
|||
list<Image> frames;
|
||||
list<Image> coalesced;
|
||||
list<Image> mid;
|
||||
readImages(&frames, path);
|
||||
readImages(&frames, Blob(data.Data(), data.Length()));
|
||||
coalesceImages(&coalesced, frames.begin(), frames.end());
|
||||
|
||||
for (Image &image : coalesced) {
|
||||
|
|
|
@ -12,7 +12,7 @@ Napi::Value Watermark(const Napi::CallbackInfo &info) {
|
|||
|
||||
try {
|
||||
Napi::Object obj = info[0].As<Napi::Object>();
|
||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||
Napi::Buffer<char> data = obj.Get("data").As<Napi::Buffer<char>>();
|
||||
string water = obj.Get("water").As<Napi::String>().Utf8Value();
|
||||
int gravity = obj.Get("gravity").As<Napi::Number>().Int32Value();
|
||||
bool resize = obj.Has("resize")
|
||||
|
@ -32,7 +32,7 @@ Napi::Value Watermark(const Napi::CallbackInfo &info) {
|
|||
list<Image> coalesced;
|
||||
list<Image> mid;
|
||||
Image watermark;
|
||||
readImages(&frames, path);
|
||||
readImages(&frames, Blob(data.Data(), data.Length()));
|
||||
watermark.read(water);
|
||||
if (resize && append) {
|
||||
string query(to_string(frames.front().baseColumns()) + "x");
|
||||
|
|
|
@ -11,7 +11,7 @@ Napi::Value Wdt(const Napi::CallbackInfo &info) {
|
|||
|
||||
try {
|
||||
Napi::Object obj = info[0].As<Napi::Object>();
|
||||
string path = obj.Get("path").As<Napi::String>().Utf8Value();
|
||||
Napi::Buffer<char> data = obj.Get("data").As<Napi::Buffer<char>>();
|
||||
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
||||
int delay =
|
||||
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
|
||||
|
@ -22,7 +22,7 @@ Napi::Value Wdt(const Napi::CallbackInfo &info) {
|
|||
list<Image> coalesced;
|
||||
list<Image> mid;
|
||||
Image watermark;
|
||||
readImages(&frames, path);
|
||||
readImages(&frames, Blob(data.Data(), data.Length()));
|
||||
watermark.read("./assets/images/whodidthis.png");
|
||||
coalesceImages(&coalesced, frames.begin(), frames.end());
|
||||
|
||||
|
|
|
@ -1,19 +1,24 @@
|
|||
const magick = require("../build/Release/image.node");
|
||||
const { isMainThread, parentPort, workerData } = require("worker_threads");
|
||||
const fetch = require("node-fetch");
|
||||
|
||||
exports.run = object => {
|
||||
return new Promise((resolve, reject) => {
|
||||
// If the image has a path, it must also have a type
|
||||
let promise = new Promise((resolveTest) => { resolveTest(); }); // no-op
|
||||
if (object.path) {
|
||||
if (object.type !== "image/gif" && object.onlyGIF) resolve({
|
||||
buffer: Buffer.alloc(0),
|
||||
fileExtension: "nogif"
|
||||
});
|
||||
promise = fetch(object.path).then(res => res.buffer());
|
||||
}
|
||||
// Convert from a MIME type (e.g. "image/png") to something ImageMagick understands (e.g. "png").
|
||||
// Don't set `type` directly on the object we are passed as it will be read afterwards.
|
||||
// If no image type is given (say, the command generates its own image), make it a PNG.
|
||||
const fileExtension = object.type ? object.type.split("/")[1] : "png";
|
||||
promise.then(buf => {
|
||||
object.data = buf;
|
||||
const objectWithFixedType = Object.assign({}, object, {type: fileExtension});
|
||||
try {
|
||||
const result = magick[object.cmd](objectWithFixedType);
|
||||
|
@ -26,6 +31,7 @@ exports.run = object => {
|
|||
reject(e);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
if (!isMainThread) {
|
||||
|
|
Loading…
Reference in a new issue