Make all native image functions synchronous
This commit is contained in:
parent
f44abc5576
commit
6cecd4b9d6
39 changed files with 1581 additions and 1996 deletions
|
@ -2,7 +2,9 @@
|
|||
"emotes": [
|
||||
"<a:processing:818243325891051581>",
|
||||
"<a:glxgears:802272302082293770>",
|
||||
"<a:spunchbob:834829415661568000>"
|
||||
"<a:spunchbob:834829415661568000>",
|
||||
"<a:processing:834861794794536990>",
|
||||
"<a:processing:834861794802532432>"
|
||||
],
|
||||
"messages": [
|
||||
"with your sanity",
|
||||
|
|
|
@ -1,20 +1,26 @@
|
|||
#include <napi.h>
|
||||
#include <list>
|
||||
#include <Magick++.h>
|
||||
#include <napi.h>
|
||||
|
||||
#include <list>
|
||||
|
||||
using namespace std;
|
||||
using namespace Magick;
|
||||
|
||||
class BlurWorker : public Napi::AsyncWorker {
|
||||
public:
|
||||
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) {}
|
||||
~BlurWorker() {}
|
||||
Napi::Value Blur(const Napi::CallbackInfo &info) {
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
void Execute() {
|
||||
list <Image> frames;
|
||||
list <Image> coalesced;
|
||||
readImages(&frames, in_path);
|
||||
Napi::Object obj = info[0].As<Napi::Object>();
|
||||
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;
|
||||
|
||||
list<Image> frames;
|
||||
list<Image> coalesced;
|
||||
readImages(&frames, path);
|
||||
coalesceImages(&coalesced, frames.begin(), frames.end());
|
||||
|
||||
if (sharp) {
|
||||
|
@ -36,31 +42,10 @@ class BlurWorker : public Napi::AsyncWorker {
|
|||
}
|
||||
|
||||
writeImages(coalesced.begin(), coalesced.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;
|
||||
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();
|
||||
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;
|
||||
}
|
|
@ -1,21 +1,26 @@
|
|||
#include <napi.h>
|
||||
#include <list>
|
||||
#include <Magick++.h>
|
||||
#include <napi.h>
|
||||
|
||||
#include <list>
|
||||
|
||||
using namespace std;
|
||||
using namespace Magick;
|
||||
|
||||
class BlurpleWorker : public Napi::AsyncWorker {
|
||||
public:
|
||||
BlurpleWorker(Napi::Function& callback, string in_path, string type, int delay)
|
||||
: Napi::AsyncWorker(callback), in_path(in_path), type(type), delay(delay) {}
|
||||
~BlurpleWorker() {}
|
||||
Napi::Value Blurple(const Napi::CallbackInfo &info) {
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
void Execute() {
|
||||
list <Image> frames;
|
||||
list <Image> coalesced;
|
||||
list <Image> blurpled;
|
||||
readImages(&frames, in_path);
|
||||
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> blurpled;
|
||||
readImages(&frames, path);
|
||||
coalesceImages(&coalesced, frames.begin(), frames.end());
|
||||
|
||||
for (Image &image : coalesced) {
|
||||
|
@ -35,31 +40,11 @@ class BlurpleWorker : public Napi::AsyncWorker {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
writeImages(blurpled.begin(), blurpled.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 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();
|
||||
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;
|
||||
}
|
|
@ -1,22 +1,27 @@
|
|||
#include <napi.h>
|
||||
#include <list>
|
||||
#include <Magick++.h>
|
||||
#include <napi.h>
|
||||
|
||||
#include <list>
|
||||
|
||||
using namespace std;
|
||||
using namespace Magick;
|
||||
|
||||
class CaptionWorker : public Napi::AsyncWorker {
|
||||
public:
|
||||
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) {}
|
||||
~CaptionWorker() {}
|
||||
Napi::Value Caption(const Napi::CallbackInfo &info) {
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
void Execute() {
|
||||
list <Image> frames;
|
||||
list <Image> coalesced;
|
||||
list <Image> captioned;
|
||||
list <Image> result;
|
||||
readImages(&frames, in_path);
|
||||
Napi::Object obj = info[0].As<Napi::Object>();
|
||||
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;
|
||||
|
||||
list<Image> frames;
|
||||
list<Image> coalesced;
|
||||
list<Image> captioned;
|
||||
readImages(&frames, path);
|
||||
|
||||
size_t width = frames.front().baseColumns();
|
||||
string query(to_string(width - ((width / 25) * 2)) + "x");
|
||||
|
@ -27,13 +32,14 @@ class CaptionWorker : public Napi::AsyncWorker {
|
|||
caption_image.fontPointsize(width / 13);
|
||||
caption_image.textGravity(Magick::CenterGravity);
|
||||
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());
|
||||
|
||||
for (Image &image : coalesced) {
|
||||
Image appended;
|
||||
list <Image> images;
|
||||
list<Image> images;
|
||||
image.backgroundColor("white");
|
||||
images.push_back(caption_image);
|
||||
images.push_back(image);
|
||||
|
@ -54,32 +60,11 @@ class CaptionWorker : public Napi::AsyncWorker {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
writeImages(captioned.begin(), captioned.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 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();
|
||||
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;
|
||||
}
|
|
@ -1,22 +1,28 @@
|
|||
#include <napi.h>
|
||||
#include <list>
|
||||
#include <Magick++.h>
|
||||
#include <napi.h>
|
||||
|
||||
#include <list>
|
||||
|
||||
using namespace std;
|
||||
using namespace Magick;
|
||||
|
||||
class CaptionTwoWorker : public Napi::AsyncWorker {
|
||||
public:
|
||||
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) {}
|
||||
~CaptionTwoWorker() {}
|
||||
Napi::Value CaptionTwo(const Napi::CallbackInfo &info) {
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
void Execute() {
|
||||
list <Image> frames;
|
||||
list <Image> coalesced;
|
||||
list <Image> captioned;
|
||||
Napi::Object obj = info[0].As<Napi::Object>();
|
||||
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;
|
||||
|
||||
list<Image> frames;
|
||||
list<Image> coalesced;
|
||||
list<Image> captioned;
|
||||
Blob caption_blob;
|
||||
readImages(&frames, in_path);
|
||||
readImages(&frames, path);
|
||||
|
||||
size_t width = frames.front().baseColumns();
|
||||
string query(to_string(width - ((width / 25) * 2)) + "x");
|
||||
|
@ -25,13 +31,14 @@ class CaptionTwoWorker : public Napi::AsyncWorker {
|
|||
caption_image.font("Helvetica Neue");
|
||||
caption_image.fontPointsize(width / 17);
|
||||
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());
|
||||
|
||||
for (Image &image : coalesced) {
|
||||
Image appended;
|
||||
list <Image> images;
|
||||
list<Image> images;
|
||||
image.backgroundColor("white");
|
||||
images.push_back(image);
|
||||
images.push_back(caption_image);
|
||||
|
@ -52,30 +59,10 @@ class CaptionTwoWorker : public Napi::AsyncWorker {
|
|||
}
|
||||
|
||||
writeImages(captioned.begin(), captioned.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 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();
|
||||
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;
|
||||
}
|
|
@ -1,21 +1,26 @@
|
|||
#include <napi.h>
|
||||
#include <list>
|
||||
#include <Magick++.h>
|
||||
#include <napi.h>
|
||||
|
||||
#include <list>
|
||||
|
||||
using namespace std;
|
||||
using namespace Magick;
|
||||
|
||||
class CircleWorker : public Napi::AsyncWorker {
|
||||
public:
|
||||
CircleWorker(Napi::Function& callback, string in_path, string type, int delay)
|
||||
: Napi::AsyncWorker(callback), in_path(in_path), type(type), delay(delay) {}
|
||||
~CircleWorker() {}
|
||||
Napi::Value Circle(const Napi::CallbackInfo &info) {
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
void Execute() {
|
||||
list <Image> frames;
|
||||
list <Image> coalesced;
|
||||
list <Image> blurred;
|
||||
readImages(&frames, in_path);
|
||||
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> blurred;
|
||||
readImages(&frames, path);
|
||||
coalesceImages(&coalesced, frames.begin(), frames.end());
|
||||
|
||||
for (Image &image : coalesced) {
|
||||
|
@ -35,29 +40,10 @@ class CircleWorker : public Napi::AsyncWorker {
|
|||
}
|
||||
|
||||
writeImages(blurred.begin(), blurred.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 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();
|
||||
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;
|
||||
}
|
|
@ -1,26 +1,38 @@
|
|||
#include <napi.h>
|
||||
#include <list>
|
||||
#include <Magick++.h>
|
||||
#include <napi.h>
|
||||
|
||||
#include <list>
|
||||
|
||||
using namespace std;
|
||||
using namespace Magick;
|
||||
|
||||
class CropWorker : public Napi::AsyncWorker {
|
||||
public:
|
||||
CropWorker(Napi::Function& callback, string in_path, string type, int delay)
|
||||
: Napi::AsyncWorker(callback), in_path(in_path), type(type), delay(delay) {}
|
||||
~CropWorker() {}
|
||||
Napi::Value Crop(const Napi::CallbackInfo &info) {
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
void Execute() {
|
||||
list <Image> frames;
|
||||
list <Image> coalesced;
|
||||
list <Image> mid;
|
||||
readImages(&frames, in_path);
|
||||
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.extent(Geometry(to_string(image.columns() / image.rows() >= 1 ? 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.extent(Geometry(to_string(image.columns() / image.rows() >= 1
|
||||
? 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);
|
||||
mid.push_back(image);
|
||||
}
|
||||
|
@ -36,29 +48,10 @@ class CropWorker : public Napi::AsyncWorker {
|
|||
}
|
||||
|
||||
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 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();
|
||||
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;
|
||||
}
|
|
@ -1,21 +1,27 @@
|
|||
#include <napi.h>
|
||||
#include <list>
|
||||
#include <Magick++.h>
|
||||
#include <napi.h>
|
||||
|
||||
#include <list>
|
||||
|
||||
using namespace std;
|
||||
using namespace Magick;
|
||||
|
||||
class ExplodeWorker : public Napi::AsyncWorker {
|
||||
public:
|
||||
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) {}
|
||||
~ExplodeWorker() {}
|
||||
Napi::Value Explode(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();
|
||||
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> coalesced;
|
||||
list<Image> blurred;
|
||||
readImages(&frames, in_path);
|
||||
readImages(&frames, path);
|
||||
coalesceImages(&coalesced, frames.begin(), frames.end());
|
||||
|
||||
for (Image &image : coalesced) {
|
||||
|
@ -35,30 +41,10 @@ class ExplodeWorker : public Napi::AsyncWorker {
|
|||
}
|
||||
|
||||
writeImages(blurred.begin(), blurred.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, 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();
|
||||
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;
|
||||
}
|
|
@ -1,26 +1,34 @@
|
|||
#include <napi.h>
|
||||
#include <list>
|
||||
#include <Magick++.h>
|
||||
#include <napi.h>
|
||||
|
||||
#include <list>
|
||||
|
||||
using namespace std;
|
||||
using namespace Magick;
|
||||
|
||||
class FlagWorker : public Napi::AsyncWorker {
|
||||
public:
|
||||
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) {}
|
||||
~FlagWorker() {}
|
||||
Napi::Value Flag(const Napi::CallbackInfo &info) {
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
void Execute() {
|
||||
list <Image> frames;
|
||||
list <Image> coalesced;
|
||||
list <Image> mid;
|
||||
Napi::Object obj = info[0].As<Napi::Object>();
|
||||
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;
|
||||
|
||||
list<Image> frames;
|
||||
list<Image> coalesced;
|
||||
list<Image> mid;
|
||||
Image watermark;
|
||||
readImages(&frames, in_path);
|
||||
watermark.read(overlay_path);
|
||||
readImages(&frames, path);
|
||||
watermark.read(overlay);
|
||||
watermark.alphaChannel(Magick::SetAlphaChannel);
|
||||
watermark.evaluate(Magick::AlphaChannel, Magick::MultiplyEvaluateOperator, 0.5);
|
||||
string query(to_string(frames.front().baseColumns()) + "x" + to_string(frames.front().baseRows()) + "!");
|
||||
watermark.evaluate(Magick::AlphaChannel, Magick::MultiplyEvaluateOperator,
|
||||
0.5);
|
||||
string query(to_string(frames.front().baseColumns()) + "x" +
|
||||
to_string(frames.front().baseRows()) + "!");
|
||||
watermark.scale(Geometry(query));
|
||||
coalesceImages(&coalesced, frames.begin(), frames.end());
|
||||
|
||||
|
@ -41,30 +49,10 @@ class FlagWorker : public Napi::AsyncWorker {
|
|||
}
|
||||
|
||||
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, 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();
|
||||
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;
|
||||
}
|
|
@ -1,21 +1,28 @@
|
|||
#include <napi.h>
|
||||
#include <list>
|
||||
#include <Magick++.h>
|
||||
#include <napi.h>
|
||||
|
||||
#include <list>
|
||||
|
||||
using namespace std;
|
||||
using namespace Magick;
|
||||
|
||||
class FlipWorker : public Napi::AsyncWorker {
|
||||
public:
|
||||
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) {}
|
||||
~FlipWorker() {}
|
||||
Napi::Value Flip(const Napi::CallbackInfo &info) {
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
void Execute() {
|
||||
list <Image> frames;
|
||||
list <Image> coalesced;
|
||||
list <Image> mid;
|
||||
readImages(&frames, in_path);
|
||||
Napi::Object obj = info[0].As<Napi::Object>();
|
||||
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;
|
||||
|
||||
list<Image> frames;
|
||||
list<Image> coalesced;
|
||||
list<Image> mid;
|
||||
readImages(&frames, path);
|
||||
coalesceImages(&coalesced, frames.begin(), frames.end());
|
||||
|
||||
for (Image &image : coalesced) {
|
||||
|
@ -35,31 +42,10 @@ class FlipWorker : public Napi::AsyncWorker {
|
|||
}
|
||||
|
||||
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;
|
||||
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();
|
||||
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;
|
||||
}
|
|
@ -1,56 +1,45 @@
|
|||
#include <napi.h>
|
||||
#include <list>
|
||||
#include <Magick++.h>
|
||||
#include <napi.h>
|
||||
|
||||
#include <list>
|
||||
|
||||
using namespace std;
|
||||
using namespace Magick;
|
||||
|
||||
class FreezeWorker : public Napi::AsyncWorker {
|
||||
public:
|
||||
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) {}
|
||||
~FreezeWorker() {}
|
||||
Napi::Value Freeze(const Napi::CallbackInfo &info) {
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
void Execute() {
|
||||
list <Image> frames;
|
||||
readImages(&frames, in_path);
|
||||
Napi::Object obj = info[0].As<Napi::Object>();
|
||||
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;
|
||||
|
||||
list<Image> frames;
|
||||
readImages(&frames, path);
|
||||
|
||||
if (frame >= 0 && !loop) {
|
||||
size_t frameSize = frames.size();
|
||||
int framePos = clamp(frame, 0, (int)frameSize);
|
||||
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));
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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 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();
|
||||
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;
|
||||
}
|
|
@ -1,22 +1,27 @@
|
|||
#include <napi.h>
|
||||
#include <list>
|
||||
#include <Magick++.h>
|
||||
#include <napi.h>
|
||||
|
||||
#include <list>
|
||||
|
||||
using namespace std;
|
||||
using namespace Magick;
|
||||
|
||||
class GamexplainWorker : public Napi::AsyncWorker {
|
||||
public:
|
||||
GamexplainWorker(Napi::Function& callback, string in_path, string type, int delay)
|
||||
: Napi::AsyncWorker(callback), in_path(in_path), type(type), delay(delay) {}
|
||||
~GamexplainWorker() {}
|
||||
Napi::Value Gamexplain(const Napi::CallbackInfo &info) {
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
void Execute() {
|
||||
list <Image> frames;
|
||||
list <Image> coalesced;
|
||||
list <Image> mid;
|
||||
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;
|
||||
Image watermark;
|
||||
readImages(&frames, in_path);
|
||||
readImages(&frames, path);
|
||||
watermark.read("./assets/images/gamexplain.png");
|
||||
coalesceImages(&coalesced, frames.begin(), frames.end());
|
||||
|
||||
|
@ -40,29 +45,10 @@ class GamexplainWorker : public Napi::AsyncWorker {
|
|||
}
|
||||
|
||||
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 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();
|
||||
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;
|
||||
}
|
|
@ -1,29 +1,34 @@
|
|||
#include <napi.h>
|
||||
#include <list>
|
||||
#include <Magick++.h>
|
||||
#include <napi.h>
|
||||
|
||||
#include <list>
|
||||
|
||||
using namespace std;
|
||||
using namespace Magick;
|
||||
|
||||
class GlobeWorker : public Napi::AsyncWorker {
|
||||
public:
|
||||
GlobeWorker(Napi::Function& callback, string in_path, string type, int delay)
|
||||
: Napi::AsyncWorker(callback), in_path(in_path), type(type), delay(delay) {}
|
||||
~GlobeWorker() {}
|
||||
Napi::Value Globe(const Napi::CallbackInfo &info) {
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
void Execute() {
|
||||
list <Image> frames;
|
||||
list <Image> coalesced;
|
||||
list <Image> mid;
|
||||
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;
|
||||
Image distort;
|
||||
Image overlay;
|
||||
readImages(&frames, in_path);
|
||||
readImages(&frames, path);
|
||||
distort.read("./assets/images/spheremap.png");
|
||||
overlay.read("./assets/images/sphere_overlay.png");
|
||||
coalesceImages(&coalesced, frames.begin(), frames.end());
|
||||
|
||||
if (type != "gif") {
|
||||
list <Image>::iterator it = coalesced.begin();
|
||||
list<Image>::iterator it = coalesced.begin();
|
||||
for (int i = 0; i < 29; ++i) {
|
||||
coalesced.push_back(*it);
|
||||
}
|
||||
|
@ -35,7 +40,8 @@ class GlobeWorker : public Napi::AsyncWorker {
|
|||
image.alphaChannel(Magick::SetAlphaChannel);
|
||||
size_t width = image.columns();
|
||||
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.magick("GIF");
|
||||
mid.push_back(image);
|
||||
|
@ -55,29 +61,10 @@ class GlobeWorker : public Napi::AsyncWorker {
|
|||
}
|
||||
|
||||
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(), "gif")});
|
||||
}
|
||||
|
||||
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();
|
||||
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;
|
||||
}
|
|
@ -1,17 +1,19 @@
|
|||
#include <napi.h>
|
||||
#include <list>
|
||||
#include <Magick++.h>
|
||||
#include <napi.h>
|
||||
|
||||
#include <list>
|
||||
|
||||
using namespace std;
|
||||
using namespace Magick;
|
||||
|
||||
class HomebrewWorker : public Napi::AsyncWorker {
|
||||
public:
|
||||
HomebrewWorker(Napi::Function& callback, string text)
|
||||
: Napi::AsyncWorker(callback), text(text) {}
|
||||
~HomebrewWorker() {}
|
||||
Napi::Value Homebrew(const Napi::CallbackInfo &info) {
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
Napi::Object obj = info[0].As<Napi::Object>();
|
||||
string caption = obj.Get("caption").As<Napi::String>().Utf8Value();
|
||||
|
||||
Blob blob;
|
||||
|
||||
void Execute() {
|
||||
Image image;
|
||||
image.read("./assets/images/hbc.png");
|
||||
image.textGravity(Magick::CenterGravity);
|
||||
|
@ -19,29 +21,13 @@ class HomebrewWorker : public Napi::AsyncWorker {
|
|||
image.textKerning(-5);
|
||||
image.fillColor("white");
|
||||
image.fontPointsize(96);
|
||||
image.draw(DrawableText(0, 0, text));
|
||||
image.draw(DrawableText(0, 0, caption));
|
||||
image.magick("PNG");
|
||||
image.write(&blob);
|
||||
}
|
||||
|
||||
void OnOK() {
|
||||
Callback().Call({Env().Undefined(), Napi::Buffer<char>::Copy(Env(), (char *)blob.data(), blob.length()), Napi::String::From(Env(), "png")});
|
||||
}
|
||||
|
||||
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();
|
||||
Napi::Object result = Napi::Object::New(env);
|
||||
result.Set("data",
|
||||
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
|
||||
result.Set("type", "png");
|
||||
return result;
|
||||
}
|
|
@ -19,7 +19,7 @@
|
|||
#include "magik.h"
|
||||
#include "meme.h"
|
||||
#include "mirror.h"
|
||||
#include "misc.h"
|
||||
#include "swirl.h"
|
||||
#include "motivate.h"
|
||||
#include "resize.h"
|
||||
#include "retro.h"
|
||||
|
|
|
@ -1,21 +1,26 @@
|
|||
#include <napi.h>
|
||||
#include <list>
|
||||
#include <Magick++.h>
|
||||
#include <napi.h>
|
||||
|
||||
#include <list>
|
||||
|
||||
using namespace std;
|
||||
using namespace Magick;
|
||||
|
||||
class InvertWorker : public Napi::AsyncWorker {
|
||||
public:
|
||||
InvertWorker(Napi::Function& callback, string in_path, string type, int delay)
|
||||
: Napi::AsyncWorker(callback), in_path(in_path), type(type), delay(delay) {}
|
||||
~InvertWorker() {}
|
||||
Napi::Value Invert(const Napi::CallbackInfo &info) {
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
void Execute() {
|
||||
list <Image> frames;
|
||||
list <Image> coalesced;
|
||||
list <Image> mid;
|
||||
readImages(&frames, in_path);
|
||||
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_each(coalesced.begin(), coalesced.end(), negateImage());
|
||||
|
@ -37,29 +42,10 @@ class InvertWorker : public Napi::AsyncWorker {
|
|||
}
|
||||
|
||||
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 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();
|
||||
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;
|
||||
}
|
|
@ -1,42 +1,28 @@
|
|||
#include <napi.h>
|
||||
#include <list>
|
||||
#include <Magick++.h>
|
||||
#include <napi.h>
|
||||
|
||||
#include <list>
|
||||
|
||||
using namespace std;
|
||||
using namespace Magick;
|
||||
|
||||
class JpegWorker : public Napi::AsyncWorker {
|
||||
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::Value Jpeg(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();
|
||||
|
||||
JpegWorker* explodeWorker = new JpegWorker(cb, path);
|
||||
explodeWorker->Queue();
|
||||
return env.Undefined();
|
||||
Blob blob;
|
||||
|
||||
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;
|
||||
}
|
|
@ -1,22 +1,27 @@
|
|||
#include <napi.h>
|
||||
#include <list>
|
||||
#include <Magick++.h>
|
||||
#include <napi.h>
|
||||
|
||||
#include <list>
|
||||
|
||||
using namespace std;
|
||||
using namespace Magick;
|
||||
|
||||
class LeakWorker : public Napi::AsyncWorker {
|
||||
public:
|
||||
LeakWorker(Napi::Function& callback, string in_path, string type, int delay)
|
||||
: Napi::AsyncWorker(callback), in_path(in_path), type(type), delay(delay) {}
|
||||
~LeakWorker() {}
|
||||
Napi::Value Leak(const Napi::CallbackInfo &info) {
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
void Execute() {
|
||||
list <Image> frames;
|
||||
list <Image> coalesced;
|
||||
list <Image> mid;
|
||||
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;
|
||||
Image watermark;
|
||||
readImages(&frames, in_path);
|
||||
readImages(&frames, path);
|
||||
watermark.read("./assets/images/leak.png");
|
||||
coalesceImages(&coalesced, frames.begin(), frames.end());
|
||||
|
||||
|
@ -41,29 +46,10 @@ class LeakWorker : public Napi::AsyncWorker {
|
|||
}
|
||||
|
||||
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 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();
|
||||
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;
|
||||
}
|
|
@ -1,21 +1,26 @@
|
|||
#include <napi.h>
|
||||
#include <list>
|
||||
#include <Magick++.h>
|
||||
#include <napi.h>
|
||||
|
||||
#include <list>
|
||||
|
||||
using namespace std;
|
||||
using namespace Magick;
|
||||
|
||||
class MagikWorker : public Napi::AsyncWorker {
|
||||
public:
|
||||
MagikWorker(Napi::Function& callback, string in_path, string type, int delay)
|
||||
: Napi::AsyncWorker(callback), in_path(in_path), type(type), delay(delay) {}
|
||||
~MagikWorker() {}
|
||||
Napi::Value Magik(const Napi::CallbackInfo &info) {
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
void Execute() {
|
||||
list <Image> frames;
|
||||
list <Image> coalesced;
|
||||
list <Image> blurred;
|
||||
readImages(&frames, in_path);
|
||||
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> blurred;
|
||||
readImages(&frames, path);
|
||||
coalesceImages(&coalesced, frames.begin(), frames.end());
|
||||
|
||||
for (Image &image : coalesced) {
|
||||
|
@ -37,30 +42,10 @@ class MagikWorker : public Napi::AsyncWorker {
|
|||
}
|
||||
|
||||
writeImages(blurred.begin(), blurred.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 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();
|
||||
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;
|
||||
}
|
|
@ -1,23 +1,30 @@
|
|||
#include <napi.h>
|
||||
#include <list>
|
||||
#include <Magick++.h>
|
||||
#include <napi.h>
|
||||
|
||||
#include <list>
|
||||
|
||||
using namespace std;
|
||||
using namespace Magick;
|
||||
|
||||
class MemeWorker : public Napi::AsyncWorker {
|
||||
public:
|
||||
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) {}
|
||||
~MemeWorker() {}
|
||||
Napi::Value Meme(const Napi::CallbackInfo &info) {
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
void Execute() {
|
||||
list <Image> frames;
|
||||
list <Image> coalesced;
|
||||
list <Image> mid;
|
||||
Napi::Object obj = info[0].As<Napi::Object>();
|
||||
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;
|
||||
|
||||
list<Image> frames;
|
||||
list<Image> coalesced;
|
||||
list<Image> mid;
|
||||
Image top_text;
|
||||
Image bottom_text;
|
||||
readImages(&frames, in_path);
|
||||
readImages(&frames, path);
|
||||
coalesceImages(&coalesced, frames.begin(), frames.end());
|
||||
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.fontPointsize(40);
|
||||
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;
|
||||
top_text_fill.channel(Magick::AlphaChannel);
|
||||
top_text_fill.morphology(Magick::EdgeOutMorphology, "Octagon");
|
||||
top_text_fill.backgroundColor("black");
|
||||
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.backgroundColor("none");
|
||||
bottom_text.font("Impact");
|
||||
bottom_text.fontPointsize(40);
|
||||
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;
|
||||
bottom_text_fill.channel(Magick::AlphaChannel);
|
||||
bottom_text_fill.morphology(Magick::EdgeOutMorphology, "Octagon");
|
||||
bottom_text_fill.backgroundColor("black");
|
||||
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) {
|
||||
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);
|
||||
mid.push_back(image);
|
||||
}
|
||||
|
@ -67,31 +78,10 @@ class MemeWorker : public Napi::AsyncWorker {
|
|||
}
|
||||
|
||||
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, 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();
|
||||
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;
|
||||
}
|
|
@ -1,22 +1,32 @@
|
|||
#include <napi.h>
|
||||
#include <list>
|
||||
#include <Magick++.h>
|
||||
#include <napi.h>
|
||||
|
||||
#include <list>
|
||||
|
||||
using namespace std;
|
||||
using namespace Magick;
|
||||
|
||||
class MirrorWorker : public Napi::AsyncWorker {
|
||||
public:
|
||||
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) {}
|
||||
~MirrorWorker() {}
|
||||
Napi::Value Mirror(const Napi::CallbackInfo &info) {
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
void Execute() {
|
||||
list <Image> frames;
|
||||
list <Image> coalesced;
|
||||
list <Image> mid;
|
||||
Napi::Object obj = info[0].As<Napi::Object>();
|
||||
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;
|
||||
|
||||
list<Image> frames;
|
||||
list<Image> coalesced;
|
||||
list<Image> mid;
|
||||
MagickCore::GravityType gravity;
|
||||
readImages(&frames, in_path);
|
||||
readImages(&frames, path);
|
||||
coalesceImages(&coalesced, frames.begin(), frames.end());
|
||||
|
||||
if (vertical && first) {
|
||||
|
@ -30,9 +40,14 @@ class MirrorWorker : public Napi::AsyncWorker {
|
|||
}
|
||||
|
||||
for (Image &image : coalesced) {
|
||||
list <Image> mirrored;
|
||||
list<Image> mirrored;
|
||||
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);
|
||||
Image mirror = image;
|
||||
if (vertical) {
|
||||
|
@ -62,32 +77,10 @@ class MirrorWorker : public Napi::AsyncWorker {
|
|||
}
|
||||
|
||||
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;
|
||||
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();
|
||||
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;
|
||||
}
|
|
@ -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();
|
||||
}
|
|
@ -1,23 +1,30 @@
|
|||
#include <napi.h>
|
||||
#include <list>
|
||||
#include <Magick++.h>
|
||||
#include <napi.h>
|
||||
|
||||
#include <list>
|
||||
|
||||
using namespace std;
|
||||
using namespace Magick;
|
||||
|
||||
class MotivateWorker : public Napi::AsyncWorker {
|
||||
public:
|
||||
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) {}
|
||||
~MotivateWorker() {}
|
||||
Napi::Value Motivate(const Napi::CallbackInfo &info) {
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
void Execute() {
|
||||
list <Image> frames;
|
||||
list <Image> coalesced;
|
||||
list <Image> mid;
|
||||
Napi::Object obj = info[0].As<Napi::Object>();
|
||||
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;
|
||||
|
||||
list<Image> frames;
|
||||
list<Image> coalesced;
|
||||
list<Image> mid;
|
||||
Image top;
|
||||
Image bottom;
|
||||
readImages(&frames, in_path);
|
||||
readImages(&frames, path);
|
||||
coalesceImages(&coalesced, frames.begin(), frames.end());
|
||||
|
||||
top.size(Geometry("600"));
|
||||
|
@ -26,7 +33,11 @@ class MotivateWorker : public Napi::AsyncWorker {
|
|||
top.textGravity(Magick::CenterGravity);
|
||||
top.fontPointsize(56);
|
||||
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 != "") {
|
||||
bottom.size(Geometry("600"));
|
||||
|
@ -35,7 +46,9 @@ class MotivateWorker : public Napi::AsyncWorker {
|
|||
bottom.textGravity(Magick::CenterGravity);
|
||||
bottom.fontPointsize(28);
|
||||
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) {
|
||||
|
@ -48,7 +61,7 @@ class MotivateWorker : public Napi::AsyncWorker {
|
|||
image.backgroundColor("black");
|
||||
image.extent(Geometry(600, image.rows() + 50), Magick::CenterGravity);
|
||||
|
||||
list <Image> to_append;
|
||||
list<Image> to_append;
|
||||
to_append.push_back(image);
|
||||
to_append.push_back(top);
|
||||
if (bottom_text != "") to_append.push_back(bottom);
|
||||
|
@ -69,31 +82,10 @@ class MotivateWorker : public Napi::AsyncWorker {
|
|||
}
|
||||
|
||||
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, 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();
|
||||
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;
|
||||
}
|
|
@ -1,28 +1,39 @@
|
|||
#include <napi.h>
|
||||
#include <list>
|
||||
#include <Magick++.h>
|
||||
#include <napi.h>
|
||||
|
||||
#include <list>
|
||||
|
||||
using namespace std;
|
||||
using namespace Magick;
|
||||
|
||||
class ResizeWorker : public Napi::AsyncWorker {
|
||||
public:
|
||||
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) {}
|
||||
~ResizeWorker() {}
|
||||
Napi::Value Resize(const Napi::CallbackInfo &info) {
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
void Execute() {
|
||||
list <Image> frames;
|
||||
list <Image> coalesced;
|
||||
list <Image> blurred;
|
||||
readImages(&frames, in_path);
|
||||
Napi::Object obj = info[0].As<Napi::Object>();
|
||||
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;
|
||||
|
||||
list<Image> frames;
|
||||
list<Image> coalesced;
|
||||
list<Image> blurred;
|
||||
readImages(&frames, path);
|
||||
coalesceImages(&coalesced, frames.begin(), frames.end());
|
||||
|
||||
for (Image &image : coalesced) {
|
||||
if (stretch) {
|
||||
image.resize(Geometry("512x512!"));
|
||||
} 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 {
|
||||
image.scale(Geometry("10%"));
|
||||
image.scale(Geometry("1000%"));
|
||||
|
@ -42,32 +53,10 @@ class ResizeWorker : public Napi::AsyncWorker {
|
|||
}
|
||||
|
||||
writeImages(blurred.begin(), blurred.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, 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();
|
||||
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;
|
||||
}
|
|
@ -1,17 +1,21 @@
|
|||
#include <napi.h>
|
||||
#include <list>
|
||||
#include <Magick++.h>
|
||||
#include <napi.h>
|
||||
|
||||
#include <list>
|
||||
|
||||
using namespace std;
|
||||
using namespace Magick;
|
||||
|
||||
class RetroWorker : public Napi::AsyncWorker {
|
||||
public:
|
||||
RetroWorker(Napi::Function& callback, string line1, string line2, string line3)
|
||||
: Napi::AsyncWorker(callback), line1(line1), line2(line2), line3(line3) {}
|
||||
~RetroWorker() {}
|
||||
Napi::Value Retro(const Napi::CallbackInfo &info) {
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
Napi::Object obj = info[0].As<Napi::Object>();
|
||||
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 line1_text;
|
||||
Image line2_text;
|
||||
|
@ -23,14 +27,16 @@ class RetroWorker : public Napi::AsyncWorker {
|
|||
line2_text.fontPointsize(128);
|
||||
line2_text.textGravity(Magick::CenterGravity);
|
||||
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);
|
||||
Image line2_text_fill = line2_text;
|
||||
line2_text_fill.channel(Magick::AlphaChannel);
|
||||
line2_text_fill.morphology(Magick::EdgeOutMorphology, "Octagon:10");
|
||||
line2_text_fill.backgroundColor("gray");
|
||||
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);
|
||||
|
||||
if (line2 != "") {
|
||||
|
@ -45,7 +51,8 @@ class RetroWorker : public Napi::AsyncWorker {
|
|||
line1_text_fill.morphology(Magick::EdgeOutMorphology, "Octagon:10");
|
||||
line1_text_fill.backgroundColor("gray");
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -61,34 +68,17 @@ class RetroWorker : public Napi::AsyncWorker {
|
|||
line3_text_fill.morphology(Magick::EdgeOutMorphology, "Octagon:10");
|
||||
line3_text_fill.backgroundColor("gray");
|
||||
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.magick("PNG");
|
||||
image.write(&blob);
|
||||
}
|
||||
|
||||
void OnOK() {
|
||||
Callback().Call({Env().Undefined(), Napi::Buffer<char>::Copy(Env(), (char *)blob.data(), blob.length()), Napi::String::From(Env(), "png")});
|
||||
}
|
||||
|
||||
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();
|
||||
Napi::Object result = Napi::Object::New(env);
|
||||
result.Set("data",
|
||||
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
|
||||
result.Set("type", "png");
|
||||
return result;
|
||||
}
|
|
@ -1,20 +1,26 @@
|
|||
#include <napi.h>
|
||||
#include <list>
|
||||
#include <Magick++.h>
|
||||
#include <napi.h>
|
||||
|
||||
#include <list>
|
||||
|
||||
using namespace std;
|
||||
using namespace Magick;
|
||||
|
||||
class ReverseWorker : public Napi::AsyncWorker {
|
||||
public:
|
||||
ReverseWorker(Napi::Function& callback, string in_path, bool soos, int delay)
|
||||
: Napi::AsyncWorker(callback), in_path(in_path), soos(soos), delay(delay) {}
|
||||
~ReverseWorker() {}
|
||||
Napi::Value Reverse(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();
|
||||
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> coalesced;
|
||||
readImages(&frames, in_path);
|
||||
readImages(&frames, path);
|
||||
coalesceImages(&coalesced, frames.begin(), frames.end());
|
||||
|
||||
if (soos) {
|
||||
|
@ -36,30 +42,10 @@ class ReverseWorker : public Napi::AsyncWorker {
|
|||
}
|
||||
|
||||
writeImages(coalesced.begin(), coalesced.end(), &blob);
|
||||
}
|
||||
|
||||
void OnOK() {
|
||||
Callback().Call({Env().Undefined(), Napi::Buffer<char>::Copy(Env(), (char *)blob.data(), blob.length()), Napi::String::From(Env(), "gif")});
|
||||
}
|
||||
|
||||
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();
|
||||
Napi::Object result = Napi::Object::New(env);
|
||||
result.Set("data",
|
||||
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
|
||||
result.Set("type", "gif");
|
||||
return result;
|
||||
}
|
|
@ -1,22 +1,27 @@
|
|||
#include <napi.h>
|
||||
#include <list>
|
||||
#include <Magick++.h>
|
||||
#include <napi.h>
|
||||
|
||||
#include <list>
|
||||
|
||||
using namespace std;
|
||||
using namespace Magick;
|
||||
|
||||
class ScottWorker : public Napi::AsyncWorker {
|
||||
public:
|
||||
ScottWorker(Napi::Function& callback, string in_path, string type, int delay)
|
||||
: Napi::AsyncWorker(callback), in_path(in_path), type(type), delay(delay) {}
|
||||
~ScottWorker() {}
|
||||
Napi::Value Scott(const Napi::CallbackInfo &info) {
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
void Execute() {
|
||||
list <Image> frames;
|
||||
list <Image> coalesced;
|
||||
list <Image> mid;
|
||||
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;
|
||||
Image watermark;
|
||||
readImages(&frames, in_path);
|
||||
readImages(&frames, path);
|
||||
watermark.read("./assets/images/scott.png");
|
||||
coalesceImages(&coalesced, frames.begin(), frames.end());
|
||||
|
||||
|
@ -25,10 +30,12 @@ class ScottWorker : public Napi::AsyncWorker {
|
|||
image.virtualPixelMethod(Magick::TransparentVirtualPixelMethod);
|
||||
image.backgroundColor("none");
|
||||
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.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.animationDelay(delay == 0 ? image.animationDelay() : delay);
|
||||
mid.push_back(watermark_new);
|
||||
|
@ -44,29 +51,10 @@ class ScottWorker : public Napi::AsyncWorker {
|
|||
}
|
||||
|
||||
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 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();
|
||||
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;
|
||||
}
|
|
@ -1,17 +1,19 @@
|
|||
#include <napi.h>
|
||||
#include <list>
|
||||
#include <Magick++.h>
|
||||
#include <napi.h>
|
||||
|
||||
#include <list>
|
||||
|
||||
using namespace std;
|
||||
using namespace Magick;
|
||||
|
||||
class SonicWorker : public Napi::AsyncWorker {
|
||||
public:
|
||||
SonicWorker(Napi::Function& callback, string text)
|
||||
: Napi::AsyncWorker(callback), text(text) {}
|
||||
~SonicWorker() {}
|
||||
Napi::Value Sonic(const Napi::CallbackInfo &info) {
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
Napi::Object obj = info[0].As<Napi::Object>();
|
||||
string text = obj.Get("text").As<Napi::String>().Utf8Value();
|
||||
|
||||
Blob blob;
|
||||
|
||||
void Execute() {
|
||||
Image image;
|
||||
Image text_image;
|
||||
text_image.backgroundColor("none");
|
||||
|
@ -25,26 +27,10 @@ class SonicWorker : public Napi::AsyncWorker {
|
|||
image.composite(text_image, Geometry("+160+10"), Magick::OverCompositeOp);
|
||||
image.magick("PNG");
|
||||
image.write(&blob);
|
||||
}
|
||||
|
||||
void OnOK() {
|
||||
Callback().Call({Env().Undefined(), Napi::Buffer<char>::Copy(Env(), (char *)blob.data(), blob.length()), Napi::String::From(Env(), "png")});
|
||||
}
|
||||
|
||||
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();
|
||||
Napi::Object result = Napi::Object::New(env);
|
||||
result.Set("data",
|
||||
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
|
||||
result.Set("type", "png");
|
||||
return result;
|
||||
}
|
|
@ -1,19 +1,28 @@
|
|||
#include <napi.h>
|
||||
#include <list>
|
||||
#include <Magick++.h>
|
||||
#include <napi.h>
|
||||
|
||||
#include <list>
|
||||
|
||||
using namespace std;
|
||||
using namespace Magick;
|
||||
|
||||
class SpeedWorker : public Napi::AsyncWorker {
|
||||
public:
|
||||
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) {}
|
||||
~SpeedWorker() {}
|
||||
Napi::Value Speed(const Napi::CallbackInfo &info) {
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
void Execute() {
|
||||
list <Image> frames;
|
||||
readImages(&frames, in_path);
|
||||
Napi::Object obj = info[0].As<Napi::Object>();
|
||||
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;
|
||||
|
||||
list<Image> frames;
|
||||
readImages(&frames, path);
|
||||
|
||||
// if passed a delay, use that. otherwise use the average frame delay.
|
||||
if (delay == 0) {
|
||||
|
@ -35,24 +44,22 @@ class SpeedWorker : public Napi::AsyncWorker {
|
|||
}
|
||||
|
||||
if (removeFrames) {
|
||||
for (list <Image>::iterator i = frames.begin(); i != frames.end(); ++i) {
|
||||
for (list<Image>::iterator i = frames.begin(); i != frames.end(); ++i) {
|
||||
int index = distance(frames.begin(), i);
|
||||
i->animationDelay(old_delays[index]);
|
||||
}
|
||||
|
||||
for (int i = 0; i < speed - 1; ++i) {
|
||||
frames.remove_if([counter = 0](const auto x) mutable {
|
||||
return ++counter % 2 == 0;
|
||||
});
|
||||
frames.remove_if(
|
||||
[counter = 0](const auto x) mutable { return ++counter % 2 == 0; });
|
||||
}
|
||||
}
|
||||
} else {
|
||||
int new_delay = slow ? delay * speed : delay / speed;
|
||||
if (!slow && new_delay <= 1) {
|
||||
for (int i = 0; i < speed - 1; ++i) {
|
||||
frames.remove_if([counter = 0](const auto x) mutable {
|
||||
return ++counter % 2 == 0;
|
||||
});
|
||||
frames.remove_if(
|
||||
[counter = 0](const auto x) mutable { return ++counter % 2 == 0; });
|
||||
}
|
||||
} else {
|
||||
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));
|
||||
|
||||
writeImages(frames.begin(), frames.end(), &blob);
|
||||
}
|
||||
|
||||
void OnOK() {
|
||||
Callback().Call({Env().Undefined(), Napi::Buffer<char>::Copy(Env(), (char *)blob.data(), blob.length()), Napi::String::From(Env(), type)});
|
||||
}
|
||||
|
||||
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();
|
||||
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;
|
||||
}
|
|
@ -1,25 +1,30 @@
|
|||
#include <napi.h>
|
||||
#include <list>
|
||||
#include <Magick++.h>
|
||||
#include <napi.h>
|
||||
|
||||
#include <list>
|
||||
|
||||
using namespace std;
|
||||
using namespace Magick;
|
||||
|
||||
class SpinWorker : public Napi::AsyncWorker {
|
||||
public:
|
||||
SpinWorker(Napi::Function& callback, string in_path, string type, int delay)
|
||||
: Napi::AsyncWorker(callback), in_path(in_path), type(type), delay(delay) {}
|
||||
~SpinWorker() {}
|
||||
Napi::Value Spin(const Napi::CallbackInfo &info) {
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
void Execute() {
|
||||
list <Image> frames;
|
||||
list <Image> coalesced;
|
||||
list <Image> mid;
|
||||
readImages(&frames, in_path);
|
||||
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());
|
||||
|
||||
if (type != "gif") {
|
||||
list <Image>::iterator it = coalesced.begin();
|
||||
list<Image>::iterator it = coalesced.begin();
|
||||
for (int i = 0; i < 29; ++i) {
|
||||
coalesced.push_back(*it);
|
||||
}
|
||||
|
@ -37,7 +42,8 @@ class SpinWorker : public Napi::AsyncWorker {
|
|||
i++;
|
||||
}
|
||||
|
||||
for_each(mid.begin(), mid.end(), gifDisposeMethodImage(Magick::BackgroundDispose));
|
||||
for_each(mid.begin(), mid.end(),
|
||||
gifDisposeMethodImage(Magick::BackgroundDispose));
|
||||
|
||||
optimizeTransparency(mid.begin(), mid.end());
|
||||
if (delay != 0) {
|
||||
|
@ -52,29 +58,10 @@ class SpinWorker : public Napi::AsyncWorker {
|
|||
}
|
||||
|
||||
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(), "gif")});
|
||||
}
|
||||
|
||||
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();
|
||||
Napi::Object result = Napi::Object::New(env);
|
||||
result.Set("data",
|
||||
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
|
||||
result.Set("type", "gif");
|
||||
return result;
|
||||
}
|
49
natives/swirl.cc
Normal file
49
natives/swirl.cc
Normal 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;
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef ESMBOT_NATIVES_MISC_H_
|
||||
#define ESMBOT_NATIVES_MISC_H_
|
||||
#ifndef ESMBOT_NATIVES_SWIRL_H_
|
||||
#define ESMBOT_NATIVES_SWIRL_H_
|
||||
|
||||
#include <napi.h>
|
||||
|
|
@ -1,27 +1,32 @@
|
|||
#include <napi.h>
|
||||
#include <list>
|
||||
#include <Magick++.h>
|
||||
#include <napi.h>
|
||||
|
||||
#include <list>
|
||||
|
||||
using namespace std;
|
||||
using namespace Magick;
|
||||
|
||||
class TileWorker : public Napi::AsyncWorker {
|
||||
public:
|
||||
TileWorker(Napi::Function& callback, string in_path, string type, int delay)
|
||||
: Napi::AsyncWorker(callback), in_path(in_path), type(type), delay(delay) {}
|
||||
~TileWorker() {}
|
||||
Napi::Value Tile(const Napi::CallbackInfo &info) {
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
void Execute() {
|
||||
list <Image> frames;
|
||||
list <Image> coalesced;
|
||||
list <Image> mid;
|
||||
readImages(&frames, in_path);
|
||||
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) {
|
||||
list <Image> duplicated;
|
||||
list<Image> duplicated;
|
||||
Image appended;
|
||||
list <Image> montage;
|
||||
list<Image> montage;
|
||||
Image frame;
|
||||
image.magick(type);
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
|
@ -49,29 +54,10 @@ class TileWorker : public Napi::AsyncWorker {
|
|||
}
|
||||
|
||||
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 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();
|
||||
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;
|
||||
}
|
|
@ -1,22 +1,27 @@
|
|||
#include <napi.h>
|
||||
#include <list>
|
||||
#include <Magick++.h>
|
||||
#include <napi.h>
|
||||
|
||||
#include <list>
|
||||
|
||||
using namespace std;
|
||||
using namespace Magick;
|
||||
|
||||
class TrumpWorker : public Napi::AsyncWorker {
|
||||
public:
|
||||
TrumpWorker(Napi::Function& callback, string in_path, string type, int delay)
|
||||
: Napi::AsyncWorker(callback), in_path(in_path), type(type), delay(delay) {}
|
||||
~TrumpWorker() {}
|
||||
Napi::Value Trump(const Napi::CallbackInfo &info) {
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
void Execute() {
|
||||
list <Image> frames;
|
||||
list <Image> coalesced;
|
||||
list <Image> mid;
|
||||
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;
|
||||
Image watermark;
|
||||
readImages(&frames, in_path);
|
||||
readImages(&frames, path);
|
||||
watermark.read("./assets/images/trump.png");
|
||||
coalesceImages(&coalesced, frames.begin(), frames.end());
|
||||
|
||||
|
@ -25,10 +30,12 @@ class TrumpWorker : public Napi::AsyncWorker {
|
|||
image.virtualPixelMethod(Magick::TransparentVirtualPixelMethod);
|
||||
image.backgroundColor("none");
|
||||
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.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.animationDelay(delay == 0 ? image.animationDelay() : delay);
|
||||
mid.push_back(watermark_new);
|
||||
|
@ -44,29 +51,10 @@ class TrumpWorker : public Napi::AsyncWorker {
|
|||
}
|
||||
|
||||
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 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();
|
||||
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;
|
||||
}
|
|
@ -1,21 +1,26 @@
|
|||
#include <napi.h>
|
||||
#include <list>
|
||||
#include <Magick++.h>
|
||||
#include <napi.h>
|
||||
|
||||
#include <list>
|
||||
|
||||
using namespace std;
|
||||
using namespace Magick;
|
||||
|
||||
class WallWorker : public Napi::AsyncWorker {
|
||||
public:
|
||||
WallWorker(Napi::Function& callback, string in_path, string type, int delay)
|
||||
: Napi::AsyncWorker(callback), in_path(in_path), type(type), delay(delay) {}
|
||||
~WallWorker() {}
|
||||
Napi::Value Wall(const Napi::CallbackInfo &info) {
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
void Execute() {
|
||||
list <Image> frames;
|
||||
list <Image> coalesced;
|
||||
list <Image> mid;
|
||||
readImages(&frames, in_path);
|
||||
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) {
|
||||
|
@ -24,7 +29,8 @@ class WallWorker : public Napi::AsyncWorker {
|
|||
image.matteColor("none");
|
||||
image.backgroundColor("none");
|
||||
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.scale(Geometry("800x800>"));
|
||||
image.magick(type);
|
||||
|
@ -42,29 +48,10 @@ class WallWorker : public Napi::AsyncWorker {
|
|||
}
|
||||
|
||||
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 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();
|
||||
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;
|
||||
}
|
|
@ -1,24 +1,36 @@
|
|||
#include <napi.h>
|
||||
#include <list>
|
||||
#include <iostream>
|
||||
#include <Magick++.h>
|
||||
#include <napi.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <list>
|
||||
|
||||
using namespace std;
|
||||
using namespace Magick;
|
||||
|
||||
class WatermarkWorker : public Napi::AsyncWorker {
|
||||
public:
|
||||
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) {}
|
||||
~WatermarkWorker() {}
|
||||
Napi::Value Watermark(const Napi::CallbackInfo &info) {
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
void Execute() {
|
||||
list <Image> frames;
|
||||
list <Image> coalesced;
|
||||
list <Image> mid;
|
||||
Napi::Object obj = info[0].As<Napi::Object>();
|
||||
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;
|
||||
|
||||
list<Image> frames;
|
||||
list<Image> coalesced;
|
||||
list<Image> mid;
|
||||
Image watermark;
|
||||
readImages(&frames, in_path);
|
||||
watermark.read(water_path);
|
||||
readImages(&frames, path);
|
||||
watermark.read(water);
|
||||
if (resize && append) {
|
||||
string query(to_string(frames.front().baseColumns()) + "x");
|
||||
watermark.scale(Geometry(query));
|
||||
|
@ -31,7 +43,7 @@ class WatermarkWorker : public Napi::AsyncWorker {
|
|||
for (Image &image : coalesced) {
|
||||
Image final;
|
||||
if (append) {
|
||||
list <Image> to_append;
|
||||
list<Image> to_append;
|
||||
to_append.push_back(image);
|
||||
to_append.push_back(watermark);
|
||||
appendImages(&final, to_append.begin(), to_append.end(), true);
|
||||
|
@ -39,10 +51,12 @@ class WatermarkWorker : public Napi::AsyncWorker {
|
|||
} else if (mc) {
|
||||
image.backgroundColor("white");
|
||||
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;
|
||||
} else {
|
||||
image.composite(watermark, Magick::GravityType(gravity), Magick::OverCompositeOp);
|
||||
image.composite(watermark, Magick::GravityType(gravity),
|
||||
Magick::OverCompositeOp);
|
||||
final = image;
|
||||
}
|
||||
image.magick(type);
|
||||
|
@ -60,35 +74,10 @@ class WatermarkWorker : public Napi::AsyncWorker {
|
|||
}
|
||||
|
||||
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, 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();
|
||||
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;
|
||||
}
|
|
@ -1,29 +1,35 @@
|
|||
#include <napi.h>
|
||||
#include <list>
|
||||
#include <Magick++.h>
|
||||
#include <napi.h>
|
||||
|
||||
#include <list>
|
||||
|
||||
using namespace std;
|
||||
using namespace Magick;
|
||||
|
||||
class WdtWorker : public Napi::AsyncWorker {
|
||||
public:
|
||||
WdtWorker(Napi::Function& callback, string in_path, string type, int delay)
|
||||
: Napi::AsyncWorker(callback), in_path(in_path), type(type), delay(delay) {}
|
||||
~WdtWorker() {}
|
||||
Napi::Value Wdt(const Napi::CallbackInfo &info) {
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
void Execute() {
|
||||
list <Image> frames;
|
||||
list <Image> coalesced;
|
||||
list <Image> mid;
|
||||
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;
|
||||
Image watermark;
|
||||
readImages(&frames, in_path);
|
||||
readImages(&frames, path);
|
||||
watermark.read("./assets/images/whodidthis.png");
|
||||
coalesceImages(&coalesced, frames.begin(), frames.end());
|
||||
|
||||
for (Image &image : coalesced) {
|
||||
Image watermark_new = watermark;
|
||||
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.animationDelay(delay == 0 ? image.animationDelay() : delay);
|
||||
mid.push_back(watermark_new);
|
||||
|
@ -39,29 +45,10 @@ class WdtWorker : public Napi::AsyncWorker {
|
|||
}
|
||||
|
||||
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 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();
|
||||
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;
|
||||
}
|
|
@ -15,14 +15,16 @@ exports.run = object => {
|
|||
// If no image type is given (say, the command generates its own image), make it a PNG.
|
||||
const fileExtension = object.type ? object.type.split("/")[1] : "png";
|
||||
const objectWithFixedType = Object.assign({}, object, {type: fileExtension});
|
||||
magick[object.cmd](objectWithFixedType, (error, data, type) => {
|
||||
if (error) reject(error);
|
||||
try {
|
||||
const result = magick[object.cmd](objectWithFixedType);
|
||||
const returnObject = {
|
||||
buffer: data,
|
||||
fileExtension: type
|
||||
buffer: result.data,
|
||||
fileExtension: result.type
|
||||
};
|
||||
resolve(returnObject);
|
||||
});
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -105,7 +105,7 @@ exports.disconnect = async () => {
|
|||
connection.destroy();
|
||||
}
|
||||
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 = [];
|
||||
return;
|
||||
|
|
Loading…
Reference in a new issue