From 61758fa3bb57faa92633dfc34ab5e0925ef73e7a Mon Sep 17 00:00:00 2001 From: TheEssem Date: Tue, 11 May 2021 14:25:02 -0500 Subject: [PATCH] Pass an image buffer into the native functions instead of a URL --- natives/blur.cc | 4 ++-- natives/blurple.cc | 4 ++-- natives/caption.cc | 4 ++-- natives/caption2.cc | 4 ++-- natives/circle.cc | 4 ++-- natives/crop.cc | 4 ++-- natives/explode.cc | 4 ++-- natives/flag.cc | 4 ++-- natives/flip.cc | 4 ++-- natives/freeze.cc | 4 ++-- natives/gamexplain.cc | 4 ++-- natives/globe.cc | 4 ++-- natives/invert.cc | 4 ++-- natives/jpeg.cc | 4 ++-- natives/leak.cc | 4 ++-- natives/magik.cc | 4 ++-- natives/meme.cc | 4 ++-- natives/mirror.cc | 4 ++-- natives/motivate.cc | 4 ++-- natives/reddit.cc | 4 ++-- natives/resize.cc | 4 ++-- natives/reverse.cc | 4 ++-- natives/scott.cc | 4 ++-- natives/speed.cc | 4 ++-- natives/spin.cc | 4 ++-- natives/swirl.cc | 4 ++-- natives/tile.cc | 4 ++-- natives/trump.cc | 4 ++-- natives/uncaption.cc | 4 ++-- natives/wall.cc | 4 ++-- natives/watermark.cc | 4 ++-- natives/wdt.cc | 4 ++-- utils/image-runner.js | 28 +++++++++++++++++----------- 33 files changed, 81 insertions(+), 75 deletions(-) diff --git a/natives/blur.cc b/natives/blur.cc index 74eef2c..b9d6f83 100644 --- a/natives/blur.cc +++ b/natives/blur.cc @@ -11,7 +11,7 @@ Napi::Value Blur(const Napi::CallbackInfo &info) { try { Napi::Object obj = info[0].As(); - string path = obj.Get("path").As().Utf8Value(); + Napi::Buffer data = obj.Get("data").As>(); bool sharp = obj.Get("sharp").As().Value(); string type = obj.Get("type").As().Utf8Value(); int delay = @@ -21,7 +21,7 @@ Napi::Value Blur(const Napi::CallbackInfo &info) { list frames; list coalesced; - readImages(&frames, path); + readImages(&frames, Blob(data.Data(), data.Length())); coalesceImages(&coalesced, frames.begin(), frames.end()); if (sharp) { diff --git a/natives/blurple.cc b/natives/blurple.cc index bd044e4..0f9a4df 100644 --- a/natives/blurple.cc +++ b/natives/blurple.cc @@ -11,7 +11,7 @@ Napi::Value Blurple(const Napi::CallbackInfo &info) { try { Napi::Object obj = info[0].As(); - string path = obj.Get("path").As().Utf8Value(); + Napi::Buffer data = obj.Get("data").As>(); string type = obj.Get("type").As().Utf8Value(); int delay = obj.Has("delay") ? obj.Get("delay").As().Int32Value() : 0; @@ -21,7 +21,7 @@ Napi::Value Blurple(const Napi::CallbackInfo &info) { list frames; list coalesced; list blurpled; - readImages(&frames, path); + readImages(&frames, Blob(data.Data(), data.Length())); coalesceImages(&coalesced, frames.begin(), frames.end()); for (Image &image : coalesced) { diff --git a/natives/caption.cc b/natives/caption.cc index c50e296..49b6df0 100644 --- a/natives/caption.cc +++ b/natives/caption.cc @@ -11,7 +11,7 @@ Napi::Value Caption(const Napi::CallbackInfo &info) { try { Napi::Object obj = info[0].As(); - string path = obj.Get("path").As().Utf8Value(); + Napi::Buffer data = obj.Get("data").As>(); string caption = obj.Get("caption").As().Utf8Value(); string type = obj.Get("type").As().Utf8Value(); int delay = @@ -22,7 +22,7 @@ Napi::Value Caption(const Napi::CallbackInfo &info) { list frames; list coalesced; list 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"); diff --git a/natives/caption2.cc b/natives/caption2.cc index acf7965..2677141 100644 --- a/natives/caption2.cc +++ b/natives/caption2.cc @@ -11,7 +11,7 @@ Napi::Value CaptionTwo(const Napi::CallbackInfo &info) { try { Napi::Object obj = info[0].As(); - string path = obj.Get("path").As().Utf8Value(); + Napi::Buffer data = obj.Get("data").As>(); string caption = obj.Get("caption").As().Utf8Value(); string type = obj.Get("type").As().Utf8Value(); int delay = @@ -23,7 +23,7 @@ Napi::Value CaptionTwo(const Napi::CallbackInfo &info) { list coalesced; list 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"); diff --git a/natives/circle.cc b/natives/circle.cc index c5f51be..058caad 100644 --- a/natives/circle.cc +++ b/natives/circle.cc @@ -11,7 +11,7 @@ Napi::Value Circle(const Napi::CallbackInfo &info) { try { Napi::Object obj = info[0].As(); - string path = obj.Get("path").As().Utf8Value(); + Napi::Buffer data = obj.Get("data").As>(); string type = obj.Get("type").As().Utf8Value(); int delay = obj.Has("delay") ? obj.Get("delay").As().Int32Value() : 0; @@ -21,7 +21,7 @@ Napi::Value Circle(const Napi::CallbackInfo &info) { list frames; list coalesced; list blurred; - readImages(&frames, path); + readImages(&frames, Blob(data.Data(), data.Length())); coalesceImages(&coalesced, frames.begin(), frames.end()); for (Image &image : coalesced) { diff --git a/natives/crop.cc b/natives/crop.cc index 5ee14f8..f5e7bb9 100644 --- a/natives/crop.cc +++ b/natives/crop.cc @@ -11,7 +11,7 @@ Napi::Value Crop(const Napi::CallbackInfo &info) { try { Napi::Object obj = info[0].As(); - string path = obj.Get("path").As().Utf8Value(); + Napi::Buffer data = obj.Get("data").As>(); string type = obj.Get("type").As().Utf8Value(); int delay = obj.Has("delay") ? obj.Get("delay").As().Int32Value() : 0; @@ -21,7 +21,7 @@ Napi::Value Crop(const Napi::CallbackInfo &info) { list frames; list coalesced; list mid; - readImages(&frames, path); + readImages(&frames, Blob(data.Data(), data.Length())); coalesceImages(&coalesced, frames.begin(), frames.end()); for (Image &image : coalesced) { diff --git a/natives/explode.cc b/natives/explode.cc index 0a386ec..7385783 100644 --- a/natives/explode.cc +++ b/natives/explode.cc @@ -11,7 +11,7 @@ Napi::Value Explode(const Napi::CallbackInfo &info) { try { Napi::Object obj = info[0].As(); - string path = obj.Get("path").As().Utf8Value(); + Napi::Buffer data = obj.Get("data").As>(); int amount = obj.Get("amount").As().Int32Value(); string type = obj.Get("type").As().Utf8Value(); int delay = @@ -22,7 +22,7 @@ Napi::Value Explode(const Napi::CallbackInfo &info) { list frames; list coalesced; list blurred; - readImages(&frames, path); + readImages(&frames, Blob(data.Data(), data.Length())); coalesceImages(&coalesced, frames.begin(), frames.end()); for (Image &image : coalesced) { diff --git a/natives/flag.cc b/natives/flag.cc index 8d039b0..8daf0e8 100644 --- a/natives/flag.cc +++ b/natives/flag.cc @@ -11,7 +11,7 @@ Napi::Value Flag(const Napi::CallbackInfo &info) { try { Napi::Object obj = info[0].As(); - string path = obj.Get("path").As().Utf8Value(); + Napi::Buffer data = obj.Get("data").As>(); string overlay = obj.Get("overlay").As().Utf8Value(); string type = obj.Get("type").As().Utf8Value(); int delay = @@ -23,7 +23,7 @@ Napi::Value Flag(const Napi::CallbackInfo &info) { list coalesced; list 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, diff --git a/natives/flip.cc b/natives/flip.cc index f07d461..630ac23 100644 --- a/natives/flip.cc +++ b/natives/flip.cc @@ -11,7 +11,7 @@ Napi::Value Flip(const Napi::CallbackInfo &info) { try { Napi::Object obj = info[0].As(); - string path = obj.Get("path").As().Utf8Value(); + Napi::Buffer data = obj.Get("data").As>(); bool flop = obj.Has("flop") ? obj.Get("flop").As().Value() : false; string type = obj.Get("type").As().Utf8Value(); @@ -23,7 +23,7 @@ Napi::Value Flip(const Napi::CallbackInfo &info) { list frames; list coalesced; list mid; - readImages(&frames, path); + readImages(&frames, Blob(data.Data(), data.Length())); coalesceImages(&coalesced, frames.begin(), frames.end()); for (Image &image : coalesced) { diff --git a/natives/freeze.cc b/natives/freeze.cc index 14a1d8b..824f70e 100644 --- a/natives/freeze.cc +++ b/natives/freeze.cc @@ -11,7 +11,7 @@ Napi::Value Freeze(const Napi::CallbackInfo &info) { try { Napi::Object obj = info[0].As(); - string path = obj.Get("path").As().Utf8Value(); + Napi::Buffer data = obj.Get("data").As>(); bool loop = obj.Has("loop") ? obj.Get("loop").As().Value() : false; string type = obj.Get("type").As().Utf8Value(); @@ -24,7 +24,7 @@ Napi::Value Freeze(const Napi::CallbackInfo &info) { Blob blob; list frames; - readImages(&frames, path); + readImages(&frames, Blob(data.Data(), data.Length())); if (frame >= 0 && !loop) { size_t frameSize = frames.size(); diff --git a/natives/gamexplain.cc b/natives/gamexplain.cc index f62f6f1..10c357e 100644 --- a/natives/gamexplain.cc +++ b/natives/gamexplain.cc @@ -11,7 +11,7 @@ Napi::Value Gamexplain(const Napi::CallbackInfo &info) { try { Napi::Object obj = info[0].As(); - string path = obj.Get("path").As().Utf8Value(); + Napi::Buffer data = obj.Get("data").As>(); string type = obj.Get("type").As().Utf8Value(); int delay = obj.Has("delay") ? obj.Get("delay").As().Int32Value() : 0; @@ -22,7 +22,7 @@ Napi::Value Gamexplain(const Napi::CallbackInfo &info) { list coalesced; list 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()); diff --git a/natives/globe.cc b/natives/globe.cc index ec4f362..bf606ae 100644 --- a/natives/globe.cc +++ b/natives/globe.cc @@ -11,7 +11,7 @@ Napi::Value Globe(const Napi::CallbackInfo &info) { try { Napi::Object obj = info[0].As(); - string path = obj.Get("path").As().Utf8Value(); + Napi::Buffer data = obj.Get("data").As>(); string type = obj.Get("type").As().Utf8Value(); int delay = obj.Has("delay") ? obj.Get("delay").As().Int32Value() : 0; @@ -23,7 +23,7 @@ Napi::Value Globe(const Napi::CallbackInfo &info) { list 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()); diff --git a/natives/invert.cc b/natives/invert.cc index afc7dd7..5550889 100644 --- a/natives/invert.cc +++ b/natives/invert.cc @@ -11,7 +11,7 @@ Napi::Value Invert(const Napi::CallbackInfo &info) { try { Napi::Object obj = info[0].As(); - string path = obj.Get("path").As().Utf8Value(); + Napi::Buffer data = obj.Get("data").As>(); string type = obj.Get("type").As().Utf8Value(); int delay = obj.Has("delay") ? obj.Get("delay").As().Int32Value() : 0; @@ -21,7 +21,7 @@ Napi::Value Invert(const Napi::CallbackInfo &info) { list frames; list coalesced; list mid; - readImages(&frames, path); + readImages(&frames, Blob(data.Data(), data.Length())); coalesceImages(&coalesced, frames.begin(), frames.end()); for_each(coalesced.begin(), coalesced.end(), negateImage()); diff --git a/natives/jpeg.cc b/natives/jpeg.cc index b94cfd3..92a179b 100644 --- a/natives/jpeg.cc +++ b/natives/jpeg.cc @@ -11,12 +11,12 @@ Napi::Value Jpeg(const Napi::CallbackInfo &info) { try { Napi::Object obj = info[0].As(); - string path = obj.Get("path").As().Utf8Value(); + Napi::Buffer data = obj.Get("data").As>(); Blob blob; Image image; - image.read(path); + image.read(Blob(data.Data(), data.Length())); image.quality(1); image.magick("JPEG"); image.write(&blob); diff --git a/natives/leak.cc b/natives/leak.cc index 09d1d52..314407e 100644 --- a/natives/leak.cc +++ b/natives/leak.cc @@ -11,7 +11,7 @@ Napi::Value Leak(const Napi::CallbackInfo &info) { try { Napi::Object obj = info[0].As(); - string path = obj.Get("path").As().Utf8Value(); + Napi::Buffer data = obj.Get("data").As>(); string type = obj.Get("type").As().Utf8Value(); int delay = obj.Has("delay") ? obj.Get("delay").As().Int32Value() : 0; @@ -22,7 +22,7 @@ Napi::Value Leak(const Napi::CallbackInfo &info) { list coalesced; list 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()); diff --git a/natives/magik.cc b/natives/magik.cc index f531612..7cacb27 100644 --- a/natives/magik.cc +++ b/natives/magik.cc @@ -11,7 +11,7 @@ Napi::Value Magik(const Napi::CallbackInfo &info) { try { Napi::Object obj = info[0].As(); - string path = obj.Get("path").As().Utf8Value(); + Napi::Buffer data = obj.Get("data").As>(); string type = obj.Get("type").As().Utf8Value(); int delay = obj.Has("delay") ? obj.Get("delay").As().Int32Value() : 0; @@ -21,7 +21,7 @@ Napi::Value Magik(const Napi::CallbackInfo &info) { list frames; list coalesced; list blurred; - readImages(&frames, path); + readImages(&frames, Blob(data.Data(), data.Length())); coalesceImages(&coalesced, frames.begin(), frames.end()); for (Image &image : coalesced) { diff --git a/natives/meme.cc b/natives/meme.cc index feb8e11..e609171 100644 --- a/natives/meme.cc +++ b/natives/meme.cc @@ -11,7 +11,7 @@ Napi::Value Meme(const Napi::CallbackInfo &info) { try { Napi::Object obj = info[0].As(); - string path = obj.Get("path").As().Utf8Value(); + Napi::Buffer data = obj.Get("data").As>(); string top = obj.Get("top").As().Utf8Value(); string bottom = obj.Get("bottom").As().Utf8Value(); string type = obj.Get("type").As().Utf8Value(); @@ -25,7 +25,7 @@ Napi::Value Meme(const Napi::CallbackInfo &info) { list 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))); diff --git a/natives/mirror.cc b/natives/mirror.cc index cd39164..9372f5c 100644 --- a/natives/mirror.cc +++ b/natives/mirror.cc @@ -11,7 +11,7 @@ Napi::Value Mirror(const Napi::CallbackInfo &info) { try { Napi::Object obj = info[0].As(); - string path = obj.Get("path").As().Utf8Value(); + Napi::Buffer data = obj.Get("data").As>(); bool vertical = obj.Has("vertical") ? obj.Get("vertical").As().Value() : false; @@ -27,7 +27,7 @@ Napi::Value Mirror(const Napi::CallbackInfo &info) { list coalesced; list mid; MagickCore::GravityType gravity; - readImages(&frames, path); + readImages(&frames, Blob(data.Data(), data.Length())); coalesceImages(&coalesced, frames.begin(), frames.end()); if (vertical && first) { diff --git a/natives/motivate.cc b/natives/motivate.cc index 024f2ef..b8595ff 100644 --- a/natives/motivate.cc +++ b/natives/motivate.cc @@ -11,7 +11,7 @@ Napi::Value Motivate(const Napi::CallbackInfo &info) { try { Napi::Object obj = info[0].As(); - string path = obj.Get("path").As().Utf8Value(); + Napi::Buffer data = obj.Get("data").As>(); string top_text = obj.Get("top").As().Utf8Value(); string bottom_text = obj.Get("bottom").As().Utf8Value(); string type = obj.Get("type").As().Utf8Value(); @@ -25,7 +25,7 @@ Napi::Value Motivate(const Napi::CallbackInfo &info) { list 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")); diff --git a/natives/reddit.cc b/natives/reddit.cc index 090d01a..757fe2e 100644 --- a/natives/reddit.cc +++ b/natives/reddit.cc @@ -10,7 +10,7 @@ Napi::Value Reddit(const Napi::CallbackInfo &info) { Napi::Env env = info.Env(); try { Napi::Object obj = info[0].As(); - string path = obj.Get("path").As().Utf8Value(); + Napi::Buffer data = obj.Get("data").As>(); string text = obj.Get("caption").As().Utf8Value(); string type = obj.Get("type").As().Utf8Value(); int delay = @@ -23,7 +23,7 @@ Napi::Value Reddit(const Napi::CallbackInfo &info) { list 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); diff --git a/natives/resize.cc b/natives/resize.cc index 80726d7..a119844 100644 --- a/natives/resize.cc +++ b/natives/resize.cc @@ -11,7 +11,7 @@ Napi::Value Resize(const Napi::CallbackInfo &info) { try { Napi::Object obj = info[0].As(); - string path = obj.Get("path").As().Utf8Value(); + Napi::Buffer data = obj.Get("data").As>(); bool stretch = obj.Has("stretch") ? obj.Get("stretch").As().Value() : false; @@ -26,7 +26,7 @@ Napi::Value Resize(const Napi::CallbackInfo &info) { list frames; list coalesced; list blurred; - readImages(&frames, path); + readImages(&frames, Blob(data.Data(), data.Length())); coalesceImages(&coalesced, frames.begin(), frames.end()); for (Image &image : coalesced) { diff --git a/natives/reverse.cc b/natives/reverse.cc index 00e5035..ee5fb83 100644 --- a/natives/reverse.cc +++ b/natives/reverse.cc @@ -11,7 +11,7 @@ Napi::Value Reverse(const Napi::CallbackInfo &info) { try { Napi::Object obj = info[0].As(); - string path = obj.Get("path").As().Utf8Value(); + Napi::Buffer data = obj.Get("data").As>(); bool soos = obj.Has("soos") ? obj.Get("soos").As().Value() : false; int delay = @@ -21,7 +21,7 @@ Napi::Value Reverse(const Napi::CallbackInfo &info) { list frames; list coalesced; - readImages(&frames, path); + readImages(&frames, Blob(data.Data(), data.Length())); coalesceImages(&coalesced, frames.begin(), frames.end()); if (soos) { diff --git a/natives/scott.cc b/natives/scott.cc index 2c89e98..6f4914f 100644 --- a/natives/scott.cc +++ b/natives/scott.cc @@ -11,7 +11,7 @@ Napi::Value Scott(const Napi::CallbackInfo &info) { try { Napi::Object obj = info[0].As(); - string path = obj.Get("path").As().Utf8Value(); + Napi::Buffer data = obj.Get("data").As>(); string type = obj.Get("type").As().Utf8Value(); int delay = obj.Has("delay") ? obj.Get("delay").As().Int32Value() : 0; @@ -22,7 +22,7 @@ Napi::Value Scott(const Napi::CallbackInfo &info) { list coalesced; list 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()); diff --git a/natives/speed.cc b/natives/speed.cc index 35c7c98..999f9c9 100644 --- a/natives/speed.cc +++ b/natives/speed.cc @@ -11,7 +11,7 @@ Napi::Value Speed(const Napi::CallbackInfo &info) { try { Napi::Object obj = info[0].As(); - string path = obj.Get("path").As().Utf8Value(); + Napi::Buffer data = obj.Get("data").As>(); bool slow = obj.Has("slow") ? obj.Get("slow").As().Value() : false; string type = obj.Get("type").As().Utf8Value(); @@ -23,7 +23,7 @@ Napi::Value Speed(const Napi::CallbackInfo &info) { Blob blob; list 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) { diff --git a/natives/spin.cc b/natives/spin.cc index be6e048..d789cc4 100644 --- a/natives/spin.cc +++ b/natives/spin.cc @@ -11,7 +11,7 @@ Napi::Value Spin(const Napi::CallbackInfo &info) { try { Napi::Object obj = info[0].As(); - string path = obj.Get("path").As().Utf8Value(); + Napi::Buffer data = obj.Get("data").As>(); string type = obj.Get("type").As().Utf8Value(); int delay = obj.Has("delay") ? obj.Get("delay").As().Int32Value() : 0; @@ -21,7 +21,7 @@ Napi::Value Spin(const Napi::CallbackInfo &info) { list frames; list coalesced; list mid; - readImages(&frames, path); + readImages(&frames, Blob(data.Data(), data.Length())); coalesceImages(&coalesced, frames.begin(), frames.end()); if (type != "gif") { diff --git a/natives/swirl.cc b/natives/swirl.cc index 5b6ce12..a93177b 100644 --- a/natives/swirl.cc +++ b/natives/swirl.cc @@ -11,7 +11,7 @@ Napi::Value Swirl(const Napi::CallbackInfo &info) { try { Napi::Object obj = info[0].As(); - string path = obj.Get("path").As().Utf8Value(); + Napi::Buffer data = obj.Get("data").As>(); string type = obj.Get("type").As().Utf8Value(); int delay = obj.Has("delay") ? obj.Get("delay").As().Int32Value() : 0; @@ -21,7 +21,7 @@ Napi::Value Swirl(const Napi::CallbackInfo &info) { list frames; list coalesced; list mid; - readImages(&frames, path); + readImages(&frames, Blob(data.Data(), data.Length())); coalesceImages(&coalesced, frames.begin(), frames.end()); for (Image &image : coalesced) { diff --git a/natives/tile.cc b/natives/tile.cc index 563c976..e2012d6 100644 --- a/natives/tile.cc +++ b/natives/tile.cc @@ -11,7 +11,7 @@ Napi::Value Tile(const Napi::CallbackInfo &info) { try { Napi::Object obj = info[0].As(); - string path = obj.Get("path").As().Utf8Value(); + Napi::Buffer data = obj.Get("data").As>(); string type = obj.Get("type").As().Utf8Value(); int delay = obj.Has("delay") ? obj.Get("delay").As().Int32Value() : 0; @@ -21,7 +21,7 @@ Napi::Value Tile(const Napi::CallbackInfo &info) { list frames; list coalesced; list mid; - readImages(&frames, path); + readImages(&frames, Blob(data.Data(), data.Length())); coalesceImages(&coalesced, frames.begin(), frames.end()); for (Image &image : coalesced) { diff --git a/natives/trump.cc b/natives/trump.cc index 0c82c9b..ff59eca 100644 --- a/natives/trump.cc +++ b/natives/trump.cc @@ -11,7 +11,7 @@ Napi::Value Trump(const Napi::CallbackInfo &info) { try { Napi::Object obj = info[0].As(); - string path = obj.Get("path").As().Utf8Value(); + Napi::Buffer data = obj.Get("data").As>(); string type = obj.Get("type").As().Utf8Value(); int delay = obj.Has("delay") ? obj.Get("delay").As().Int32Value() : 0; @@ -22,7 +22,7 @@ Napi::Value Trump(const Napi::CallbackInfo &info) { list coalesced; list 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()); diff --git a/natives/uncaption.cc b/natives/uncaption.cc index 5377d1b..41e4655 100644 --- a/natives/uncaption.cc +++ b/natives/uncaption.cc @@ -34,7 +34,7 @@ Napi::Value Uncaption(const Napi::CallbackInfo &info) { try { Napi::Object obj = info[0].As(); - string path = obj.Get("path").As().Utf8Value(); + Napi::Buffer data = obj.Get("data").As>(); string type = obj.Get("type").As().Utf8Value(); int delay = obj.Has("delay") ? obj.Get("delay").As().Int32Value() : 0; @@ -44,7 +44,7 @@ Napi::Value Uncaption(const Napi::CallbackInfo &info) { list frames; list coalesced; list mid; - readImages(&frames, path); + readImages(&frames, Blob(data.Data(), data.Length())); coalesceImages(&coalesced, frames.begin(), frames.end()); Image firstImage = coalesced.front(); diff --git a/natives/wall.cc b/natives/wall.cc index 4293405..6882085 100644 --- a/natives/wall.cc +++ b/natives/wall.cc @@ -11,7 +11,7 @@ Napi::Value Wall(const Napi::CallbackInfo &info) { try { Napi::Object obj = info[0].As(); - string path = obj.Get("path").As().Utf8Value(); + Napi::Buffer data = obj.Get("data").As>(); string type = obj.Get("type").As().Utf8Value(); int delay = obj.Has("delay") ? obj.Get("delay").As().Int32Value() : 0; @@ -21,7 +21,7 @@ Napi::Value Wall(const Napi::CallbackInfo &info) { list frames; list coalesced; list mid; - readImages(&frames, path); + readImages(&frames, Blob(data.Data(), data.Length())); coalesceImages(&coalesced, frames.begin(), frames.end()); for (Image &image : coalesced) { diff --git a/natives/watermark.cc b/natives/watermark.cc index 9045b99..cda2a71 100644 --- a/natives/watermark.cc +++ b/natives/watermark.cc @@ -12,7 +12,7 @@ Napi::Value Watermark(const Napi::CallbackInfo &info) { try { Napi::Object obj = info[0].As(); - string path = obj.Get("path").As().Utf8Value(); + Napi::Buffer data = obj.Get("data").As>(); string water = obj.Get("water").As().Utf8Value(); int gravity = obj.Get("gravity").As().Int32Value(); bool resize = obj.Has("resize") @@ -32,7 +32,7 @@ Napi::Value Watermark(const Napi::CallbackInfo &info) { list coalesced; list 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"); diff --git a/natives/wdt.cc b/natives/wdt.cc index 532d8e3..2959ece 100644 --- a/natives/wdt.cc +++ b/natives/wdt.cc @@ -11,7 +11,7 @@ Napi::Value Wdt(const Napi::CallbackInfo &info) { try { Napi::Object obj = info[0].As(); - string path = obj.Get("path").As().Utf8Value(); + Napi::Buffer data = obj.Get("data").As>(); string type = obj.Get("type").As().Utf8Value(); int delay = obj.Has("delay") ? obj.Get("delay").As().Int32Value() : 0; @@ -22,7 +22,7 @@ Napi::Value Wdt(const Napi::CallbackInfo &info) { list coalesced; list 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()); diff --git a/utils/image-runner.js b/utils/image-runner.js index f45260f..4e8a995 100644 --- a/utils/image-runner.js +++ b/utils/image-runner.js @@ -1,30 +1,36 @@ 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"; - const objectWithFixedType = Object.assign({}, object, {type: fileExtension}); - try { - const result = magick[object.cmd](objectWithFixedType); - const returnObject = { - buffer: result.data, - fileExtension: result.type - }; - resolve(returnObject); - } catch (e) { - reject(e); - } + promise.then(buf => { + object.data = buf; + const objectWithFixedType = Object.assign({}, object, {type: fileExtension}); + try { + const result = magick[object.cmd](objectWithFixedType); + const returnObject = { + buffer: result.data, + fileExtension: result.type + }; + resolve(returnObject); + } catch (e) { + reject(e); + } + }); }); };