Make all native image functions synchronous

This commit is contained in:
TheEssem 2021-04-24 17:54:47 -05:00
parent f44abc5576
commit 6cecd4b9d6
39 changed files with 1581 additions and 1996 deletions

View file

@ -2,7 +2,9 @@
"emotes": [ "emotes": [
"<a:processing:818243325891051581>", "<a:processing:818243325891051581>",
"<a:glxgears:802272302082293770>", "<a:glxgears:802272302082293770>",
"<a:spunchbob:834829415661568000>" "<a:spunchbob:834829415661568000>",
"<a:processing:834861794794536990>",
"<a:processing:834861794802532432>"
], ],
"messages": [ "messages": [
"with your sanity", "with your sanity",

View file

@ -1,20 +1,26 @@
#include <napi.h>
#include <list>
#include <Magick++.h> #include <Magick++.h>
#include <napi.h>
#include <list>
using namespace std; using namespace std;
using namespace Magick; using namespace Magick;
class BlurWorker : public Napi::AsyncWorker { Napi::Value Blur(const Napi::CallbackInfo &info) {
public: Napi::Env env = info.Env();
BlurWorker(Napi::Function& callback, string in_path, bool sharp, string type, int delay)
: Napi::AsyncWorker(callback), in_path(in_path), sharp(sharp), type(type), delay(delay) {} Napi::Object obj = info[0].As<Napi::Object>();
~BlurWorker() {} string path = obj.Get("path").As<Napi::String>().Utf8Value();
bool sharp = obj.Get("sharp").As<Napi::Boolean>().Value();
string type = obj.Get("type").As<Napi::String>().Utf8Value();
int delay =
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
Blob blob;
void Execute() {
list<Image> frames; list<Image> frames;
list<Image> coalesced; list<Image> coalesced;
readImages(&frames, in_path); readImages(&frames, path);
coalesceImages(&coalesced, frames.begin(), frames.end()); coalesceImages(&coalesced, frames.begin(), frames.end());
if (sharp) { if (sharp) {
@ -36,31 +42,10 @@ class BlurWorker : public Napi::AsyncWorker {
} }
writeImages(coalesced.begin(), coalesced.end(), &blob); writeImages(coalesced.begin(), coalesced.end(), &blob);
}
Napi::Object result = Napi::Object::New(env);
void OnOK() { result.Set("data",
Callback().Call({Env().Undefined(), Napi::Buffer<char>::Copy(Env(), (char *)blob.data(), blob.length()), Napi::String::From(Env(), type)}); Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
} result.Set("type", type);
return result;
private:
string in_path, type;
int delay;
Blob blob;
bool sharp;
};
Napi::Value Blur(const Napi::CallbackInfo &info)
{
Napi::Env env = info.Env();
Napi::Object obj = info[0].As<Napi::Object>();
Napi::Function cb = info[1].As<Napi::Function>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
bool sharp = obj.Get("sharp").As<Napi::Boolean>().Value();
string type = obj.Get("type").As<Napi::String>().Utf8Value();
int delay = obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
BlurWorker* blurWorker = new BlurWorker(cb, path, sharp, type, delay);
blurWorker->Queue();
return env.Undefined();
} }

View file

@ -1,21 +1,26 @@
#include <napi.h>
#include <list>
#include <Magick++.h> #include <Magick++.h>
#include <napi.h>
#include <list>
using namespace std; using namespace std;
using namespace Magick; using namespace Magick;
class BlurpleWorker : public Napi::AsyncWorker { Napi::Value Blurple(const Napi::CallbackInfo &info) {
public: Napi::Env env = info.Env();
BlurpleWorker(Napi::Function& callback, string in_path, string type, int delay)
: Napi::AsyncWorker(callback), in_path(in_path), type(type), delay(delay) {} Napi::Object obj = info[0].As<Napi::Object>();
~BlurpleWorker() {} string path = obj.Get("path").As<Napi::String>().Utf8Value();
string type = obj.Get("type").As<Napi::String>().Utf8Value();
int delay =
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
Blob blob;
void Execute() {
list<Image> frames; list<Image> frames;
list<Image> coalesced; list<Image> coalesced;
list<Image> blurpled; list<Image> blurpled;
readImages(&frames, in_path); readImages(&frames, path);
coalesceImages(&coalesced, frames.begin(), frames.end()); coalesceImages(&coalesced, frames.begin(), frames.end());
for (Image &image : coalesced) { for (Image &image : coalesced) {
@ -35,31 +40,11 @@ class BlurpleWorker : public Napi::AsyncWorker {
} }
} }
writeImages(blurpled.begin(), blurpled.end(), &blob); writeImages(blurpled.begin(), blurpled.end(), &blob);
}
Napi::Object result = Napi::Object::New(env);
void OnOK() { result.Set("data",
Callback().Call({Env().Undefined(), Napi::Buffer<char>::Copy(Env(), (char *)blob.data(), blob.length()), Napi::String::From(Env(), type)}); Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
} result.Set("type", type);
return result;
private:
string in_path, type;
int delay;
Blob blob;
};
Napi::Value Blurple(const Napi::CallbackInfo &info)
{
Napi::Env env = info.Env();
Napi::Object obj = info[0].As<Napi::Object>();
Napi::Function cb = info[1].As<Napi::Function>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
string type = obj.Get("type").As<Napi::String>().Utf8Value();
int delay = obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
BlurpleWorker* blurpleWorker = new BlurpleWorker(cb, path, type, delay);
blurpleWorker->Queue();
return env.Undefined();
} }

View file

@ -1,22 +1,27 @@
#include <napi.h>
#include <list>
#include <Magick++.h> #include <Magick++.h>
#include <napi.h>
#include <list>
using namespace std; using namespace std;
using namespace Magick; using namespace Magick;
class CaptionWorker : public Napi::AsyncWorker { Napi::Value Caption(const Napi::CallbackInfo &info) {
public: Napi::Env env = info.Env();
CaptionWorker(Napi::Function& callback, string caption, string in_path, string type, int delay)
: Napi::AsyncWorker(callback), caption(caption), in_path(in_path), type(type), delay(delay) {} Napi::Object obj = info[0].As<Napi::Object>();
~CaptionWorker() {} string path = obj.Get("path").As<Napi::String>().Utf8Value();
string caption = 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;
void Execute() {
list<Image> frames; list<Image> frames;
list<Image> coalesced; list<Image> coalesced;
list<Image> captioned; list<Image> captioned;
list <Image> result; readImages(&frames, path);
readImages(&frames, in_path);
size_t width = frames.front().baseColumns(); size_t width = frames.front().baseColumns();
string query(to_string(width - ((width / 25) * 2)) + "x"); string query(to_string(width - ((width / 25) * 2)) + "x");
@ -27,7 +32,8 @@ class CaptionWorker : public Napi::AsyncWorker {
caption_image.fontPointsize(width / 13); caption_image.fontPointsize(width / 13);
caption_image.textGravity(Magick::CenterGravity); caption_image.textGravity(Magick::CenterGravity);
caption_image.read("pango:" + caption); caption_image.read("pango:" + caption);
caption_image.extent(Geometry(width, caption_image.rows() + (width / 13)), Magick::CenterGravity); caption_image.extent(Geometry(width, caption_image.rows() + (width / 13)),
Magick::CenterGravity);
coalesceImages(&coalesced, frames.begin(), frames.end()); coalesceImages(&coalesced, frames.begin(), frames.end());
@ -54,32 +60,11 @@ class CaptionWorker : public Napi::AsyncWorker {
} }
} }
writeImages(captioned.begin(), captioned.end(), &blob); writeImages(captioned.begin(), captioned.end(), &blob);
}
Napi::Object result = Napi::Object::New(env);
void OnOK() { result.Set("data",
Callback().Call({Env().Undefined(), Napi::Buffer<char>::Copy(Env(), (char *)blob.data(), blob.length()), Napi::String::From(Env(), type)}); Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
} result.Set("type", type);
return result;
private:
string caption, in_path, type;
int delay;
Blob blob;
};
Napi::Value Caption(const Napi::CallbackInfo &info)
{
Napi::Env env = info.Env();
Napi::Object obj = info[0].As<Napi::Object>();
Napi::Function cb = info[1].As<Napi::Function>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
string caption = 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;
CaptionWorker* captionWorker = new CaptionWorker(cb, caption, path, type, delay);
captionWorker->Queue();
return env.Undefined();
} }

View file

@ -1,22 +1,28 @@
#include <napi.h>
#include <list>
#include <Magick++.h> #include <Magick++.h>
#include <napi.h>
#include <list>
using namespace std; using namespace std;
using namespace Magick; using namespace Magick;
class CaptionTwoWorker : public Napi::AsyncWorker { Napi::Value CaptionTwo(const Napi::CallbackInfo &info) {
public: Napi::Env env = info.Env();
CaptionTwoWorker(Napi::Function& callback, string caption, string in_path, string type, int delay)
: Napi::AsyncWorker(callback), caption(caption), in_path(in_path), type(type), delay(delay) {} Napi::Object obj = info[0].As<Napi::Object>();
~CaptionTwoWorker() {} string path = obj.Get("path").As<Napi::String>().Utf8Value();
string caption = 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;
void Execute() {
list<Image> frames; list<Image> frames;
list<Image> coalesced; list<Image> coalesced;
list<Image> captioned; list<Image> captioned;
Blob caption_blob; Blob caption_blob;
readImages(&frames, in_path); readImages(&frames, path);
size_t width = frames.front().baseColumns(); size_t width = frames.front().baseColumns();
string query(to_string(width - ((width / 25) * 2)) + "x"); string query(to_string(width - ((width / 25) * 2)) + "x");
@ -25,7 +31,8 @@ class CaptionTwoWorker : public Napi::AsyncWorker {
caption_image.font("Helvetica Neue"); caption_image.font("Helvetica Neue");
caption_image.fontPointsize(width / 17); caption_image.fontPointsize(width / 17);
caption_image.read("pango:" + caption); caption_image.read("pango:" + caption);
caption_image.extent(Geometry(width, caption_image.rows() + (width / 25)), Magick::CenterGravity); caption_image.extent(Geometry(width, caption_image.rows() + (width / 25)),
Magick::CenterGravity);
coalesceImages(&coalesced, frames.begin(), frames.end()); coalesceImages(&coalesced, frames.begin(), frames.end());
@ -52,30 +59,10 @@ class CaptionTwoWorker : public Napi::AsyncWorker {
} }
writeImages(captioned.begin(), captioned.end(), &blob); writeImages(captioned.begin(), captioned.end(), &blob);
}
Napi::Object result = Napi::Object::New(env);
void OnOK() { result.Set("data",
Callback().Call({Env().Undefined(), Napi::Buffer<char>::Copy(Env(), (char *)blob.data(), blob.length()), Napi::String::From(Env(), type)}); Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
} result.Set("type", type);
return result;
private:
string caption, in_path, type;
int delay;
Blob blob;
};
Napi::Value CaptionTwo(const Napi::CallbackInfo &info)
{
Napi::Env env = info.Env();
Napi::Object obj = info[0].As<Napi::Object>();
Napi::Function cb = info[1].As<Napi::Function>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
string caption = 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;
CaptionTwoWorker* captionTwoWorker = new CaptionTwoWorker(cb, caption, path, type, delay);
captionTwoWorker->Queue();
return env.Undefined();
} }

View file

@ -1,21 +1,26 @@
#include <napi.h>
#include <list>
#include <Magick++.h> #include <Magick++.h>
#include <napi.h>
#include <list>
using namespace std; using namespace std;
using namespace Magick; using namespace Magick;
class CircleWorker : public Napi::AsyncWorker { Napi::Value Circle(const Napi::CallbackInfo &info) {
public: Napi::Env env = info.Env();
CircleWorker(Napi::Function& callback, string in_path, string type, int delay)
: Napi::AsyncWorker(callback), in_path(in_path), type(type), delay(delay) {} Napi::Object obj = info[0].As<Napi::Object>();
~CircleWorker() {} string path = obj.Get("path").As<Napi::String>().Utf8Value();
string type = obj.Get("type").As<Napi::String>().Utf8Value();
int delay =
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
Blob blob;
void Execute() {
list<Image> frames; list<Image> frames;
list<Image> coalesced; list<Image> coalesced;
list<Image> blurred; list<Image> blurred;
readImages(&frames, in_path); readImages(&frames, path);
coalesceImages(&coalesced, frames.begin(), frames.end()); coalesceImages(&coalesced, frames.begin(), frames.end());
for (Image &image : coalesced) { for (Image &image : coalesced) {
@ -35,29 +40,10 @@ class CircleWorker : public Napi::AsyncWorker {
} }
writeImages(blurred.begin(), blurred.end(), &blob); writeImages(blurred.begin(), blurred.end(), &blob);
}
Napi::Object result = Napi::Object::New(env);
void OnOK() { result.Set("data",
Callback().Call({Env().Undefined(), Napi::Buffer<char>::Copy(Env(), (char *)blob.data(), blob.length()), Napi::String::From(Env(), type)}); Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
} result.Set("type", type);
return result;
private:
string in_path, type;
int delay;
Blob blob;
};
Napi::Value Circle(const Napi::CallbackInfo &info)
{
Napi::Env env = info.Env();
Napi::Object obj = info[0].As<Napi::Object>();
Napi::Function cb = info[1].As<Napi::Function>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
string type = obj.Get("type").As<Napi::String>().Utf8Value();
int delay = obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
CircleWorker* circleWorker = new CircleWorker(cb, path, type, delay);
circleWorker->Queue();
return env.Undefined();
} }

View file

@ -1,26 +1,38 @@
#include <napi.h>
#include <list>
#include <Magick++.h> #include <Magick++.h>
#include <napi.h>
#include <list>
using namespace std; using namespace std;
using namespace Magick; using namespace Magick;
class CropWorker : public Napi::AsyncWorker { Napi::Value Crop(const Napi::CallbackInfo &info) {
public: Napi::Env env = info.Env();
CropWorker(Napi::Function& callback, string in_path, string type, int delay)
: Napi::AsyncWorker(callback), in_path(in_path), type(type), delay(delay) {} Napi::Object obj = info[0].As<Napi::Object>();
~CropWorker() {} string path = obj.Get("path").As<Napi::String>().Utf8Value();
string type = obj.Get("type").As<Napi::String>().Utf8Value();
int delay =
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
Blob blob;
void Execute() {
list<Image> frames; list<Image> frames;
list<Image> coalesced; list<Image> coalesced;
list<Image> mid; list<Image> mid;
readImages(&frames, in_path); readImages(&frames, path);
coalesceImages(&coalesced, frames.begin(), frames.end()); coalesceImages(&coalesced, frames.begin(), frames.end());
for (Image &image : coalesced) { for (Image &image : coalesced) {
image.extent(Geometry(to_string(image.columns() / image.rows() >= 1 ? image.rows() : image.columns()) + "x"), Magick::CenterGravity); image.extent(Geometry(to_string(image.columns() / image.rows() >= 1
image.extent(Geometry("x" + to_string(image.columns() / image.rows() <= 1 ? image.columns() : image.rows())), Magick::CenterGravity); ? image.rows()
: image.columns()) +
"x"),
Magick::CenterGravity);
image.extent(Geometry("x" + to_string(image.columns() / image.rows() <= 1
? image.columns()
: image.rows())),
Magick::CenterGravity);
image.magick(type); image.magick(type);
mid.push_back(image); mid.push_back(image);
} }
@ -36,29 +48,10 @@ class CropWorker : public Napi::AsyncWorker {
} }
writeImages(mid.begin(), mid.end(), &blob); writeImages(mid.begin(), mid.end(), &blob);
}
Napi::Object result = Napi::Object::New(env);
void OnOK() { result.Set("data",
Callback().Call({Env().Undefined(), Napi::Buffer<char>::Copy(Env(), (char *)blob.data(), blob.length()), Napi::String::From(Env(), type)}); Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
} result.Set("type", type);
return result;
private:
string in_path, type;
int delay;
Blob blob;
};
Napi::Value Crop(const Napi::CallbackInfo &info)
{
Napi::Env env = info.Env();
Napi::Object obj = info[0].As<Napi::Object>();
Napi::Function cb = info[1].As<Napi::Function>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
string type = obj.Get("type").As<Napi::String>().Utf8Value();
int delay = obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
CropWorker* blurWorker = new CropWorker(cb, path, type, delay);
blurWorker->Queue();
return env.Undefined();
} }

View file

@ -1,21 +1,27 @@
#include <napi.h>
#include <list>
#include <Magick++.h> #include <Magick++.h>
#include <napi.h>
#include <list>
using namespace std; using namespace std;
using namespace Magick; using namespace Magick;
class ExplodeWorker : public Napi::AsyncWorker { Napi::Value Explode(const Napi::CallbackInfo &info) {
public: Napi::Env env = info.Env();
ExplodeWorker(Napi::Function& callback, string in_path, int amount, string type, int delay)
: Napi::AsyncWorker(callback), in_path(in_path), amount(amount), type(type), delay(delay) {} Napi::Object obj = info[0].As<Napi::Object>();
~ExplodeWorker() {} string path = obj.Get("path").As<Napi::String>().Utf8Value();
int amount = obj.Get("amount").As<Napi::Number>().Int32Value();
string type = obj.Get("type").As<Napi::String>().Utf8Value();
int delay =
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
Blob blob;
void Execute() {
list<Image> frames; list<Image> frames;
list<Image> coalesced; list<Image> coalesced;
list<Image> blurred; list<Image> blurred;
readImages(&frames, in_path); readImages(&frames, path);
coalesceImages(&coalesced, frames.begin(), frames.end()); coalesceImages(&coalesced, frames.begin(), frames.end());
for (Image &image : coalesced) { for (Image &image : coalesced) {
@ -35,30 +41,10 @@ class ExplodeWorker : public Napi::AsyncWorker {
} }
writeImages(blurred.begin(), blurred.end(), &blob); writeImages(blurred.begin(), blurred.end(), &blob);
}
Napi::Object result = Napi::Object::New(env);
void OnOK() { result.Set("data",
Callback().Call({Env().Undefined(), Napi::Buffer<char>::Copy(Env(), (char *)blob.data(), blob.length()), Napi::String::From(Env(), type)}); Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
} result.Set("type", type);
return result;
private:
string in_path, type;
int delay, amount;
Blob blob;
};
Napi::Value Explode(const Napi::CallbackInfo &info)
{
Napi::Env env = info.Env();
Napi::Object obj = info[0].As<Napi::Object>();
Napi::Function cb = info[1].As<Napi::Function>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
int amount = obj.Get("amount").As<Napi::Number>().Int32Value();
string type = obj.Get("type").As<Napi::String>().Utf8Value();
int delay = obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
ExplodeWorker* explodeWorker = new ExplodeWorker(cb, path, amount, type, delay);
explodeWorker->Queue();
return env.Undefined();
} }

View file

@ -1,26 +1,34 @@
#include <napi.h>
#include <list>
#include <Magick++.h> #include <Magick++.h>
#include <napi.h>
#include <list>
using namespace std; using namespace std;
using namespace Magick; using namespace Magick;
class FlagWorker : public Napi::AsyncWorker { Napi::Value Flag(const Napi::CallbackInfo &info) {
public: Napi::Env env = info.Env();
FlagWorker(Napi::Function& callback, string in_path, string overlay_path, string type, int delay)
: Napi::AsyncWorker(callback), in_path(in_path), overlay_path(overlay_path), type(type), delay(delay) {} Napi::Object obj = info[0].As<Napi::Object>();
~FlagWorker() {} string path = obj.Get("path").As<Napi::String>().Utf8Value();
string overlay = obj.Get("overlay").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;
void Execute() {
list<Image> frames; list<Image> frames;
list<Image> coalesced; list<Image> coalesced;
list<Image> mid; list<Image> mid;
Image watermark; Image watermark;
readImages(&frames, in_path); readImages(&frames, path);
watermark.read(overlay_path); watermark.read(overlay);
watermark.alphaChannel(Magick::SetAlphaChannel); watermark.alphaChannel(Magick::SetAlphaChannel);
watermark.evaluate(Magick::AlphaChannel, Magick::MultiplyEvaluateOperator, 0.5); watermark.evaluate(Magick::AlphaChannel, Magick::MultiplyEvaluateOperator,
string query(to_string(frames.front().baseColumns()) + "x" + to_string(frames.front().baseRows()) + "!"); 0.5);
string query(to_string(frames.front().baseColumns()) + "x" +
to_string(frames.front().baseRows()) + "!");
watermark.scale(Geometry(query)); watermark.scale(Geometry(query));
coalesceImages(&coalesced, frames.begin(), frames.end()); coalesceImages(&coalesced, frames.begin(), frames.end());
@ -41,30 +49,10 @@ class FlagWorker : public Napi::AsyncWorker {
} }
writeImages(mid.begin(), mid.end(), &blob); writeImages(mid.begin(), mid.end(), &blob);
}
Napi::Object result = Napi::Object::New(env);
void OnOK() { result.Set("data",
Callback().Call({Env().Undefined(), Napi::Buffer<char>::Copy(Env(), (char *)blob.data(), blob.length()), Napi::String::From(Env(), type)}); Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
} result.Set("type", type);
return result;
private:
string in_path, overlay_path, type;
int delay;
Blob blob;
};
Napi::Value Flag(const Napi::CallbackInfo &info)
{
Napi::Env env = info.Env();
Napi::Object obj = info[0].As<Napi::Object>();
Napi::Function cb = info[1].As<Napi::Function>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
string overlay = obj.Get("overlay").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;
FlagWorker* flagWorker = new FlagWorker(cb, path, overlay, type, delay);
flagWorker->Queue();
return env.Undefined();
} }

View file

@ -1,21 +1,28 @@
#include <napi.h>
#include <list>
#include <Magick++.h> #include <Magick++.h>
#include <napi.h>
#include <list>
using namespace std; using namespace std;
using namespace Magick; using namespace Magick;
class FlipWorker : public Napi::AsyncWorker { Napi::Value Flip(const Napi::CallbackInfo &info) {
public: Napi::Env env = info.Env();
FlipWorker(Napi::Function& callback, string in_path, bool flop, string type, int delay)
: Napi::AsyncWorker(callback), in_path(in_path), flop(flop), type(type), delay(delay) {} Napi::Object obj = info[0].As<Napi::Object>();
~FlipWorker() {} string path = obj.Get("path").As<Napi::String>().Utf8Value();
bool flop =
obj.Has("flop") ? obj.Get("flop").As<Napi::Boolean>().Value() : false;
string type = obj.Get("type").As<Napi::String>().Utf8Value();
int delay =
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
Blob blob;
void Execute() {
list<Image> frames; list<Image> frames;
list<Image> coalesced; list<Image> coalesced;
list<Image> mid; list<Image> mid;
readImages(&frames, in_path); readImages(&frames, path);
coalesceImages(&coalesced, frames.begin(), frames.end()); coalesceImages(&coalesced, frames.begin(), frames.end());
for (Image &image : coalesced) { for (Image &image : coalesced) {
@ -35,31 +42,10 @@ class FlipWorker : public Napi::AsyncWorker {
} }
writeImages(mid.begin(), mid.end(), &blob); writeImages(mid.begin(), mid.end(), &blob);
}
Napi::Object result = Napi::Object::New(env);
void OnOK() { result.Set("data",
Callback().Call({Env().Undefined(), Napi::Buffer<char>::Copy(Env(), (char *)blob.data(), blob.length()), Napi::String::From(Env(), type)}); Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
} result.Set("type", type);
return result;
private:
string in_path, type;
bool flop;
int delay;
Blob blob;
};
Napi::Value Flip(const Napi::CallbackInfo &info)
{
Napi::Env env = info.Env();
Napi::Object obj = info[0].As<Napi::Object>();
Napi::Function cb = info[1].As<Napi::Function>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
bool flop = obj.Has("flop") ? obj.Get("flop").As<Napi::Boolean>().Value() : false;
string type = obj.Get("type").As<Napi::String>().Utf8Value();
int delay = obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
FlipWorker* flipWorker = new FlipWorker(cb, path, flop, type, delay);
flipWorker->Queue();
return env.Undefined();
} }

View file

@ -1,56 +1,45 @@
#include <napi.h>
#include <list>
#include <Magick++.h> #include <Magick++.h>
#include <napi.h>
#include <list>
using namespace std; using namespace std;
using namespace Magick; using namespace Magick;
class FreezeWorker : public Napi::AsyncWorker { Napi::Value Freeze(const Napi::CallbackInfo &info) {
public: Napi::Env env = info.Env();
FreezeWorker(Napi::Function& callback, string in_path, bool loop, int frame, string type, int delay)
: Napi::AsyncWorker(callback), in_path(in_path), loop(loop), frame(frame), type(type), delay(delay) {} Napi::Object obj = info[0].As<Napi::Object>();
~FreezeWorker() {} string path = obj.Get("path").As<Napi::String>().Utf8Value();
bool loop =
obj.Has("loop") ? obj.Get("loop").As<Napi::Boolean>().Value() : false;
string type = obj.Get("type").As<Napi::String>().Utf8Value();
int delay =
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
int frame =
obj.Has("frame") ? obj.Get("frame").As<Napi::Number>().Int32Value() : -1;
Blob blob;
void Execute() {
list<Image> frames; list<Image> frames;
readImages(&frames, in_path); readImages(&frames, path);
if (frame >= 0 && !loop) { if (frame >= 0 && !loop) {
size_t frameSize = frames.size(); size_t frameSize = frames.size();
int framePos = clamp(frame, 0, (int)frameSize); int framePos = clamp(frame, 0, (int)frameSize);
frames.resize(framePos + 1); frames.resize(framePos + 1);
} }
for_each(frames.begin(), frames.end(), animationIterationsImage(loop ? 0 : 1)); for_each(frames.begin(), frames.end(),
animationIterationsImage(loop ? 0 : 1));
for_each(frames.begin(), frames.end(), magickImage(type)); for_each(frames.begin(), frames.end(), magickImage(type));
if (delay != 0) for_each(frames.begin(), frames.end(), animationDelayImage(delay)); if (delay != 0)
for_each(frames.begin(), frames.end(), animationDelayImage(delay));
writeImages(frames.begin(), frames.end(), &blob); writeImages(frames.begin(), frames.end(), &blob);
}
Napi::Object result = Napi::Object::New(env);
void OnOK() { result.Set("data",
Callback().Call({Env().Undefined(), Napi::Buffer<char>::Copy(Env(), (char *)blob.data(), blob.length()), Napi::String::From(Env(), type)}); Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
} result.Set("type", type);
return result;
private:
string in_path, type;
int frame, delay;
Blob blob;
bool loop;
};
Napi::Value Freeze(const Napi::CallbackInfo &info)
{
Napi::Env env = info.Env();
Napi::Object obj = info[0].As<Napi::Object>();
Napi::Function cb = info[1].As<Napi::Function>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
bool loop = obj.Has("loop") ? obj.Get("loop").As<Napi::Boolean>().Value() : false;
string type = obj.Get("type").As<Napi::String>().Utf8Value();
int delay = obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
int frame = obj.Has("frame") ? obj.Get("frame").As<Napi::Number>().Int32Value() : -1;
FreezeWorker* freezeWorker = new FreezeWorker(cb, path, loop, frame, type, delay);
freezeWorker->Queue();
return env.Undefined();
} }

View file

@ -1,22 +1,27 @@
#include <napi.h>
#include <list>
#include <Magick++.h> #include <Magick++.h>
#include <napi.h>
#include <list>
using namespace std; using namespace std;
using namespace Magick; using namespace Magick;
class GamexplainWorker : public Napi::AsyncWorker { Napi::Value Gamexplain(const Napi::CallbackInfo &info) {
public: Napi::Env env = info.Env();
GamexplainWorker(Napi::Function& callback, string in_path, string type, int delay)
: Napi::AsyncWorker(callback), in_path(in_path), type(type), delay(delay) {} Napi::Object obj = info[0].As<Napi::Object>();
~GamexplainWorker() {} string path = obj.Get("path").As<Napi::String>().Utf8Value();
string type = obj.Get("type").As<Napi::String>().Utf8Value();
int delay =
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
Blob blob;
void Execute() {
list<Image> frames; list<Image> frames;
list<Image> coalesced; list<Image> coalesced;
list<Image> mid; list<Image> mid;
Image watermark; Image watermark;
readImages(&frames, in_path); readImages(&frames, path);
watermark.read("./assets/images/gamexplain.png"); watermark.read("./assets/images/gamexplain.png");
coalesceImages(&coalesced, frames.begin(), frames.end()); coalesceImages(&coalesced, frames.begin(), frames.end());
@ -40,29 +45,10 @@ class GamexplainWorker : public Napi::AsyncWorker {
} }
writeImages(mid.begin(), mid.end(), &blob); writeImages(mid.begin(), mid.end(), &blob);
}
Napi::Object result = Napi::Object::New(env);
void OnOK() { result.Set("data",
Callback().Call({Env().Undefined(), Napi::Buffer<char>::Copy(Env(), (char *)blob.data(), blob.length()), Napi::String::From(Env(), type)}); Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
} result.Set("type", type);
return result;
private:
string in_path, type;
int delay;
Blob blob;
};
Napi::Value Gamexplain(const Napi::CallbackInfo &info)
{
Napi::Env env = info.Env();
Napi::Object obj = info[0].As<Napi::Object>();
Napi::Function cb = info[1].As<Napi::Function>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
string type = obj.Get("type").As<Napi::String>().Utf8Value();
int delay = obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
GamexplainWorker* blurWorker = new GamexplainWorker(cb, path, type, delay);
blurWorker->Queue();
return env.Undefined();
} }

View file

@ -1,23 +1,28 @@
#include <napi.h>
#include <list>
#include <Magick++.h> #include <Magick++.h>
#include <napi.h>
#include <list>
using namespace std; using namespace std;
using namespace Magick; using namespace Magick;
class GlobeWorker : public Napi::AsyncWorker { Napi::Value Globe(const Napi::CallbackInfo &info) {
public: Napi::Env env = info.Env();
GlobeWorker(Napi::Function& callback, string in_path, string type, int delay)
: Napi::AsyncWorker(callback), in_path(in_path), type(type), delay(delay) {} Napi::Object obj = info[0].As<Napi::Object>();
~GlobeWorker() {} string path = obj.Get("path").As<Napi::String>().Utf8Value();
string type = obj.Get("type").As<Napi::String>().Utf8Value();
int delay =
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
Blob blob;
void Execute() {
list<Image> frames; list<Image> frames;
list<Image> coalesced; list<Image> coalesced;
list<Image> mid; list<Image> mid;
Image distort; Image distort;
Image overlay; Image overlay;
readImages(&frames, in_path); readImages(&frames, path);
distort.read("./assets/images/spheremap.png"); distort.read("./assets/images/spheremap.png");
overlay.read("./assets/images/sphere_overlay.png"); overlay.read("./assets/images/sphere_overlay.png");
coalesceImages(&coalesced, frames.begin(), frames.end()); coalesceImages(&coalesced, frames.begin(), frames.end());
@ -35,7 +40,8 @@ class GlobeWorker : public Napi::AsyncWorker {
image.alphaChannel(Magick::SetAlphaChannel); image.alphaChannel(Magick::SetAlphaChannel);
size_t width = image.columns(); size_t width = image.columns();
image.roll(Geometry("+" + to_string(width * i / coalesced.size()))); image.roll(Geometry("+" + to_string(width * i / coalesced.size())));
image.composite(overlay, Magick::CenterGravity, Magick::HardLightCompositeOp); image.composite(overlay, Magick::CenterGravity,
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);
@ -55,29 +61,10 @@ class GlobeWorker : public Napi::AsyncWorker {
} }
writeImages(mid.begin(), mid.end(), &blob); writeImages(mid.begin(), mid.end(), &blob);
}
Napi::Object result = Napi::Object::New(env);
void OnOK() { result.Set("data",
Callback().Call({Env().Undefined(), Napi::Buffer<char>::Copy(Env(), (char *)blob.data(), blob.length()), Napi::String::From(Env(), "gif")}); Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
} result.Set("type", type);
return result;
private:
string in_path, type;
int delay;
Blob blob;
};
Napi::Value Globe(const Napi::CallbackInfo &info)
{
Napi::Env env = info.Env();
Napi::Object obj = info[0].As<Napi::Object>();
Napi::Function cb = info[1].As<Napi::Function>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
string type = obj.Get("type").As<Napi::String>().Utf8Value();
int delay = obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
GlobeWorker* blurWorker = new GlobeWorker(cb, path, type, delay);
blurWorker->Queue();
return env.Undefined();
} }

View file

@ -1,17 +1,19 @@
#include <napi.h>
#include <list>
#include <Magick++.h> #include <Magick++.h>
#include <napi.h>
#include <list>
using namespace std; using namespace std;
using namespace Magick; using namespace Magick;
class HomebrewWorker : public Napi::AsyncWorker { Napi::Value Homebrew(const Napi::CallbackInfo &info) {
public: Napi::Env env = info.Env();
HomebrewWorker(Napi::Function& callback, string text)
: Napi::AsyncWorker(callback), text(text) {} Napi::Object obj = info[0].As<Napi::Object>();
~HomebrewWorker() {} string caption = obj.Get("caption").As<Napi::String>().Utf8Value();
Blob blob;
void Execute() {
Image image; Image image;
image.read("./assets/images/hbc.png"); image.read("./assets/images/hbc.png");
image.textGravity(Magick::CenterGravity); image.textGravity(Magick::CenterGravity);
@ -19,29 +21,13 @@ class HomebrewWorker : public Napi::AsyncWorker {
image.textKerning(-5); image.textKerning(-5);
image.fillColor("white"); image.fillColor("white");
image.fontPointsize(96); image.fontPointsize(96);
image.draw(DrawableText(0, 0, text)); image.draw(DrawableText(0, 0, caption));
image.magick("PNG"); image.magick("PNG");
image.write(&blob); image.write(&blob);
}
Napi::Object result = Napi::Object::New(env);
void OnOK() { result.Set("data",
Callback().Call({Env().Undefined(), Napi::Buffer<char>::Copy(Env(), (char *)blob.data(), blob.length()), Napi::String::From(Env(), "png")}); Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
} result.Set("type", "png");
return result;
private:
string text;
Blob blob;
};
Napi::Value Homebrew(const Napi::CallbackInfo &info)
{
Napi::Env env = info.Env();
Napi::Object obj = info[0].As<Napi::Object>();
Napi::Function cb = info[1].As<Napi::Function>();
string caption = obj.Get("caption").As<Napi::String>().Utf8Value();
HomebrewWorker* explodeWorker = new HomebrewWorker(cb, caption);
explodeWorker->Queue();
return env.Undefined();
} }

View file

@ -19,7 +19,7 @@
#include "magik.h" #include "magik.h"
#include "meme.h" #include "meme.h"
#include "mirror.h" #include "mirror.h"
#include "misc.h" #include "swirl.h"
#include "motivate.h" #include "motivate.h"
#include "resize.h" #include "resize.h"
#include "retro.h" #include "retro.h"

View file

@ -1,21 +1,26 @@
#include <napi.h>
#include <list>
#include <Magick++.h> #include <Magick++.h>
#include <napi.h>
#include <list>
using namespace std; using namespace std;
using namespace Magick; using namespace Magick;
class InvertWorker : public Napi::AsyncWorker { Napi::Value Invert(const Napi::CallbackInfo &info) {
public: Napi::Env env = info.Env();
InvertWorker(Napi::Function& callback, string in_path, string type, int delay)
: Napi::AsyncWorker(callback), in_path(in_path), type(type), delay(delay) {} Napi::Object obj = info[0].As<Napi::Object>();
~InvertWorker() {} string path = obj.Get("path").As<Napi::String>().Utf8Value();
string type = obj.Get("type").As<Napi::String>().Utf8Value();
int delay =
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
Blob blob;
void Execute() {
list<Image> frames; list<Image> frames;
list<Image> coalesced; list<Image> coalesced;
list<Image> mid; list<Image> mid;
readImages(&frames, in_path); readImages(&frames, path);
coalesceImages(&coalesced, frames.begin(), frames.end()); coalesceImages(&coalesced, frames.begin(), frames.end());
for_each(coalesced.begin(), coalesced.end(), negateImage()); for_each(coalesced.begin(), coalesced.end(), negateImage());
@ -37,29 +42,10 @@ class InvertWorker : public Napi::AsyncWorker {
} }
writeImages(mid.begin(), mid.end(), &blob); writeImages(mid.begin(), mid.end(), &blob);
}
Napi::Object result = Napi::Object::New(env);
void OnOK() { result.Set("data",
Callback().Call({Env().Undefined(), Napi::Buffer<char>::Copy(Env(), (char *)blob.data(), blob.length()), Napi::String::From(Env(), type)}); Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
} result.Set("type", type);
return result;
private:
string in_path, type;
int delay;
Blob blob;
};
Napi::Value Invert(const Napi::CallbackInfo &info)
{
Napi::Env env = info.Env();
Napi::Object obj = info[0].As<Napi::Object>();
Napi::Function cb = info[1].As<Napi::Function>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
string type = obj.Get("type").As<Napi::String>().Utf8Value();
int delay = obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
InvertWorker* invertWorker = new InvertWorker(cb, path, type, delay);
invertWorker->Queue();
return env.Undefined();
} }

View file

@ -1,42 +1,28 @@
#include <napi.h>
#include <list>
#include <Magick++.h> #include <Magick++.h>
#include <napi.h>
#include <list>
using namespace std; using namespace std;
using namespace Magick; using namespace Magick;
class JpegWorker : public Napi::AsyncWorker { Napi::Value Jpeg(const Napi::CallbackInfo &info) {
public:
JpegWorker(Napi::Function& callback, string in_path)
: Napi::AsyncWorker(callback), in_path(in_path) {}
~JpegWorker() {}
void Execute() {
Image image;
image.read(in_path);
image.quality(1);
image.magick("JPEG");
image.write(&blob);
}
void OnOK() {
Callback().Call({Env().Undefined(), Napi::Buffer<char>::Copy(Env(), (char *)blob.data(), blob.length()), Napi::String::From(Env(), "jpg")});
}
private:
string in_path;
Blob blob;
};
Napi::Value Jpeg(const Napi::CallbackInfo &info)
{
Napi::Env env = info.Env(); Napi::Env env = info.Env();
Napi::Object obj = info[0].As<Napi::Object>(); Napi::Object obj = info[0].As<Napi::Object>();
Napi::Function cb = info[1].As<Napi::Function>();
string path = obj.Get("path").As<Napi::String>().Utf8Value(); string path = obj.Get("path").As<Napi::String>().Utf8Value();
JpegWorker* explodeWorker = new JpegWorker(cb, path); Blob blob;
explodeWorker->Queue();
return env.Undefined(); Image image;
image.read(path);
image.quality(1);
image.magick("JPEG");
image.write(&blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("type", "jpg");
return result;
} }

View file

@ -1,22 +1,27 @@
#include <napi.h>
#include <list>
#include <Magick++.h> #include <Magick++.h>
#include <napi.h>
#include <list>
using namespace std; using namespace std;
using namespace Magick; using namespace Magick;
class LeakWorker : public Napi::AsyncWorker { Napi::Value Leak(const Napi::CallbackInfo &info) {
public: Napi::Env env = info.Env();
LeakWorker(Napi::Function& callback, string in_path, string type, int delay)
: Napi::AsyncWorker(callback), in_path(in_path), type(type), delay(delay) {} Napi::Object obj = info[0].As<Napi::Object>();
~LeakWorker() {} string path = obj.Get("path").As<Napi::String>().Utf8Value();
string type = obj.Get("type").As<Napi::String>().Utf8Value();
int delay =
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
Blob blob;
void Execute() {
list<Image> frames; list<Image> frames;
list<Image> coalesced; list<Image> coalesced;
list<Image> mid; list<Image> mid;
Image watermark; Image watermark;
readImages(&frames, in_path); readImages(&frames, path);
watermark.read("./assets/images/leak.png"); watermark.read("./assets/images/leak.png");
coalesceImages(&coalesced, frames.begin(), frames.end()); coalesceImages(&coalesced, frames.begin(), frames.end());
@ -41,29 +46,10 @@ class LeakWorker : public Napi::AsyncWorker {
} }
writeImages(mid.begin(), mid.end(), &blob); writeImages(mid.begin(), mid.end(), &blob);
}
Napi::Object result = Napi::Object::New(env);
void OnOK() { result.Set("data",
Callback().Call({Env().Undefined(), Napi::Buffer<char>::Copy(Env(), (char *)blob.data(), blob.length()), Napi::String::From(Env(), type)}); Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
} result.Set("type", type);
return result;
private:
string in_path, type;
int delay;
Blob blob;
};
Napi::Value Leak(const Napi::CallbackInfo &info)
{
Napi::Env env = info.Env();
Napi::Object obj = info[0].As<Napi::Object>();
Napi::Function cb = info[1].As<Napi::Function>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
string type = obj.Get("type").As<Napi::String>().Utf8Value();
int delay = obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
LeakWorker* blurWorker = new LeakWorker(cb, path, type, delay);
blurWorker->Queue();
return env.Undefined();
} }

View file

@ -1,21 +1,26 @@
#include <napi.h>
#include <list>
#include <Magick++.h> #include <Magick++.h>
#include <napi.h>
#include <list>
using namespace std; using namespace std;
using namespace Magick; using namespace Magick;
class MagikWorker : public Napi::AsyncWorker { Napi::Value Magik(const Napi::CallbackInfo &info) {
public: Napi::Env env = info.Env();
MagikWorker(Napi::Function& callback, string in_path, string type, int delay)
: Napi::AsyncWorker(callback), in_path(in_path), type(type), delay(delay) {} Napi::Object obj = info[0].As<Napi::Object>();
~MagikWorker() {} string path = obj.Get("path").As<Napi::String>().Utf8Value();
string type = obj.Get("type").As<Napi::String>().Utf8Value();
int delay =
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
Blob blob;
void Execute() {
list<Image> frames; list<Image> frames;
list<Image> coalesced; list<Image> coalesced;
list<Image> blurred; list<Image> blurred;
readImages(&frames, in_path); readImages(&frames, path);
coalesceImages(&coalesced, frames.begin(), frames.end()); coalesceImages(&coalesced, frames.begin(), frames.end());
for (Image &image : coalesced) { for (Image &image : coalesced) {
@ -37,30 +42,10 @@ class MagikWorker : public Napi::AsyncWorker {
} }
writeImages(blurred.begin(), blurred.end(), &blob); writeImages(blurred.begin(), blurred.end(), &blob);
}
Napi::Object result = Napi::Object::New(env);
void OnOK() { result.Set("data",
Callback().Call({Env().Undefined(), Napi::Buffer<char>::Copy(Env(), (char *)blob.data(), blob.length()), Napi::String::From(Env(), type)}); Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
} result.Set("type", type);
return result;
private:
string in_path, type;
int delay;
Blob blob;
};
Napi::Value Magik(const Napi::CallbackInfo &info)
{
Napi::Env env = info.Env();
Napi::Object obj = info[0].As<Napi::Object>();
Napi::Function cb = info[1].As<Napi::Function>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
string type = obj.Get("type").As<Napi::String>().Utf8Value();
int delay = obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
MagikWorker* explodeWorker = new MagikWorker(cb, path, type, delay);
explodeWorker->Queue();
return env.Undefined();
} }

View file

@ -1,23 +1,30 @@
#include <napi.h>
#include <list>
#include <Magick++.h> #include <Magick++.h>
#include <napi.h>
#include <list>
using namespace std; using namespace std;
using namespace Magick; using namespace Magick;
class MemeWorker : public Napi::AsyncWorker { Napi::Value Meme(const Napi::CallbackInfo &info) {
public: Napi::Env env = info.Env();
MemeWorker(Napi::Function& callback, string in_path, string text_top, string text_bottom, string type, int delay)
: Napi::AsyncWorker(callback), in_path(in_path), text_top(text_top), text_bottom(text_bottom), type(type), delay(delay) {} Napi::Object obj = info[0].As<Napi::Object>();
~MemeWorker() {} string path = obj.Get("path").As<Napi::String>().Utf8Value();
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();
int delay =
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
Blob blob;
void Execute() {
list<Image> frames; list<Image> frames;
list<Image> coalesced; list<Image> coalesced;
list<Image> mid; list<Image> mid;
Image top_text; Image top_text;
Image bottom_text; Image bottom_text;
readImages(&frames, in_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)));
@ -26,32 +33,36 @@ class MemeWorker : public Napi::AsyncWorker {
top_text.font("Impact"); top_text.font("Impact");
top_text.fontPointsize(40); top_text.fontPointsize(40);
top_text.textGravity(Magick::CenterGravity); top_text.textGravity(Magick::CenterGravity);
top_text.read("pango:<span foreground='white'>" + text_top + "</span>"); top_text.read("pango:<span foreground='white'>" + top + "</span>");
Image top_text_fill = top_text; Image top_text_fill = top_text;
top_text_fill.channel(Magick::AlphaChannel); top_text_fill.channel(Magick::AlphaChannel);
top_text_fill.morphology(Magick::EdgeOutMorphology, "Octagon"); top_text_fill.morphology(Magick::EdgeOutMorphology, "Octagon");
top_text_fill.backgroundColor("black"); top_text_fill.backgroundColor("black");
top_text_fill.alphaChannel(Magick::ShapeAlphaChannel); top_text_fill.alphaChannel(Magick::ShapeAlphaChannel);
top_text.composite(top_text_fill, Magick::CenterGravity, Magick::DstOverCompositeOp); top_text.composite(top_text_fill, Magick::CenterGravity,
Magick::DstOverCompositeOp);
if (text_bottom != "") { if (bottom != "") {
bottom_text.size(Geometry(to_string(coalesced.front().columns()))); bottom_text.size(Geometry(to_string(coalesced.front().columns())));
bottom_text.backgroundColor("none"); bottom_text.backgroundColor("none");
bottom_text.font("Impact"); bottom_text.font("Impact");
bottom_text.fontPointsize(40); bottom_text.fontPointsize(40);
bottom_text.textGravity(Magick::CenterGravity); bottom_text.textGravity(Magick::CenterGravity);
bottom_text.read("pango:<span foreground='white'>" + text_bottom + "</span>"); bottom_text.read("pango:<span foreground='white'>" + bottom + "</span>");
Image bottom_text_fill = bottom_text; Image bottom_text_fill = bottom_text;
bottom_text_fill.channel(Magick::AlphaChannel); bottom_text_fill.channel(Magick::AlphaChannel);
bottom_text_fill.morphology(Magick::EdgeOutMorphology, "Octagon"); bottom_text_fill.morphology(Magick::EdgeOutMorphology, "Octagon");
bottom_text_fill.backgroundColor("black"); bottom_text_fill.backgroundColor("black");
bottom_text_fill.alphaChannel(Magick::ShapeAlphaChannel); bottom_text_fill.alphaChannel(Magick::ShapeAlphaChannel);
bottom_text.composite(bottom_text_fill, Magick::CenterGravity, Magick::DstOverCompositeOp); bottom_text.composite(bottom_text_fill, Magick::CenterGravity,
Magick::DstOverCompositeOp);
} }
for (Image &image : coalesced) { for (Image &image : coalesced) {
image.composite(top_text, Magick::NorthGravity, Magick::OverCompositeOp); image.composite(top_text, Magick::NorthGravity, Magick::OverCompositeOp);
if (text_bottom != "") image.composite(bottom_text, Magick::SouthGravity, Magick::OverCompositeOp); if (bottom != "")
image.composite(bottom_text, Magick::SouthGravity,
Magick::OverCompositeOp);
image.magick(type); image.magick(type);
mid.push_back(image); mid.push_back(image);
} }
@ -67,31 +78,10 @@ class MemeWorker : public Napi::AsyncWorker {
} }
writeImages(mid.begin(), mid.end(), &blob); writeImages(mid.begin(), mid.end(), &blob);
}
Napi::Object result = Napi::Object::New(env);
void OnOK() { result.Set("data",
Callback().Call({Env().Undefined(), Napi::Buffer<char>::Copy(Env(), (char *)blob.data(), blob.length()), Napi::String::From(Env(), type)}); Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
} result.Set("type", type);
return result;
private:
string in_path, type, text_top, text_bottom;
int delay;
Blob blob;
};
Napi::Value Meme(const Napi::CallbackInfo &info)
{
Napi::Env env = info.Env();
Napi::Object obj = info[0].As<Napi::Object>();
Napi::Function cb = info[1].As<Napi::Function>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
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();
int delay = obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
MemeWorker* blurWorker = new MemeWorker(cb, path, top, bottom, type, delay);
blurWorker->Queue();
return env.Undefined();
} }

View file

@ -1,22 +1,32 @@
#include <napi.h>
#include <list>
#include <Magick++.h> #include <Magick++.h>
#include <napi.h>
#include <list>
using namespace std; using namespace std;
using namespace Magick; using namespace Magick;
class MirrorWorker : public Napi::AsyncWorker { Napi::Value Mirror(const Napi::CallbackInfo &info) {
public: Napi::Env env = info.Env();
MirrorWorker(Napi::Function& callback, string in_path, bool vertical, bool first, string type, int delay)
: Napi::AsyncWorker(callback), in_path(in_path), vertical(vertical), first(first), type(type), delay(delay) {} Napi::Object obj = info[0].As<Napi::Object>();
~MirrorWorker() {} string path = obj.Get("path").As<Napi::String>().Utf8Value();
bool vertical = obj.Has("vertical")
? obj.Get("vertical").As<Napi::Boolean>().Value()
: false;
bool first =
obj.Has("first") ? obj.Get("first").As<Napi::Boolean>().Value() : false;
string type = obj.Get("type").As<Napi::String>().Utf8Value();
int delay =
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
Blob blob;
void Execute() {
list<Image> frames; list<Image> frames;
list<Image> coalesced; list<Image> coalesced;
list<Image> mid; list<Image> mid;
MagickCore::GravityType gravity; MagickCore::GravityType gravity;
readImages(&frames, in_path); readImages(&frames, path);
coalesceImages(&coalesced, frames.begin(), frames.end()); coalesceImages(&coalesced, frames.begin(), frames.end());
if (vertical && first) { if (vertical && first) {
@ -32,7 +42,12 @@ class MirrorWorker : public Napi::AsyncWorker {
for (Image &image : coalesced) { for (Image &image : coalesced) {
list<Image> mirrored; list<Image> mirrored;
Image final; Image final;
image.extent(Geometry(to_string(vertical ? image.baseColumns() : image.baseColumns() / 2) + "x" + to_string(vertical ? image.baseRows() / 2 : image.baseRows())), gravity); image.extent(
Geometry(to_string(vertical ? image.baseColumns()
: image.baseColumns() / 2) +
"x" +
to_string(vertical ? image.baseRows() / 2 : image.baseRows())),
gravity);
mirrored.push_back(image); mirrored.push_back(image);
Image mirror = image; Image mirror = image;
if (vertical) { if (vertical) {
@ -62,32 +77,10 @@ class MirrorWorker : public Napi::AsyncWorker {
} }
writeImages(mid.begin(), mid.end(), &blob); writeImages(mid.begin(), mid.end(), &blob);
}
Napi::Object result = Napi::Object::New(env);
void OnOK() { result.Set("data",
Callback().Call({Env().Undefined(), Napi::Buffer<char>::Copy(Env(), (char *)blob.data(), blob.length()), Napi::String::From(Env(), type)}); Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
} result.Set("type", type);
return result;
private:
string in_path, type;
int delay;
bool vertical, first;
Blob blob;
};
Napi::Value Mirror(const Napi::CallbackInfo &info)
{
Napi::Env env = info.Env();
Napi::Object obj = info[0].As<Napi::Object>();
Napi::Function cb = info[1].As<Napi::Function>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
bool vertical = obj.Has("vertical") ? obj.Get("vertical").As<Napi::Boolean>().Value() : false;
bool first = obj.Has("first") ? obj.Get("first").As<Napi::Boolean>().Value() : false;
string type = obj.Get("type").As<Napi::String>().Utf8Value();
int delay = obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
MirrorWorker* mirrorWorker = new MirrorWorker(cb, path, vertical, first, type, delay);
mirrorWorker->Queue();
return env.Undefined();
} }

View file

@ -1,63 +0,0 @@
#include <napi.h>
#include <list>
#include <Magick++.h>
using namespace std;
using namespace Magick;
class SwirlWorker : public Napi::AsyncWorker {
public:
SwirlWorker(Napi::Function& callback, string in_path, string type, int delay)
: Napi::AsyncWorker(callback), in_path(in_path), type(type), delay(delay) {}
~SwirlWorker() {}
void Execute() {
list <Image> frames;
list <Image> coalesced;
list <Image> mid;
readImages(&frames, in_path);
coalesceImages(&coalesced, frames.begin(), frames.end());
for (Image &image : coalesced) {
image.swirl(180);
image.magick(type);
mid.push_back(image);
}
optimizeTransparency(mid.begin(), mid.end());
if (type == "gif") {
for (Image &image : mid) {
image.quantizeDither(false);
image.quantize();
if (delay != 0) image.animationDelay(delay);
}
}
writeImages(mid.begin(), mid.end(), &blob);
}
void OnOK() {
Callback().Call({Env().Undefined(), Napi::Buffer<char>::Copy(Env(), (char *)blob.data(), blob.length()), Napi::String::From(Env(), type)});
}
private:
string in_path, type;
int delay;
Blob blob;
};
Napi::Value Swirl(const Napi::CallbackInfo &info)
{
Napi::Env env = info.Env();
Napi::Object obj = info[0].As<Napi::Object>();
Napi::Function cb = info[1].As<Napi::Function>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
string type = obj.Get("type").As<Napi::String>().Utf8Value();
int delay = obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
SwirlWorker* flopWorker = new SwirlWorker(cb, path, type, delay);
flopWorker->Queue();
return env.Undefined();
}

View file

@ -1,23 +1,30 @@
#include <napi.h>
#include <list>
#include <Magick++.h> #include <Magick++.h>
#include <napi.h>
#include <list>
using namespace std; using namespace std;
using namespace Magick; using namespace Magick;
class MotivateWorker : public Napi::AsyncWorker { Napi::Value Motivate(const Napi::CallbackInfo &info) {
public: Napi::Env env = info.Env();
MotivateWorker(Napi::Function& callback, string in_path, string top_text, string bottom_text, string type, int delay)
: Napi::AsyncWorker(callback), in_path(in_path), top_text(top_text), bottom_text(bottom_text), type(type), delay(delay) {} Napi::Object obj = info[0].As<Napi::Object>();
~MotivateWorker() {} string path = obj.Get("path").As<Napi::String>().Utf8Value();
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();
int delay =
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
Blob blob;
void Execute() {
list<Image> frames; list<Image> frames;
list<Image> coalesced; list<Image> coalesced;
list<Image> mid; list<Image> mid;
Image top; Image top;
Image bottom; Image bottom;
readImages(&frames, in_path); readImages(&frames, path);
coalesceImages(&coalesced, frames.begin(), frames.end()); coalesceImages(&coalesced, frames.begin(), frames.end());
top.size(Geometry("600")); top.size(Geometry("600"));
@ -26,7 +33,11 @@ class MotivateWorker : public Napi::AsyncWorker {
top.textGravity(Magick::CenterGravity); top.textGravity(Magick::CenterGravity);
top.fontPointsize(56); top.fontPointsize(56);
top.read("pango:<span foreground='white'>" + top_text + "</span>"); top.read("pango:<span foreground='white'>" + top_text + "</span>");
top.extent(Geometry(bottom_text != "" ? to_string(top.columns()) + "x" + to_string(top.rows()) : to_string(top.columns()) + "x" + to_string(top.rows() + 20)), "black", Magick::NorthGravity); top.extent(Geometry(bottom_text != "" ? to_string(top.columns()) + "x" +
to_string(top.rows())
: to_string(top.columns()) + "x" +
to_string(top.rows() + 20)),
"black", Magick::NorthGravity);
if (bottom_text != "") { if (bottom_text != "") {
bottom.size(Geometry("600")); bottom.size(Geometry("600"));
@ -35,7 +46,9 @@ class MotivateWorker : public Napi::AsyncWorker {
bottom.textGravity(Magick::CenterGravity); bottom.textGravity(Magick::CenterGravity);
bottom.fontPointsize(28); bottom.fontPointsize(28);
bottom.read("pango:<span foreground='white'>" + bottom_text + "</span>"); bottom.read("pango:<span foreground='white'>" + bottom_text + "</span>");
bottom.extent(Geometry(to_string(bottom.columns()) + "x" + to_string(bottom.rows() + 20)), "black", Magick::NorthGravity); bottom.extent(Geometry(to_string(bottom.columns()) + "x" +
to_string(bottom.rows() + 20)),
"black", Magick::NorthGravity);
} }
for (Image &image : coalesced) { for (Image &image : coalesced) {
@ -69,31 +82,10 @@ class MotivateWorker : public Napi::AsyncWorker {
} }
writeImages(mid.begin(), mid.end(), &blob); writeImages(mid.begin(), mid.end(), &blob);
}
Napi::Object result = Napi::Object::New(env);
void OnOK() { result.Set("data",
Callback().Call({Env().Undefined(), Napi::Buffer<char>::Copy(Env(), (char *)blob.data(), blob.length()), Napi::String::From(Env(), type)}); Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
} result.Set("type", type);
return result;
private:
string in_path, type, top_text, bottom_text;
int delay;
Blob blob;
};
Napi::Value Motivate(const Napi::CallbackInfo &info)
{
Napi::Env env = info.Env();
Napi::Object obj = info[0].As<Napi::Object>();
Napi::Function cb = info[1].As<Napi::Function>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
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();
int delay = obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
MotivateWorker* blurWorker = new MotivateWorker(cb, path, top, bottom, type, delay);
blurWorker->Queue();
return env.Undefined();
} }

View file

@ -1,28 +1,39 @@
#include <napi.h>
#include <list>
#include <Magick++.h> #include <Magick++.h>
#include <napi.h>
#include <list>
using namespace std; using namespace std;
using namespace Magick; using namespace Magick;
class ResizeWorker : public Napi::AsyncWorker { Napi::Value Resize(const Napi::CallbackInfo &info) {
public: Napi::Env env = info.Env();
ResizeWorker(Napi::Function& callback, string in_path, bool stretch, bool wide, string type, int delay)
: Napi::AsyncWorker(callback), in_path(in_path), stretch(stretch), wide(wide), type(type), delay(delay) {} Napi::Object obj = info[0].As<Napi::Object>();
~ResizeWorker() {} string path = obj.Get("path").As<Napi::String>().Utf8Value();
bool stretch = obj.Has("stretch")
? obj.Get("stretch").As<Napi::Boolean>().Value()
: false;
bool wide =
obj.Has("wide") ? obj.Get("wide").As<Napi::Boolean>().Value() : false;
string type = obj.Get("type").As<Napi::String>().Utf8Value();
int delay =
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
Blob blob;
void Execute() {
list<Image> frames; list<Image> frames;
list<Image> coalesced; list<Image> coalesced;
list<Image> blurred; list<Image> blurred;
readImages(&frames, in_path); readImages(&frames, path);
coalesceImages(&coalesced, frames.begin(), frames.end()); coalesceImages(&coalesced, frames.begin(), frames.end());
for (Image &image : coalesced) { for (Image &image : coalesced) {
if (stretch) { if (stretch) {
image.resize(Geometry("512x512!")); image.resize(Geometry("512x512!"));
} else if (wide) { } else if (wide) {
image.resize(Geometry(to_string((image.baseColumns() * 19) / 2) + "x" + to_string(image.baseRows() / 2) + "!")); image.resize(Geometry(to_string((image.baseColumns() * 19) / 2) + "x" +
to_string(image.baseRows() / 2) + "!"));
} else { } else {
image.scale(Geometry("10%")); image.scale(Geometry("10%"));
image.scale(Geometry("1000%")); image.scale(Geometry("1000%"));
@ -42,32 +53,10 @@ class ResizeWorker : public Napi::AsyncWorker {
} }
writeImages(blurred.begin(), blurred.end(), &blob); writeImages(blurred.begin(), blurred.end(), &blob);
}
Napi::Object result = Napi::Object::New(env);
void OnOK() { result.Set("data",
Callback().Call({Env().Undefined(), Napi::Buffer<char>::Copy(Env(), (char *)blob.data(), blob.length()), Napi::String::From(Env(), type)}); Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
} result.Set("type", type);
return result;
private:
string in_path, type;
int delay, amount;
Blob blob;
bool stretch, wide;
};
Napi::Value Resize(const Napi::CallbackInfo &info)
{
Napi::Env env = info.Env();
Napi::Object obj = info[0].As<Napi::Object>();
Napi::Function cb = info[1].As<Napi::Function>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
bool stretch = obj.Has("stretch") ? obj.Get("stretch").As<Napi::Boolean>().Value() : false;
bool wide = obj.Has("wide") ? obj.Get("wide").As<Napi::Boolean>().Value() : false;
string type = obj.Get("type").As<Napi::String>().Utf8Value();
int delay = obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
ResizeWorker* explodeWorker = new ResizeWorker(cb, path, stretch, wide, type, delay);
explodeWorker->Queue();
return env.Undefined();
} }

View file

@ -1,17 +1,21 @@
#include <napi.h>
#include <list>
#include <Magick++.h> #include <Magick++.h>
#include <napi.h>
#include <list>
using namespace std; using namespace std;
using namespace Magick; using namespace Magick;
class RetroWorker : public Napi::AsyncWorker { Napi::Value Retro(const Napi::CallbackInfo &info) {
public: Napi::Env env = info.Env();
RetroWorker(Napi::Function& callback, string line1, string line2, string line3)
: Napi::AsyncWorker(callback), line1(line1), line2(line2), line3(line3) {} Napi::Object obj = info[0].As<Napi::Object>();
~RetroWorker() {} string line1 = obj.Get("line1").As<Napi::String>().Utf8Value();
string line2 = obj.Get("line2").As<Napi::String>().Utf8Value();
string line3 = obj.Get("line3").As<Napi::String>().Utf8Value();
Blob blob;
void Execute() {
Image image; Image image;
Image line1_text; Image line1_text;
Image line2_text; Image line2_text;
@ -23,14 +27,16 @@ class RetroWorker : public Napi::AsyncWorker {
line2_text.fontPointsize(128); line2_text.fontPointsize(128);
line2_text.textGravity(Magick::CenterGravity); line2_text.textGravity(Magick::CenterGravity);
line2_text.font("Comic Sans MS"); line2_text.font("Comic Sans MS");
line2_text.read("pango:<span foreground='white'>" + (line2 == "" ? line1 : line2) + "</span>"); line2_text.read("pango:<span foreground='white'>" +
(line2 == "" ? line1 : line2) + "</span>");
line2_text.extent(Geometry("1260x859+0+0"), Magick::CenterGravity); line2_text.extent(Geometry("1260x859+0+0"), Magick::CenterGravity);
Image line2_text_fill = line2_text; Image line2_text_fill = line2_text;
line2_text_fill.channel(Magick::AlphaChannel); line2_text_fill.channel(Magick::AlphaChannel);
line2_text_fill.morphology(Magick::EdgeOutMorphology, "Octagon:10"); line2_text_fill.morphology(Magick::EdgeOutMorphology, "Octagon:10");
line2_text_fill.backgroundColor("gray"); line2_text_fill.backgroundColor("gray");
line2_text_fill.alphaChannel(Magick::ShapeAlphaChannel); line2_text_fill.alphaChannel(Magick::ShapeAlphaChannel);
line2_text.composite(line2_text_fill, Magick::CenterGravity, Magick::DstOverCompositeOp); line2_text.composite(line2_text_fill, Magick::CenterGravity,
Magick::DstOverCompositeOp);
image.composite(line2_text, Geometry("+0-100"), Magick::OverCompositeOp); image.composite(line2_text, Geometry("+0-100"), Magick::OverCompositeOp);
if (line2 != "") { if (line2 != "") {
@ -45,7 +51,8 @@ class RetroWorker : public Napi::AsyncWorker {
line1_text_fill.morphology(Magick::EdgeOutMorphology, "Octagon:10"); line1_text_fill.morphology(Magick::EdgeOutMorphology, "Octagon:10");
line1_text_fill.backgroundColor("gray"); line1_text_fill.backgroundColor("gray");
line1_text_fill.alphaChannel(Magick::ShapeAlphaChannel); line1_text_fill.alphaChannel(Magick::ShapeAlphaChannel);
line1_text.composite(line1_text_fill, Magick::CenterGravity, Magick::DstOverCompositeOp); line1_text.composite(line1_text_fill, Magick::CenterGravity,
Magick::DstOverCompositeOp);
image.composite(line1_text, Geometry("+0-250"), Magick::OverCompositeOp); image.composite(line1_text, Geometry("+0-250"), Magick::OverCompositeOp);
} }
@ -61,34 +68,17 @@ class RetroWorker : public Napi::AsyncWorker {
line3_text_fill.morphology(Magick::EdgeOutMorphology, "Octagon:10"); line3_text_fill.morphology(Magick::EdgeOutMorphology, "Octagon:10");
line3_text_fill.backgroundColor("gray"); line3_text_fill.backgroundColor("gray");
line3_text_fill.alphaChannel(Magick::ShapeAlphaChannel); line3_text_fill.alphaChannel(Magick::ShapeAlphaChannel);
line3_text.composite(line3_text_fill, Magick::CenterGravity, Magick::DstOverCompositeOp); line3_text.composite(line3_text_fill, Magick::CenterGravity,
Magick::DstOverCompositeOp);
image.composite(line3_text, Geometry("+0+50"), Magick::OverCompositeOp); image.composite(line3_text, Geometry("+0+50"), Magick::OverCompositeOp);
} }
image.magick("PNG"); image.magick("PNG");
image.write(&blob); image.write(&blob);
}
Napi::Object result = Napi::Object::New(env);
void OnOK() { result.Set("data",
Callback().Call({Env().Undefined(), Napi::Buffer<char>::Copy(Env(), (char *)blob.data(), blob.length()), Napi::String::From(Env(), "png")}); Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
} result.Set("type", "png");
return result;
private:
string line1, line2, line3;
Blob blob;
};
Napi::Value Retro(const Napi::CallbackInfo &info)
{
Napi::Env env = info.Env();
Napi::Object obj = info[0].As<Napi::Object>();
Napi::Function cb = info[1].As<Napi::Function>();
string line1 = obj.Get("line1").As<Napi::String>().Utf8Value();
string line2 = obj.Get("line2").As<Napi::String>().Utf8Value();
string line3 = obj.Get("line3").As<Napi::String>().Utf8Value();
RetroWorker* retroWorker = new RetroWorker(cb, line1, line2, line3);
retroWorker->Queue();
return env.Undefined();
} }

View file

@ -1,20 +1,26 @@
#include <napi.h>
#include <list>
#include <Magick++.h> #include <Magick++.h>
#include <napi.h>
#include <list>
using namespace std; using namespace std;
using namespace Magick; using namespace Magick;
class ReverseWorker : public Napi::AsyncWorker { Napi::Value Reverse(const Napi::CallbackInfo &info) {
public: Napi::Env env = info.Env();
ReverseWorker(Napi::Function& callback, string in_path, bool soos, int delay)
: Napi::AsyncWorker(callback), in_path(in_path), soos(soos), delay(delay) {} Napi::Object obj = info[0].As<Napi::Object>();
~ReverseWorker() {} string path = obj.Get("path").As<Napi::String>().Utf8Value();
bool soos =
obj.Has("soos") ? obj.Get("soos").As<Napi::Boolean>().Value() : false;
int delay =
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
Blob blob;
void Execute() {
list<Image> frames; list<Image> frames;
list<Image> coalesced; list<Image> coalesced;
readImages(&frames, in_path); readImages(&frames, path);
coalesceImages(&coalesced, frames.begin(), frames.end()); coalesceImages(&coalesced, frames.begin(), frames.end());
if (soos) { if (soos) {
@ -36,30 +42,10 @@ class ReverseWorker : public Napi::AsyncWorker {
} }
writeImages(coalesced.begin(), coalesced.end(), &blob); writeImages(coalesced.begin(), coalesced.end(), &blob);
}
Napi::Object result = Napi::Object::New(env);
void OnOK() { result.Set("data",
Callback().Call({Env().Undefined(), Napi::Buffer<char>::Copy(Env(), (char *)blob.data(), blob.length()), Napi::String::From(Env(), "gif")}); Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
} result.Set("type", "gif");
return result;
private:
string in_path;
int delay;
Blob blob;
bool soos;
};
Napi::Value Reverse(const Napi::CallbackInfo &info)
{
Napi::Env env = info.Env();
Napi::Object obj = info[0].As<Napi::Object>();
Napi::Function cb = info[1].As<Napi::Function>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
bool soos = obj.Has("soos") ? obj.Get("soos").As<Napi::Boolean>().Value() : false;
int delay = obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
ReverseWorker* explodeWorker = new ReverseWorker(cb, path, soos, delay);
explodeWorker->Queue();
return env.Undefined();
} }

View file

@ -1,22 +1,27 @@
#include <napi.h>
#include <list>
#include <Magick++.h> #include <Magick++.h>
#include <napi.h>
#include <list>
using namespace std; using namespace std;
using namespace Magick; using namespace Magick;
class ScottWorker : public Napi::AsyncWorker { Napi::Value Scott(const Napi::CallbackInfo &info) {
public: Napi::Env env = info.Env();
ScottWorker(Napi::Function& callback, string in_path, string type, int delay)
: Napi::AsyncWorker(callback), in_path(in_path), type(type), delay(delay) {} Napi::Object obj = info[0].As<Napi::Object>();
~ScottWorker() {} string path = obj.Get("path").As<Napi::String>().Utf8Value();
string type = obj.Get("type").As<Napi::String>().Utf8Value();
int delay =
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
Blob blob;
void Execute() {
list<Image> frames; list<Image> frames;
list<Image> coalesced; list<Image> coalesced;
list<Image> mid; list<Image> mid;
Image watermark; Image watermark;
readImages(&frames, in_path); readImages(&frames, path);
watermark.read("./assets/images/scott.png"); watermark.read("./assets/images/scott.png");
coalesceImages(&coalesced, frames.begin(), frames.end()); coalesceImages(&coalesced, frames.begin(), frames.end());
@ -25,10 +30,12 @@ class ScottWorker : public Napi::AsyncWorker {
image.virtualPixelMethod(Magick::TransparentVirtualPixelMethod); image.virtualPixelMethod(Magick::TransparentVirtualPixelMethod);
image.backgroundColor("none"); image.backgroundColor("none");
image.scale(Geometry("415x234!")); image.scale(Geometry("415x234!"));
double arguments[16] = {0, 0, 129, 187, 415, 0, 517, 182, 415, 234, 517, 465, 0, 234, 132, 418}; double arguments[16] = {0, 0, 129, 187, 415, 0, 517, 182,
415, 234, 517, 465, 0, 234, 132, 418};
image.distort(Magick::PerspectiveDistortion, 16, arguments, true); image.distort(Magick::PerspectiveDistortion, 16, arguments, true);
image.extent(Geometry("864x481"), Magick::CenterGravity); image.extent(Geometry("864x481"), Magick::CenterGravity);
watermark_new.composite(image, Geometry("-110+83"), Magick::OverCompositeOp); watermark_new.composite(image, Geometry("-110+83"),
Magick::OverCompositeOp);
watermark_new.magick(type); watermark_new.magick(type);
watermark_new.animationDelay(delay == 0 ? image.animationDelay() : delay); watermark_new.animationDelay(delay == 0 ? image.animationDelay() : delay);
mid.push_back(watermark_new); mid.push_back(watermark_new);
@ -44,29 +51,10 @@ class ScottWorker : public Napi::AsyncWorker {
} }
writeImages(mid.begin(), mid.end(), &blob); writeImages(mid.begin(), mid.end(), &blob);
}
Napi::Object result = Napi::Object::New(env);
void OnOK() { result.Set("data",
Callback().Call({Env().Undefined(), Napi::Buffer<char>::Copy(Env(), (char *)blob.data(), blob.length()), Napi::String::From(Env(), type)}); Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
} result.Set("type", type);
return result;
private:
string in_path, type;
int delay;
Blob blob;
};
Napi::Value Scott(const Napi::CallbackInfo &info)
{
Napi::Env env = info.Env();
Napi::Object obj = info[0].As<Napi::Object>();
Napi::Function cb = info[1].As<Napi::Function>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
string type = obj.Get("type").As<Napi::String>().Utf8Value();
int delay = obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
ScottWorker* blurWorker = new ScottWorker(cb, path, type, delay);
blurWorker->Queue();
return env.Undefined();
} }

View file

@ -1,17 +1,19 @@
#include <napi.h>
#include <list>
#include <Magick++.h> #include <Magick++.h>
#include <napi.h>
#include <list>
using namespace std; using namespace std;
using namespace Magick; using namespace Magick;
class SonicWorker : public Napi::AsyncWorker { Napi::Value Sonic(const Napi::CallbackInfo &info) {
public: Napi::Env env = info.Env();
SonicWorker(Napi::Function& callback, string text)
: Napi::AsyncWorker(callback), text(text) {} Napi::Object obj = info[0].As<Napi::Object>();
~SonicWorker() {} string text = obj.Get("text").As<Napi::String>().Utf8Value();
Blob blob;
void Execute() {
Image image; Image image;
Image text_image; Image text_image;
text_image.backgroundColor("none"); text_image.backgroundColor("none");
@ -25,26 +27,10 @@ class SonicWorker : public Napi::AsyncWorker {
image.composite(text_image, Geometry("+160+10"), Magick::OverCompositeOp); image.composite(text_image, Geometry("+160+10"), Magick::OverCompositeOp);
image.magick("PNG"); image.magick("PNG");
image.write(&blob); image.write(&blob);
}
Napi::Object result = Napi::Object::New(env);
void OnOK() { result.Set("data",
Callback().Call({Env().Undefined(), Napi::Buffer<char>::Copy(Env(), (char *)blob.data(), blob.length()), Napi::String::From(Env(), "png")}); Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
} result.Set("type", "png");
return result;
private:
string text;
Blob blob;
};
Napi::Value Sonic(const Napi::CallbackInfo &info)
{
Napi::Env env = info.Env();
Napi::Object obj = info[0].As<Napi::Object>();
Napi::Function cb = info[1].As<Napi::Function>();
string text = obj.Get("text").As<Napi::String>().Utf8Value();
SonicWorker* explodeWorker = new SonicWorker(cb, text);
explodeWorker->Queue();
return env.Undefined();
} }

View file

@ -1,19 +1,28 @@
#include <napi.h>
#include <list>
#include <Magick++.h> #include <Magick++.h>
#include <napi.h>
#include <list>
using namespace std; using namespace std;
using namespace Magick; using namespace Magick;
class SpeedWorker : public Napi::AsyncWorker { Napi::Value Speed(const Napi::CallbackInfo &info) {
public: Napi::Env env = info.Env();
SpeedWorker(Napi::Function& callback, string in_path, bool slow, int speed, string type, int delay)
: Napi::AsyncWorker(callback), in_path(in_path), slow(slow), speed(speed), type(type), delay(delay) {} Napi::Object obj = info[0].As<Napi::Object>();
~SpeedWorker() {} string path = obj.Get("path").As<Napi::String>().Utf8Value();
bool slow =
obj.Has("slow") ? obj.Get("slow").As<Napi::Boolean>().Value() : false;
string type = obj.Get("type").As<Napi::String>().Utf8Value();
int delay =
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
int speed =
obj.Has("speed") ? obj.Get("speed").As<Napi::Number>().Int32Value() : 2;
Blob blob;
void Execute() {
list<Image> frames; list<Image> frames;
readImages(&frames, in_path); readImages(&frames, path);
// if passed a delay, use that. otherwise use the average frame delay. // if passed a delay, use that. otherwise use the average frame delay.
if (delay == 0) { if (delay == 0) {
@ -41,18 +50,16 @@ class SpeedWorker : public Napi::AsyncWorker {
} }
for (int i = 0; i < speed - 1; ++i) { for (int i = 0; i < speed - 1; ++i) {
frames.remove_if([counter = 0](const auto x) mutable { frames.remove_if(
return ++counter % 2 == 0; [counter = 0](const auto x) mutable { 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([counter = 0](const auto x) mutable { frames.remove_if(
return ++counter % 2 == 0; [counter = 0](const auto x) mutable { return ++counter % 2 == 0; });
});
} }
} else { } else {
for_each(frames.begin(), frames.end(), animationDelayImage(new_delay)); for_each(frames.begin(), frames.end(), animationDelayImage(new_delay));
@ -62,32 +69,10 @@ class SpeedWorker : public Napi::AsyncWorker {
for_each(frames.begin(), frames.end(), magickImage(type)); for_each(frames.begin(), frames.end(), magickImage(type));
writeImages(frames.begin(), frames.end(), &blob); writeImages(frames.begin(), frames.end(), &blob);
}
Napi::Object result = Napi::Object::New(env);
void OnOK() { result.Set("data",
Callback().Call({Env().Undefined(), Napi::Buffer<char>::Copy(Env(), (char *)blob.data(), blob.length()), Napi::String::From(Env(), type)}); Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
} result.Set("type", type);
return result;
private:
bool slow;
string in_path, type;
int speed, delay;
Blob blob;
};
Napi::Value Speed(const Napi::CallbackInfo &info)
{
Napi::Env env = info.Env();
Napi::Object obj = info[0].As<Napi::Object>();
Napi::Function cb = info[1].As<Napi::Function>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
bool slow = obj.Has("slow") ? obj.Get("slow").As<Napi::Boolean>().Value() : false;
string type = obj.Get("type").As<Napi::String>().Utf8Value();
int delay = obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
int speed = obj.Has("speed") ? obj.Get("speed").As<Napi::Number>().Int32Value() : 2;
SpeedWorker* explodeWorker = new SpeedWorker(cb, path, slow, speed, type, delay);
explodeWorker->Queue();
return env.Undefined();
} }

View file

@ -1,21 +1,26 @@
#include <napi.h>
#include <list>
#include <Magick++.h> #include <Magick++.h>
#include <napi.h>
#include <list>
using namespace std; using namespace std;
using namespace Magick; using namespace Magick;
class SpinWorker : public Napi::AsyncWorker { Napi::Value Spin(const Napi::CallbackInfo &info) {
public: Napi::Env env = info.Env();
SpinWorker(Napi::Function& callback, string in_path, string type, int delay)
: Napi::AsyncWorker(callback), in_path(in_path), type(type), delay(delay) {} Napi::Object obj = info[0].As<Napi::Object>();
~SpinWorker() {} string path = obj.Get("path").As<Napi::String>().Utf8Value();
string type = obj.Get("type").As<Napi::String>().Utf8Value();
int delay =
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
Blob blob;
void Execute() {
list<Image> frames; list<Image> frames;
list<Image> coalesced; list<Image> coalesced;
list<Image> mid; list<Image> mid;
readImages(&frames, in_path); readImages(&frames, path);
coalesceImages(&coalesced, frames.begin(), frames.end()); coalesceImages(&coalesced, frames.begin(), frames.end());
if (type != "gif") { if (type != "gif") {
@ -37,7 +42,8 @@ class SpinWorker : public Napi::AsyncWorker {
i++; i++;
} }
for_each(mid.begin(), mid.end(), gifDisposeMethodImage(Magick::BackgroundDispose)); for_each(mid.begin(), mid.end(),
gifDisposeMethodImage(Magick::BackgroundDispose));
optimizeTransparency(mid.begin(), mid.end()); optimizeTransparency(mid.begin(), mid.end());
if (delay != 0) { if (delay != 0) {
@ -52,29 +58,10 @@ class SpinWorker : public Napi::AsyncWorker {
} }
writeImages(mid.begin(), mid.end(), &blob); writeImages(mid.begin(), mid.end(), &blob);
}
Napi::Object result = Napi::Object::New(env);
void OnOK() { result.Set("data",
Callback().Call({Env().Undefined(), Napi::Buffer<char>::Copy(Env(), (char *)blob.data(), blob.length()), Napi::String::From(Env(), "gif")}); Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
} result.Set("type", "gif");
return result;
private:
string in_path, type;
int delay;
Blob blob;
};
Napi::Value Spin(const Napi::CallbackInfo &info)
{
Napi::Env env = info.Env();
Napi::Object obj = info[0].As<Napi::Object>();
Napi::Function cb = info[1].As<Napi::Function>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
string type = obj.Get("type").As<Napi::String>().Utf8Value();
int delay = obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
SpinWorker* blurWorker = new SpinWorker(cb, path, type, delay);
blurWorker->Queue();
return env.Undefined();
} }

49
natives/swirl.cc Normal file
View file

@ -0,0 +1,49 @@
#include <Magick++.h>
#include <napi.h>
#include <list>
using namespace std;
using namespace Magick;
Napi::Value Swirl(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
Napi::Object obj = info[0].As<Napi::Object>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
string type = obj.Get("type").As<Napi::String>().Utf8Value();
int delay =
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
Blob blob;
list<Image> frames;
list<Image> coalesced;
list<Image> mid;
readImages(&frames, path);
coalesceImages(&coalesced, frames.begin(), frames.end());
for (Image &image : coalesced) {
image.swirl(180);
image.magick(type);
mid.push_back(image);
}
optimizeTransparency(mid.begin(), mid.end());
if (type == "gif") {
for (Image &image : mid) {
image.quantizeDither(false);
image.quantize();
if (delay != 0) image.animationDelay(delay);
}
}
writeImages(mid.begin(), mid.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("type", type);
return result;
}

View file

@ -1,5 +1,5 @@
#ifndef ESMBOT_NATIVES_MISC_H_ #ifndef ESMBOT_NATIVES_SWIRL_H_
#define ESMBOT_NATIVES_MISC_H_ #define ESMBOT_NATIVES_SWIRL_H_
#include <napi.h> #include <napi.h>

View file

@ -1,21 +1,26 @@
#include <napi.h>
#include <list>
#include <Magick++.h> #include <Magick++.h>
#include <napi.h>
#include <list>
using namespace std; using namespace std;
using namespace Magick; using namespace Magick;
class TileWorker : public Napi::AsyncWorker { Napi::Value Tile(const Napi::CallbackInfo &info) {
public: Napi::Env env = info.Env();
TileWorker(Napi::Function& callback, string in_path, string type, int delay)
: Napi::AsyncWorker(callback), in_path(in_path), type(type), delay(delay) {} Napi::Object obj = info[0].As<Napi::Object>();
~TileWorker() {} string path = obj.Get("path").As<Napi::String>().Utf8Value();
string type = obj.Get("type").As<Napi::String>().Utf8Value();
int delay =
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
Blob blob;
void Execute() {
list<Image> frames; list<Image> frames;
list<Image> coalesced; list<Image> coalesced;
list<Image> mid; list<Image> mid;
readImages(&frames, in_path); readImages(&frames, path);
coalesceImages(&coalesced, frames.begin(), frames.end()); coalesceImages(&coalesced, frames.begin(), frames.end());
for (Image &image : coalesced) { for (Image &image : coalesced) {
@ -49,29 +54,10 @@ class TileWorker : public Napi::AsyncWorker {
} }
writeImages(mid.begin(), mid.end(), &blob); writeImages(mid.begin(), mid.end(), &blob);
}
Napi::Object result = Napi::Object::New(env);
void OnOK() { result.Set("data",
Callback().Call({Env().Undefined(), Napi::Buffer<char>::Copy(Env(), (char *)blob.data(), blob.length()), Napi::String::From(Env(), type)}); Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
} result.Set("type", type);
return result;
private:
string in_path, type;
int delay;
Blob blob;
};
Napi::Value Tile(const Napi::CallbackInfo &info)
{
Napi::Env env = info.Env();
Napi::Object obj = info[0].As<Napi::Object>();
Napi::Function cb = info[1].As<Napi::Function>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
string type = obj.Get("type").As<Napi::String>().Utf8Value();
int delay = obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
TileWorker* flopWorker = new TileWorker(cb, path, type, delay);
flopWorker->Queue();
return env.Undefined();
} }

View file

@ -1,22 +1,27 @@
#include <napi.h>
#include <list>
#include <Magick++.h> #include <Magick++.h>
#include <napi.h>
#include <list>
using namespace std; using namespace std;
using namespace Magick; using namespace Magick;
class TrumpWorker : public Napi::AsyncWorker { Napi::Value Trump(const Napi::CallbackInfo &info) {
public: Napi::Env env = info.Env();
TrumpWorker(Napi::Function& callback, string in_path, string type, int delay)
: Napi::AsyncWorker(callback), in_path(in_path), type(type), delay(delay) {} Napi::Object obj = info[0].As<Napi::Object>();
~TrumpWorker() {} string path = obj.Get("path").As<Napi::String>().Utf8Value();
string type = obj.Get("type").As<Napi::String>().Utf8Value();
int delay =
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
Blob blob;
void Execute() {
list<Image> frames; list<Image> frames;
list<Image> coalesced; list<Image> coalesced;
list<Image> mid; list<Image> mid;
Image watermark; Image watermark;
readImages(&frames, in_path); readImages(&frames, path);
watermark.read("./assets/images/trump.png"); watermark.read("./assets/images/trump.png");
coalesceImages(&coalesced, frames.begin(), frames.end()); coalesceImages(&coalesced, frames.begin(), frames.end());
@ -25,10 +30,12 @@ class TrumpWorker : public Napi::AsyncWorker {
image.virtualPixelMethod(Magick::TransparentVirtualPixelMethod); image.virtualPixelMethod(Magick::TransparentVirtualPixelMethod);
image.backgroundColor("none"); image.backgroundColor("none");
image.scale(Geometry("365x179!")); image.scale(Geometry("365x179!"));
double arguments[16] = {0, 0, 207, 268, 365, 0, 548, 271, 365, 179, 558, 450, 0, 179, 193, 450}; double arguments[16] = {0, 0, 207, 268, 365, 0, 548, 271,
365, 179, 558, 450, 0, 179, 193, 450};
image.distort(Magick::PerspectiveDistortion, 16, arguments, true); image.distort(Magick::PerspectiveDistortion, 16, arguments, true);
image.extent(Geometry("800x450"), Magick::CenterGravity); image.extent(Geometry("800x450"), Magick::CenterGravity);
watermark_new.composite(image, Geometry("-25+134"), Magick::DstOverCompositeOp); watermark_new.composite(image, Geometry("-25+134"),
Magick::DstOverCompositeOp);
watermark_new.magick(type); watermark_new.magick(type);
watermark_new.animationDelay(delay == 0 ? image.animationDelay() : delay); watermark_new.animationDelay(delay == 0 ? image.animationDelay() : delay);
mid.push_back(watermark_new); mid.push_back(watermark_new);
@ -44,29 +51,10 @@ class TrumpWorker : public Napi::AsyncWorker {
} }
writeImages(mid.begin(), mid.end(), &blob); writeImages(mid.begin(), mid.end(), &blob);
}
Napi::Object result = Napi::Object::New(env);
void OnOK() { result.Set("data",
Callback().Call({Env().Undefined(), Napi::Buffer<char>::Copy(Env(), (char *)blob.data(), blob.length()), Napi::String::From(Env(), type)}); Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
} result.Set("type", type);
return result;
private:
string in_path, type;
int delay;
Blob blob;
};
Napi::Value Trump(const Napi::CallbackInfo &info)
{
Napi::Env env = info.Env();
Napi::Object obj = info[0].As<Napi::Object>();
Napi::Function cb = info[1].As<Napi::Function>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
string type = obj.Get("type").As<Napi::String>().Utf8Value();
int delay = obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
TrumpWorker* blurWorker = new TrumpWorker(cb, path, type, delay);
blurWorker->Queue();
return env.Undefined();
} }

View file

@ -1,21 +1,26 @@
#include <napi.h>
#include <list>
#include <Magick++.h> #include <Magick++.h>
#include <napi.h>
#include <list>
using namespace std; using namespace std;
using namespace Magick; using namespace Magick;
class WallWorker : public Napi::AsyncWorker { Napi::Value Wall(const Napi::CallbackInfo &info) {
public: Napi::Env env = info.Env();
WallWorker(Napi::Function& callback, string in_path, string type, int delay)
: Napi::AsyncWorker(callback), in_path(in_path), type(type), delay(delay) {} Napi::Object obj = info[0].As<Napi::Object>();
~WallWorker() {} string path = obj.Get("path").As<Napi::String>().Utf8Value();
string type = obj.Get("type").As<Napi::String>().Utf8Value();
int delay =
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
Blob blob;
void Execute() {
list<Image> frames; list<Image> frames;
list<Image> coalesced; list<Image> coalesced;
list<Image> mid; list<Image> mid;
readImages(&frames, in_path); readImages(&frames, path);
coalesceImages(&coalesced, frames.begin(), frames.end()); coalesceImages(&coalesced, frames.begin(), frames.end());
for (Image &image : coalesced) { for (Image &image : coalesced) {
@ -24,7 +29,8 @@ class WallWorker : public Napi::AsyncWorker {
image.matteColor("none"); image.matteColor("none");
image.backgroundColor("none"); image.backgroundColor("none");
image.scale(Geometry("512x512")); image.scale(Geometry("512x512"));
double arguments[16] = {0, 0, 57, 42, 0, 128, 63, 130, 128, 0, 140, 60, 128, 128, 140, 140}; double arguments[16] = {0, 0, 57, 42, 0, 128, 63, 130,
128, 0, 140, 60, 128, 128, 140, 140};
image.distort(Magick::PerspectiveDistortion, 16, arguments); image.distort(Magick::PerspectiveDistortion, 16, arguments);
image.scale(Geometry("800x800>")); image.scale(Geometry("800x800>"));
image.magick(type); image.magick(type);
@ -42,29 +48,10 @@ class WallWorker : public Napi::AsyncWorker {
} }
writeImages(mid.begin(), mid.end(), &blob); writeImages(mid.begin(), mid.end(), &blob);
}
Napi::Object result = Napi::Object::New(env);
void OnOK() { result.Set("data",
Callback().Call({Env().Undefined(), Napi::Buffer<char>::Copy(Env(), (char *)blob.data(), blob.length()), Napi::String::From(Env(), type)}); Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
} result.Set("type", type);
return result;
private:
string in_path, type;
int delay;
Blob blob;
};
Napi::Value Wall(const Napi::CallbackInfo &info)
{
Napi::Env env = info.Env();
Napi::Object obj = info[0].As<Napi::Object>();
Napi::Function cb = info[1].As<Napi::Function>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
string type = obj.Get("type").As<Napi::String>().Utf8Value();
int delay = obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
WallWorker* flopWorker = new WallWorker(cb, path, type, delay);
flopWorker->Queue();
return env.Undefined();
} }

View file

@ -1,24 +1,36 @@
#include <napi.h>
#include <list>
#include <iostream>
#include <Magick++.h> #include <Magick++.h>
#include <napi.h>
#include <iostream>
#include <list>
using namespace std; using namespace std;
using namespace Magick; using namespace Magick;
class WatermarkWorker : public Napi::AsyncWorker { Napi::Value Watermark(const Napi::CallbackInfo &info) {
public: Napi::Env env = info.Env();
WatermarkWorker(Napi::Function& callback, string in_path, string water_path, int gravity, string type, int delay, bool resize, bool append, bool mc)
: Napi::AsyncWorker(callback), in_path(in_path), water_path(water_path), gravity(gravity), type(type), delay(delay), resize(resize), append(append), mc(mc) {} Napi::Object obj = info[0].As<Napi::Object>();
~WatermarkWorker() {} string path = obj.Get("path").As<Napi::String>().Utf8Value();
string water = obj.Get("water").As<Napi::String>().Utf8Value();
int gravity = obj.Get("gravity").As<Napi::Number>().Int32Value();
bool resize =
obj.Has("resize") ? obj.Get("resize").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;
string type = obj.Get("type").As<Napi::String>().Utf8Value();
int delay =
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
Blob blob;
void Execute() {
list<Image> frames; list<Image> frames;
list<Image> coalesced; list<Image> coalesced;
list<Image> mid; list<Image> mid;
Image watermark; Image watermark;
readImages(&frames, in_path); readImages(&frames, path);
watermark.read(water_path); watermark.read(water);
if (resize && append) { if (resize && append) {
string query(to_string(frames.front().baseColumns()) + "x"); string query(to_string(frames.front().baseColumns()) + "x");
watermark.scale(Geometry(query)); watermark.scale(Geometry(query));
@ -39,10 +51,12 @@ class WatermarkWorker : public Napi::AsyncWorker {
} else if (mc) { } else if (mc) {
image.backgroundColor("white"); image.backgroundColor("white");
image.extent(Geometry(image.columns(), image.rows() + 15)); image.extent(Geometry(image.columns(), image.rows() + 15));
image.composite(watermark, Magick::GravityType(gravity), Magick::OverCompositeOp); image.composite(watermark, Magick::GravityType(gravity),
Magick::OverCompositeOp);
final = image; final = image;
} else { } else {
image.composite(watermark, Magick::GravityType(gravity), Magick::OverCompositeOp); image.composite(watermark, Magick::GravityType(gravity),
Magick::OverCompositeOp);
final = image; final = image;
} }
image.magick(type); image.magick(type);
@ -60,35 +74,10 @@ class WatermarkWorker : public Napi::AsyncWorker {
} }
writeImages(mid.begin(), mid.end(), &blob); writeImages(mid.begin(), mid.end(), &blob);
}
Napi::Object result = Napi::Object::New(env);
void OnOK() { result.Set("data",
Callback().Call({Env().Undefined(), Napi::Buffer<char>::Copy(Env(), (char *)blob.data(), blob.length()), Napi::String::From(Env(), type)}); Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
} result.Set("type", type);
return result;
private:
string in_path, water_path, type;
int delay, gravity;
Blob blob;
bool resize, append, mc;
};
Napi::Value Watermark(const Napi::CallbackInfo &info)
{
Napi::Env env = info.Env();
Napi::Object obj = info[0].As<Napi::Object>();
Napi::Function cb = info[1].As<Napi::Function>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
string water = obj.Get("water").As<Napi::String>().Utf8Value();
int gravity = obj.Get("gravity").As<Napi::Number>().Int32Value();
bool resize = obj.Has("resize") ? obj.Get("resize").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;
string type = obj.Get("type").As<Napi::String>().Utf8Value();
int delay = obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
WatermarkWorker* watermarkWorker = new WatermarkWorker(cb, path, water, gravity, type, delay, resize, append, mc);
watermarkWorker->Queue();
return env.Undefined();
} }

View file

@ -1,29 +1,35 @@
#include <napi.h>
#include <list>
#include <Magick++.h> #include <Magick++.h>
#include <napi.h>
#include <list>
using namespace std; using namespace std;
using namespace Magick; using namespace Magick;
class WdtWorker : public Napi::AsyncWorker { Napi::Value Wdt(const Napi::CallbackInfo &info) {
public: Napi::Env env = info.Env();
WdtWorker(Napi::Function& callback, string in_path, string type, int delay)
: Napi::AsyncWorker(callback), in_path(in_path), type(type), delay(delay) {} Napi::Object obj = info[0].As<Napi::Object>();
~WdtWorker() {} string path = obj.Get("path").As<Napi::String>().Utf8Value();
string type = obj.Get("type").As<Napi::String>().Utf8Value();
int delay =
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
Blob blob;
void Execute() {
list<Image> frames; list<Image> frames;
list<Image> coalesced; list<Image> coalesced;
list<Image> mid; list<Image> mid;
Image watermark; Image watermark;
readImages(&frames, in_path); readImages(&frames, path);
watermark.read("./assets/images/whodidthis.png"); watermark.read("./assets/images/whodidthis.png");
coalesceImages(&coalesced, frames.begin(), frames.end()); coalesceImages(&coalesced, frames.begin(), frames.end());
for (Image &image : coalesced) { for (Image &image : coalesced) {
Image watermark_new = watermark; Image watermark_new = watermark;
image.scale(Geometry("374x374>")); image.scale(Geometry("374x374>"));
watermark_new.composite(image, Magick::CenterGravity, Magick::OverCompositeOp); watermark_new.composite(image, Magick::CenterGravity,
Magick::OverCompositeOp);
watermark_new.magick(type); watermark_new.magick(type);
watermark_new.animationDelay(delay == 0 ? image.animationDelay() : delay); watermark_new.animationDelay(delay == 0 ? image.animationDelay() : delay);
mid.push_back(watermark_new); mid.push_back(watermark_new);
@ -39,29 +45,10 @@ class WdtWorker : public Napi::AsyncWorker {
} }
writeImages(mid.begin(), mid.end(), &blob); writeImages(mid.begin(), mid.end(), &blob);
}
Napi::Object result = Napi::Object::New(env);
void OnOK() { result.Set("data",
Callback().Call({Env().Undefined(), Napi::Buffer<char>::Copy(Env(), (char *)blob.data(), blob.length()), Napi::String::From(Env(), type)}); Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
} result.Set("type", type);
return result;
private:
string in_path, type;
int delay;
Blob blob;
};
Napi::Value Wdt(const Napi::CallbackInfo &info)
{
Napi::Env env = info.Env();
Napi::Object obj = info[0].As<Napi::Object>();
Napi::Function cb = info[1].As<Napi::Function>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
string type = obj.Get("type").As<Napi::String>().Utf8Value();
int delay = obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
WdtWorker* blurWorker = new WdtWorker(cb, path, type, delay);
blurWorker->Queue();
return env.Undefined();
} }

View file

@ -15,14 +15,16 @@ exports.run = object => {
// If no image type is given (say, the command generates its own image), make it a PNG. // 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 fileExtension = object.type ? object.type.split("/")[1] : "png";
const objectWithFixedType = Object.assign({}, object, {type: fileExtension}); const objectWithFixedType = Object.assign({}, object, {type: fileExtension});
magick[object.cmd](objectWithFixedType, (error, data, type) => { try {
if (error) reject(error); const result = magick[object.cmd](objectWithFixedType);
const returnObject = { const returnObject = {
buffer: data, buffer: result.data,
fileExtension: type fileExtension: result.type
}; };
resolve(returnObject); resolve(returnObject);
}); } catch (e) {
reject(e);
}
}); });
}; };

View file

@ -105,7 +105,7 @@ exports.disconnect = async () => {
connection.destroy(); connection.destroy();
} }
for (const uuid of Object.keys(jobs)) { for (const uuid of Object.keys(jobs)) {
jobs[uuid].emit("error", new Error("Job ended prematurely (not really an error; just run your image job again)")); jobs[uuid].emit("error", "Job ended prematurely (not really an error; just run your image job again)");
} }
this.connections = []; this.connections = [];
return; return;