Make all native image functions synchronous

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

View file

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

View file

@ -1,66 +1,51 @@
#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() {}
void Execute() {
list <Image> frames;
list <Image> coalesced;
readImages(&frames, in_path);
coalesceImages(&coalesced, frames.begin(), frames.end());
if (sharp) {
for_each(coalesced.begin(), coalesced.end(), sharpenImage(10, 3));
} else {
for_each(coalesced.begin(), coalesced.end(), blurImage(15));
}
for_each(coalesced.begin(), coalesced.end(), magickImage(type));
optimizeTransparency(coalesced.begin(), coalesced.end());
if (type == "gif") {
for (Image &image : coalesced) {
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
image.quantize();
if (delay != 0) image.animationDelay(delay);
}
}
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::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;
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();
Blob blob;
list<Image> frames;
list<Image> coalesced;
readImages(&frames, path);
coalesceImages(&coalesced, frames.begin(), frames.end());
if (sharp) {
for_each(coalesced.begin(), coalesced.end(), sharpenImage(10, 3));
} else {
for_each(coalesced.begin(), coalesced.end(), blurImage(15));
}
for_each(coalesced.begin(), coalesced.end(), magickImage(type));
optimizeTransparency(coalesced.begin(), coalesced.end());
if (type == "gif") {
for (Image &image : coalesced) {
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
image.quantize();
if (delay != 0) image.animationDelay(delay);
}
}
writeImages(coalesced.begin(), coalesced.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("type", type);
return result;
}

View file

@ -1,65 +1,50 @@
#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() {}
void Execute() {
list <Image> frames;
list <Image> coalesced;
list <Image> blurpled;
readImages(&frames, in_path);
coalesceImages(&coalesced, frames.begin(), frames.end());
for (Image &image : coalesced) {
image.threshold(49151.25);
image.levelColors("#7289DA", "white");
image.magick(type);
image.animationDelay(delay == 0 ? image.animationDelay() : delay);
blurpled.push_back(image);
}
optimizeTransparency(blurpled.begin(), blurpled.end());
if (type == "gif") {
for (Image &image : blurpled) {
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
image.quantize();
}
}
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::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;
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();
Blob blob;
list<Image> frames;
list<Image> coalesced;
list<Image> blurpled;
readImages(&frames, path);
coalesceImages(&coalesced, frames.begin(), frames.end());
for (Image &image : coalesced) {
image.threshold(49151.25);
image.levelColors("#7289DA", "white");
image.magick(type);
image.animationDelay(delay == 0 ? image.animationDelay() : delay);
blurpled.push_back(image);
}
optimizeTransparency(blurpled.begin(), blurpled.end());
if (type == "gif") {
for (Image &image : blurpled) {
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
image.quantize();
}
}
writeImages(blurpled.begin(), blurpled.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("type", type);
return result;
}

View file

@ -1,85 +1,70 @@
#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() {}
void Execute() {
list <Image> frames;
list <Image> coalesced;
list <Image> captioned;
list <Image> result;
readImages(&frames, in_path);
size_t width = frames.front().baseColumns();
string query(to_string(width - ((width / 25) * 2)) + "x");
Image caption_image(Geometry(query), Color("white"));
caption_image.fillColor("black");
caption_image.alpha(true);
caption_image.font("Futura");
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);
coalesceImages(&coalesced, frames.begin(), frames.end());
for (Image &image : coalesced) {
Image appended;
list <Image> images;
image.backgroundColor("white");
images.push_back(caption_image);
images.push_back(image);
appendImages(&appended, images.begin(), images.end(), true);
appended.repage();
appended.magick(type);
appended.animationDelay(delay == 0 ? image.animationDelay() : delay);
appended.gifDisposeMethod(Magick::BackgroundDispose);
captioned.push_back(appended);
}
optimizeTransparency(captioned.begin(), captioned.end());
if (type == "gif") {
for (Image &image : captioned) {
image.quantizeDither(false);
image.quantize();
}
}
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::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;
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();
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");
Image caption_image(Geometry(query), Color("white"));
caption_image.fillColor("black");
caption_image.alpha(true);
caption_image.font("Futura");
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);
coalesceImages(&coalesced, frames.begin(), frames.end());
for (Image &image : coalesced) {
Image appended;
list<Image> images;
image.backgroundColor("white");
images.push_back(caption_image);
images.push_back(image);
appendImages(&appended, images.begin(), images.end(), true);
appended.repage();
appended.magick(type);
appended.animationDelay(delay == 0 ? image.animationDelay() : delay);
appended.gifDisposeMethod(Magick::BackgroundDispose);
captioned.push_back(appended);
}
optimizeTransparency(captioned.begin(), captioned.end());
if (type == "gif") {
for (Image &image : captioned) {
image.quantizeDither(false);
image.quantize();
}
}
writeImages(captioned.begin(), captioned.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("type", type);
return result;
}

View file

@ -1,81 +1,68 @@
#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() {}
void Execute() {
list <Image> frames;
list <Image> coalesced;
list <Image> captioned;
Blob caption_blob;
readImages(&frames, in_path);
size_t width = frames.front().baseColumns();
string query(to_string(width - ((width / 25) * 2)) + "x");
Image caption_image(Geometry(query), Color("white"));
caption_image.fillColor("black");
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);
coalesceImages(&coalesced, frames.begin(), frames.end());
for (Image &image : coalesced) {
Image appended;
list <Image> images;
image.backgroundColor("white");
images.push_back(image);
images.push_back(caption_image);
appendImages(&appended, images.begin(), images.end(), true);
appended.repage();
appended.magick(type);
appended.animationDelay(delay == 0 ? image.animationDelay() : delay);
captioned.push_back(appended);
}
optimizeTransparency(captioned.begin(), captioned.end());
if (type == "gif") {
for (Image &image : captioned) {
image.quantizeDither(false);
image.quantize();
}
}
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::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;
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();
Blob blob;
list<Image> frames;
list<Image> coalesced;
list<Image> captioned;
Blob caption_blob;
readImages(&frames, path);
size_t width = frames.front().baseColumns();
string query(to_string(width - ((width / 25) * 2)) + "x");
Image caption_image(Geometry(query), Color("white"));
caption_image.fillColor("black");
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);
coalesceImages(&coalesced, frames.begin(), frames.end());
for (Image &image : coalesced) {
Image appended;
list<Image> images;
image.backgroundColor("white");
images.push_back(image);
images.push_back(caption_image);
appendImages(&appended, images.begin(), images.end(), true);
appended.repage();
appended.magick(type);
appended.animationDelay(delay == 0 ? image.animationDelay() : delay);
captioned.push_back(appended);
}
optimizeTransparency(captioned.begin(), captioned.end());
if (type == "gif") {
for (Image &image : captioned) {
image.quantizeDither(false);
image.quantize();
}
}
writeImages(captioned.begin(), captioned.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("type", type);
return result;
}

View file

@ -1,63 +1,49 @@
#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() {}
void Execute() {
list <Image> frames;
list <Image> coalesced;
list <Image> blurred;
readImages(&frames, in_path);
coalesceImages(&coalesced, frames.begin(), frames.end());
for (Image &image : coalesced) {
image.rotationalBlur(10);
image.magick(type);
blurred.push_back(image);
}
optimizeTransparency(blurred.begin(), blurred.end());
if (type == "gif") {
for (Image &image : blurred) {
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
image.quantize();
if (delay != 0) image.animationDelay(delay);
}
}
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::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;
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();
Blob blob;
list<Image> frames;
list<Image> coalesced;
list<Image> blurred;
readImages(&frames, path);
coalesceImages(&coalesced, frames.begin(), frames.end());
for (Image &image : coalesced) {
image.rotationalBlur(10);
image.magick(type);
blurred.push_back(image);
}
optimizeTransparency(blurred.begin(), blurred.end());
if (type == "gif") {
for (Image &image : blurred) {
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
image.quantize();
if (delay != 0) image.animationDelay(delay);
}
}
writeImages(blurred.begin(), blurred.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("type", type);
return result;
}

View file

@ -1,64 +1,57 @@
#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() {}
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.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);
}
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 Crop(const Napi::CallbackInfo &info)
{
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;
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();
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.magick(type);
mid.push_back(image);
}
optimizeTransparency(mid.begin(), mid.end());
if (type == "gif") {
for (Image &image : mid) {
image.quantizeDither(false);
image.quantize();
if (delay != 0) image.animationDelay(delay);
}
}
writeImages(mid.begin(), mid.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("type", type);
return result;
}

View file

@ -1,64 +1,50 @@
#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() {}
void Execute() {
list<Image> frames;
list<Image> coalesced;
list<Image> blurred;
readImages(&frames, in_path);
coalesceImages(&coalesced, frames.begin(), frames.end());
for (Image &image : coalesced) {
image.implode(amount);
image.magick(type);
blurred.push_back(image);
}
optimizeTransparency(blurred.begin(), blurred.end());
if (type == "gif") {
for (Image &image : blurred) {
image.quantizeDither(false);
image.quantize();
if (delay != 0) image.animationDelay(delay);
}
}
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::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;
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();
Blob blob;
list<Image> frames;
list<Image> coalesced;
list<Image> blurred;
readImages(&frames, path);
coalesceImages(&coalesced, frames.begin(), frames.end());
for (Image &image : coalesced) {
image.implode(amount);
image.magick(type);
blurred.push_back(image);
}
optimizeTransparency(blurred.begin(), blurred.end());
if (type == "gif") {
for (Image &image : blurred) {
image.quantizeDither(false);
image.quantize();
if (delay != 0) image.animationDelay(delay);
}
}
writeImages(blurred.begin(), blurred.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("type", type);
return result;
}

View file

@ -1,70 +1,58 @@
#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() {}
void Execute() {
list <Image> frames;
list <Image> coalesced;
list <Image> mid;
Image watermark;
readImages(&frames, in_path);
watermark.read(overlay_path);
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.scale(Geometry(query));
coalesceImages(&coalesced, frames.begin(), frames.end());
for (Image &image : coalesced) {
image.composite(watermark, Magick::NorthGravity, Magick::OverCompositeOp);
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, overlay_path, type;
int delay;
Blob blob;
};
Napi::Value Flag(const Napi::CallbackInfo &info)
{
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;
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();
Blob blob;
list<Image> frames;
list<Image> coalesced;
list<Image> mid;
Image watermark;
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.scale(Geometry(query));
coalesceImages(&coalesced, frames.begin(), frames.end());
for (Image &image : coalesced) {
image.composite(watermark, Magick::NorthGravity, Magick::OverCompositeOp);
image.magick(type);
mid.push_back(image);
}
optimizeTransparency(mid.begin(), mid.end());
if (type == "gif") {
for (Image &image : mid) {
image.quantizeDither(false);
image.quantize();
if (delay != 0) image.animationDelay(delay);
}
}
writeImages(mid.begin(), mid.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("type", type);
return result;
}

View file

@ -1,65 +1,51 @@
#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() {}
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) {
flop ? image.flop() : image.flip();
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;
bool flop;
int delay;
Blob blob;
};
Napi::Value Flip(const Napi::CallbackInfo &info)
{
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;
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;
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();
Blob blob;
list<Image> frames;
list<Image> coalesced;
list<Image> mid;
readImages(&frames, path);
coalesceImages(&coalesced, frames.begin(), frames.end());
for (Image &image : coalesced) {
flop ? image.flop() : image.flip();
image.magick(type);
mid.push_back(image);
}
optimizeTransparency(mid.begin(), mid.end());
if (type == "gif") {
for (Image &image : mid) {
image.quantizeDither(false);
image.quantize();
if (delay != 0) image.animationDelay(delay);
}
}
writeImages(mid.begin(), mid.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("type", type);
return result;
}

View file

@ -1,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() {}
void Execute() {
list <Image> frames;
readImages(&frames, in_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(), magickImage(type));
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::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;
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;
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();
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(), magickImage(type));
if (delay != 0)
for_each(frames.begin(), frames.end(), animationDelayImage(delay));
writeImages(frames.begin(), frames.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("type", type);
return result;
}

View file

@ -1,68 +1,54 @@
#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() {}
void Execute() {
list <Image> frames;
list <Image> coalesced;
list <Image> mid;
Image watermark;
readImages(&frames, in_path);
watermark.read("./assets/images/gamexplain.png");
coalesceImages(&coalesced, frames.begin(), frames.end());
for (Image &image : coalesced) {
image.backgroundColor("white");
image.scale(Geometry("1181x571!"));
image.extent(Geometry("1200x675-10-92"));
image.composite(watermark, Geometry("+0+0"), Magick::OverCompositeOp);
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 Gamexplain(const Napi::CallbackInfo &info)
{
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;
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();
Blob blob;
list<Image> frames;
list<Image> coalesced;
list<Image> mid;
Image watermark;
readImages(&frames, path);
watermark.read("./assets/images/gamexplain.png");
coalesceImages(&coalesced, frames.begin(), frames.end());
for (Image &image : coalesced) {
image.backgroundColor("white");
image.scale(Geometry("1181x571!"));
image.extent(Geometry("1200x675-10-92"));
image.composite(watermark, Geometry("+0+0"), Magick::OverCompositeOp);
image.magick(type);
mid.push_back(image);
}
optimizeTransparency(mid.begin(), mid.end());
if (type == "gif") {
for (Image &image : mid) {
image.quantizeDither(false);
image.quantize();
if (delay != 0) image.animationDelay(delay);
}
}
writeImages(mid.begin(), mid.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("type", type);
return result;
}

View file

@ -1,83 +1,70 @@
#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() {}
void Execute() {
list <Image> frames;
list <Image> coalesced;
list <Image> mid;
Image distort;
Image overlay;
readImages(&frames, in_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();
for (int i = 0; i < 29; ++i) {
coalesced.push_back(*it);
}
}
int i = 0;
for (Image &image : coalesced) {
image.scale(Geometry("500x500!"));
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(distort, Magick::CenterGravity, Magick::DistortCompositeOp);
image.magick("GIF");
mid.push_back(image);
i++;
}
optimizeTransparency(mid.begin(), mid.end());
if (delay != 0) {
for_each(mid.begin(), mid.end(), animationDelayImage(delay));
} else if (type != "gif") {
for_each(mid.begin(), mid.end(), animationDelayImage(5));
}
for (Image &image : mid) {
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
image.quantize();
}
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::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;
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();
Blob blob;
list<Image> frames;
list<Image> coalesced;
list<Image> mid;
Image distort;
Image overlay;
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();
for (int i = 0; i < 29; ++i) {
coalesced.push_back(*it);
}
}
int i = 0;
for (Image &image : coalesced) {
image.scale(Geometry("500x500!"));
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(distort, Magick::CenterGravity, Magick::DistortCompositeOp);
image.magick("GIF");
mid.push_back(image);
i++;
}
optimizeTransparency(mid.begin(), mid.end());
if (delay != 0) {
for_each(mid.begin(), mid.end(), animationDelayImage(delay));
} else if (type != "gif") {
for_each(mid.begin(), mid.end(), animationDelayImage(5));
}
for (Image &image : mid) {
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
image.quantize();
}
writeImages(mid.begin(), mid.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("type", type);
return result;
}

View file

@ -1,47 +1,33 @@
#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() {}
void Execute() {
Image image;
image.read("./assets/images/hbc.png");
image.textGravity(Magick::CenterGravity);
image.font("./assets/hbc.ttf");
image.textKerning(-5);
image.fillColor("white");
image.fontPointsize(96);
image.draw(DrawableText(0, 0, text));
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::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();
Blob blob;
Image image;
image.read("./assets/images/hbc.png");
image.textGravity(Magick::CenterGravity);
image.font("./assets/hbc.ttf");
image.textKerning(-5);
image.fillColor("white");
image.fontPointsize(96);
image.draw(DrawableText(0, 0, caption));
image.magick("PNG");
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", "png");
return result;
}

View file

@ -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"

View file

@ -1,65 +1,51 @@
#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() {}
void Execute() {
list <Image> frames;
list <Image> coalesced;
list <Image> mid;
readImages(&frames, in_path);
coalesceImages(&coalesced, frames.begin(), frames.end());
for_each(coalesced.begin(), coalesced.end(), negateImage());
for (Image &image : coalesced) {
image.negateChannel(Magick::AlphaChannel);
mid.push_back(image);
}
// Magick::ChannelType(Magick::CompositeChannels ^ Magick::AlphaChannel)
for_each(mid.begin(), mid.end(), magickImage(type));
optimizeTransparency(mid.begin(), mid.end());
if (type == "gif") {
for (Image &image : mid) {
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
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 Invert(const Napi::CallbackInfo &info)
{
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;
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();
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());
for (Image &image : coalesced) {
image.negateChannel(Magick::AlphaChannel);
mid.push_back(image);
}
// Magick::ChannelType(Magick::CompositeChannels ^ Magick::AlphaChannel)
for_each(mid.begin(), mid.end(), magickImage(type));
optimizeTransparency(mid.begin(), mid.end());
if (type == "gif") {
for (Image &image : mid) {
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
image.quantize();
if (delay != 0) image.animationDelay(delay);
}
}
writeImages(mid.begin(), mid.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("type", type);
return result;
}

View file

@ -1,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;
}

View file

@ -1,69 +1,55 @@
#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() {}
void Execute() {
list <Image> frames;
list <Image> coalesced;
list <Image> mid;
Image watermark;
readImages(&frames, in_path);
watermark.read("./assets/images/leak.png");
coalesceImages(&coalesced, frames.begin(), frames.end());
for (Image &image : coalesced) {
image.backgroundColor("white");
image.scale(Geometry("640x360!"));
image.rotate(15);
image.extent(Geometry("1280x720-700+100"));
image.composite(watermark, Geometry("+0+0"), Magick::OverCompositeOp);
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 Leak(const Napi::CallbackInfo &info)
{
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;
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();
Blob blob;
list<Image> frames;
list<Image> coalesced;
list<Image> mid;
Image watermark;
readImages(&frames, path);
watermark.read("./assets/images/leak.png");
coalesceImages(&coalesced, frames.begin(), frames.end());
for (Image &image : coalesced) {
image.backgroundColor("white");
image.scale(Geometry("640x360!"));
image.rotate(15);
image.extent(Geometry("1280x720-700+100"));
image.composite(watermark, Geometry("+0+0"), Magick::OverCompositeOp);
image.magick(type);
mid.push_back(image);
}
optimizeTransparency(mid.begin(), mid.end());
if (type == "gif") {
for (Image &image : mid) {
image.quantizeDither(false);
image.quantize();
if (delay != 0) image.animationDelay(delay);
}
}
writeImages(mid.begin(), mid.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("type", type);
return result;
}

View file

@ -1,66 +1,51 @@
#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() {}
void Execute() {
list <Image> frames;
list <Image> coalesced;
list <Image> blurred;
readImages(&frames, in_path);
coalesceImages(&coalesced, frames.begin(), frames.end());
for (Image &image : coalesced) {
image.scale(Geometry("350x350"));
image.liquidRescale(Geometry("175x175"));
image.liquidRescale(Geometry("350x350"));
image.magick(type);
blurred.push_back(image);
}
optimizeTransparency(blurred.begin(), blurred.end());
if (type == "gif") {
for (Image &image : blurred) {
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
image.quantize();
if (delay != 0) image.animationDelay(delay);
}
}
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::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;
int delay =
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
Blob blob;
MagikWorker* explodeWorker = new MagikWorker(cb, path, type, delay);
explodeWorker->Queue();
return env.Undefined();
list<Image> frames;
list<Image> coalesced;
list<Image> blurred;
readImages(&frames, path);
coalesceImages(&coalesced, frames.begin(), frames.end());
for (Image &image : coalesced) {
image.scale(Geometry("350x350"));
image.liquidRescale(Geometry("175x175"));
image.liquidRescale(Geometry("350x350"));
image.magick(type);
blurred.push_back(image);
}
optimizeTransparency(blurred.begin(), blurred.end());
if (type == "gif") {
for (Image &image : blurred) {
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
image.quantize();
if (delay != 0) image.animationDelay(delay);
}
}
writeImages(blurred.begin(), blurred.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("type", type);
return result;
}

View file

@ -1,97 +1,87 @@
#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() {}
void Execute() {
list <Image> frames;
list <Image> coalesced;
list <Image> mid;
Image top_text;
Image bottom_text;
readImages(&frames, in_path);
coalesceImages(&coalesced, frames.begin(), frames.end());
for_each(coalesced.begin(), coalesced.end(), scaleImage(Geometry(600, 600)));
top_text.size(Geometry(to_string(coalesced.front().columns())));
top_text.backgroundColor("none");
top_text.font("Impact");
top_text.fontPointsize(40);
top_text.textGravity(Magick::CenterGravity);
top_text.read("pango:<span foreground='white'>" + text_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);
if (text_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>");
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);
}
for (Image &image : coalesced) {
image.composite(top_text, Magick::NorthGravity, Magick::OverCompositeOp);
if (text_bottom != "") image.composite(bottom_text, Magick::SouthGravity, Magick::OverCompositeOp);
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, text_top, text_bottom;
int delay;
Blob blob;
};
Napi::Value Meme(const Napi::CallbackInfo &info)
{
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;
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();
Blob blob;
list<Image> frames;
list<Image> coalesced;
list<Image> mid;
Image top_text;
Image bottom_text;
readImages(&frames, path);
coalesceImages(&coalesced, frames.begin(), frames.end());
for_each(coalesced.begin(), coalesced.end(), scaleImage(Geometry(600, 600)));
top_text.size(Geometry(to_string(coalesced.front().columns())));
top_text.backgroundColor("none");
top_text.font("Impact");
top_text.fontPointsize(40);
top_text.textGravity(Magick::CenterGravity);
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);
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'>" + 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);
}
for (Image &image : coalesced) {
image.composite(top_text, Magick::NorthGravity, Magick::OverCompositeOp);
if (bottom != "")
image.composite(bottom_text, Magick::SouthGravity,
Magick::OverCompositeOp);
image.magick(type);
mid.push_back(image);
}
optimizeTransparency(mid.begin(), mid.end());
if (type == "gif") {
for (Image &image : mid) {
image.quantizeDither(false);
image.quantize();
if (delay != 0) image.animationDelay(delay);
}
}
writeImages(mid.begin(), mid.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("type", type);
return result;
}

View file

@ -1,93 +1,86 @@
#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() {}
void Execute() {
list <Image> frames;
list <Image> coalesced;
list <Image> mid;
MagickCore::GravityType gravity;
readImages(&frames, in_path);
coalesceImages(&coalesced, frames.begin(), frames.end());
if (vertical && first) {
gravity = Magick::NorthGravity;
} else if (!vertical && first) {
gravity = Magick::WestGravity;
} else if (vertical && !first) {
gravity = Magick::SouthGravity;
} else {
gravity = Magick::EastGravity;
}
for (Image &image : coalesced) {
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);
mirrored.push_back(image);
Image mirror = image;
if (vertical) {
mirror.flip();
} else {
mirror.flop();
}
if (first) {
mirrored.push_back(mirror);
} else {
mirrored.push_front(mirror);
}
appendImages(&final, mirrored.begin(), mirrored.end(), vertical);
final.repage();
final.magick(type);
final.animationDelay(delay == 0 ? image.animationDelay() : delay);
mid.push_back(final);
}
optimizeTransparency(mid.begin(), mid.end());
if (type == "gif") {
for (Image &image : mid) {
image.quantizeDither(false);
image.quantize();
}
}
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::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;
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;
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();
Blob blob;
list<Image> frames;
list<Image> coalesced;
list<Image> mid;
MagickCore::GravityType gravity;
readImages(&frames, path);
coalesceImages(&coalesced, frames.begin(), frames.end());
if (vertical && first) {
gravity = Magick::NorthGravity;
} else if (!vertical && first) {
gravity = Magick::WestGravity;
} else if (vertical && !first) {
gravity = Magick::SouthGravity;
} else {
gravity = Magick::EastGravity;
}
for (Image &image : coalesced) {
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);
mirrored.push_back(image);
Image mirror = image;
if (vertical) {
mirror.flip();
} else {
mirror.flop();
}
if (first) {
mirrored.push_back(mirror);
} else {
mirrored.push_front(mirror);
}
appendImages(&final, mirrored.begin(), mirrored.end(), vertical);
final.repage();
final.magick(type);
final.animationDelay(delay == 0 ? image.animationDelay() : delay);
mid.push_back(final);
}
optimizeTransparency(mid.begin(), mid.end());
if (type == "gif") {
for (Image &image : mid) {
image.quantizeDither(false);
image.quantize();
}
}
writeImages(mid.begin(), mid.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("type", type);
return result;
}

View file

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

View file

@ -1,99 +1,91 @@
#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() {}
void Execute() {
list <Image> frames;
list <Image> coalesced;
list <Image> mid;
Image top;
Image bottom;
readImages(&frames, in_path);
coalesceImages(&coalesced, frames.begin(), frames.end());
top.size(Geometry("600"));
top.backgroundColor("black");
top.font("Times");
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);
if (bottom_text != "") {
bottom.size(Geometry("600"));
bottom.backgroundColor("black");
bottom.font("Times");
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);
}
for (Image &image : coalesced) {
Image final;
image.scale(Geometry(500, 500));
image.borderColor("black");
image.border(Geometry(5, 5));
image.borderColor("white");
image.border(Geometry(3, 3));
image.backgroundColor("black");
image.extent(Geometry(600, image.rows() + 50), Magick::CenterGravity);
list <Image> to_append;
to_append.push_back(image);
to_append.push_back(top);
if (bottom_text != "") to_append.push_back(bottom);
appendImages(&final, to_append.begin(), to_append.end(), true);
final.repage();
final.magick(type);
final.animationDelay(delay == 0 ? image.animationDelay() : delay);
mid.push_back(final);
}
optimizeTransparency(mid.begin(), mid.end());
if (type == "gif") {
for (Image &image : mid) {
image.quantizeDither(false);
image.quantize();
}
}
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::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 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;
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();
Blob blob;
list<Image> frames;
list<Image> coalesced;
list<Image> mid;
Image top;
Image bottom;
readImages(&frames, path);
coalesceImages(&coalesced, frames.begin(), frames.end());
top.size(Geometry("600"));
top.backgroundColor("black");
top.font("Times");
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);
if (bottom_text != "") {
bottom.size(Geometry("600"));
bottom.backgroundColor("black");
bottom.font("Times");
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);
}
for (Image &image : coalesced) {
Image final;
image.scale(Geometry(500, 500));
image.borderColor("black");
image.border(Geometry(5, 5));
image.borderColor("white");
image.border(Geometry(3, 3));
image.backgroundColor("black");
image.extent(Geometry(600, image.rows() + 50), Magick::CenterGravity);
list<Image> to_append;
to_append.push_back(image);
to_append.push_back(top);
if (bottom_text != "") to_append.push_back(bottom);
appendImages(&final, to_append.begin(), to_append.end(), true);
final.repage();
final.magick(type);
final.animationDelay(delay == 0 ? image.animationDelay() : delay);
mid.push_back(final);
}
optimizeTransparency(mid.begin(), mid.end());
if (type == "gif") {
for (Image &image : mid) {
image.quantizeDither(false);
image.quantize();
}
}
writeImages(mid.begin(), mid.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("type", type);
return result;
}

View file

@ -1,73 +1,62 @@
#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() {}
void Execute() {
list <Image> frames;
list <Image> coalesced;
list <Image> blurred;
readImages(&frames, in_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) + "!"));
} else {
image.scale(Geometry("10%"));
image.scale(Geometry("1000%"));
}
image.magick(type);
blurred.push_back(image);
}
optimizeTransparency(blurred.begin(), blurred.end());
if (type == "gif") {
for (Image &image : blurred) {
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
image.quantize();
if (delay != 0) image.animationDelay(delay);
}
}
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::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;
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;
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();
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) + "!"));
} else {
image.scale(Geometry("10%"));
image.scale(Geometry("1000%"));
}
image.magick(type);
blurred.push_back(image);
}
optimizeTransparency(blurred.begin(), blurred.end());
if (type == "gif") {
for (Image &image : blurred) {
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
image.quantize();
if (delay != 0) image.animationDelay(delay);
}
}
writeImages(blurred.begin(), blurred.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("type", type);
return result;
}

View file

@ -1,94 +1,84 @@
#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() {}
void Execute() {
Image image;
Image line1_text;
Image line2_text;
Image line3_text;
image.read("./assets/images/retro.png");
line2_text.backgroundColor("none");
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.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);
image.composite(line2_text, Geometry("+0-100"), Magick::OverCompositeOp);
if (line2 != "") {
line1_text.backgroundColor("none");
line1_text.fontPointsize(64);
line1_text.textGravity(Magick::CenterGravity);
line1_text.font("Comic Sans MS");
line1_text.read("pango:<span foreground='white'>" + line1 + "</span>");
line1_text.extent(Geometry("1260x859+0+0"), Magick::CenterGravity);
Image line1_text_fill = line1_text;
line1_text_fill.channel(Magick::AlphaChannel);
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);
image.composite(line1_text, Geometry("+0-250"), Magick::OverCompositeOp);
}
if (line3 != "") {
line3_text.backgroundColor("none");
line3_text.fontPointsize(64);
line3_text.textGravity(Magick::CenterGravity);
line3_text.font("Comic Sans MS");
line3_text.read("pango:<span foreground='white'>" + line3 + "</span>");
line3_text.extent(Geometry("1260x859+0+0"), Magick::CenterGravity);
Image line3_text_fill = line3_text;
line3_text_fill.channel(Magick::AlphaChannel);
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);
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::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();
Blob blob;
Image image;
Image line1_text;
Image line2_text;
Image line3_text;
image.read("./assets/images/retro.png");
line2_text.backgroundColor("none");
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.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);
image.composite(line2_text, Geometry("+0-100"), Magick::OverCompositeOp);
if (line2 != "") {
line1_text.backgroundColor("none");
line1_text.fontPointsize(64);
line1_text.textGravity(Magick::CenterGravity);
line1_text.font("Comic Sans MS");
line1_text.read("pango:<span foreground='white'>" + line1 + "</span>");
line1_text.extent(Geometry("1260x859+0+0"), Magick::CenterGravity);
Image line1_text_fill = line1_text;
line1_text_fill.channel(Magick::AlphaChannel);
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);
image.composite(line1_text, Geometry("+0-250"), Magick::OverCompositeOp);
}
if (line3 != "") {
line3_text.backgroundColor("none");
line3_text.fontPointsize(64);
line3_text.textGravity(Magick::CenterGravity);
line3_text.font("Comic Sans MS");
line3_text.read("pango:<span foreground='white'>" + line3 + "</span>");
line3_text.extent(Geometry("1260x859+0+0"), Magick::CenterGravity);
Image line3_text_fill = line3_text;
line3_text_fill.channel(Magick::AlphaChannel);
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);
image.composite(line3_text, Geometry("+0+50"), Magick::OverCompositeOp);
}
image.magick("PNG");
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", "png");
return result;
}

View file

@ -1,65 +1,51 @@
#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() {}
void Execute() {
list<Image> frames;
list<Image> coalesced;
readImages(&frames, in_path);
coalesceImages(&coalesced, frames.begin(), frames.end());
if (soos) {
list<Image> copy = coalesced;
copy.reverse();
coalesced.insert(coalesced.end(), copy.begin(), copy.end());
} else {
coalesced.reverse();
}
for_each(coalesced.begin(), coalesced.end(), magickImage("GIF"));
optimizeTransparency(coalesced.begin(), coalesced.end());
for (Image &image : coalesced) {
image.quantizeDither(false);
image.quantize();
if (delay != 0) image.animationDelay(delay);
}
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::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;
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();
Blob blob;
list<Image> frames;
list<Image> coalesced;
readImages(&frames, path);
coalesceImages(&coalesced, frames.begin(), frames.end());
if (soos) {
list<Image> copy = coalesced;
copy.reverse();
coalesced.insert(coalesced.end(), copy.begin(), copy.end());
} else {
coalesced.reverse();
}
for_each(coalesced.begin(), coalesced.end(), magickImage("GIF"));
optimizeTransparency(coalesced.begin(), coalesced.end());
for (Image &image : coalesced) {
image.quantizeDither(false);
image.quantize();
if (delay != 0) image.animationDelay(delay);
}
writeImages(coalesced.begin(), coalesced.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", "gif");
return result;
}

View file

@ -1,72 +1,60 @@
#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() {}
void Execute() {
list <Image> frames;
list <Image> coalesced;
list <Image> mid;
Image watermark;
readImages(&frames, in_path);
watermark.read("./assets/images/scott.png");
coalesceImages(&coalesced, frames.begin(), frames.end());
for (Image &image : coalesced) {
Image watermark_new = watermark;
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};
image.distort(Magick::PerspectiveDistortion, 16, arguments, true);
image.extent(Geometry("864x481"), Magick::CenterGravity);
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);
}
optimizeTransparency(mid.begin(), mid.end());
if (type == "gif") {
for (Image &image : mid) {
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
image.quantize();
}
}
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::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;
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();
Blob blob;
list<Image> frames;
list<Image> coalesced;
list<Image> mid;
Image watermark;
readImages(&frames, path);
watermark.read("./assets/images/scott.png");
coalesceImages(&coalesced, frames.begin(), frames.end());
for (Image &image : coalesced) {
Image watermark_new = watermark;
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};
image.distort(Magick::PerspectiveDistortion, 16, arguments, true);
image.extent(Geometry("864x481"), Magick::CenterGravity);
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);
}
optimizeTransparency(mid.begin(), mid.end());
if (type == "gif") {
for (Image &image : mid) {
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
image.quantize();
}
}
writeImages(mid.begin(), mid.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("type", type);
return result;
}

View file

@ -1,50 +1,36 @@
#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() {}
void Execute() {
Image image;
Image text_image;
text_image.backgroundColor("none");
text_image.fontPointsize(72);
text_image.textGravity(Magick::CenterGravity);
text_image.font("Bitstream Vera Sans");
text_image.read("pango:<span foreground='white'>" + text + "</span>");
text_image.resize(Geometry(474, 332));
text_image.extent(Geometry("1024x538-435-145"), Magick::CenterGravity);
image.read("./assets/images/sonic.jpg");
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::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();
Blob blob;
Image image;
Image text_image;
text_image.backgroundColor("none");
text_image.fontPointsize(72);
text_image.textGravity(Magick::CenterGravity);
text_image.font("Bitstream Vera Sans");
text_image.read("pango:<span foreground='white'>" + text + "</span>");
text_image.resize(Geometry(474, 332));
text_image.extent(Geometry("1024x538-435-145"), Magick::CenterGravity);
image.read("./assets/images/sonic.jpg");
image.composite(text_image, Geometry("+160+10"), Magick::OverCompositeOp);
image.magick("PNG");
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", "png");
return result;
}

View file

@ -1,93 +1,78 @@
#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() {}
void Execute() {
list <Image> frames;
readImages(&frames, in_path);
// if passed a delay, use that. otherwise use the average frame delay.
if (delay == 0) {
vector<int> old_delays;
bool removeFrames = false;
for (Image &image : frames) {
int animation_delay = image.animationDelay();
old_delays.push_back(animation_delay);
}
for (Image &image : frames) {
int old_delay = image.animationDelay();
int new_delay = slow ? old_delay * speed : old_delay / speed;
if (!slow && new_delay <= 1) {
removeFrames = true;
break;
}
image.animationDelay(new_delay);
}
if (removeFrames) {
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;
});
}
}
} 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;
});
}
} else {
for_each(frames.begin(), frames.end(), animationDelayImage(new_delay));
}
}
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::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;
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;
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();
Blob blob;
list<Image> frames;
readImages(&frames, path);
// if passed a delay, use that. otherwise use the average frame delay.
if (delay == 0) {
vector<int> old_delays;
bool removeFrames = false;
for (Image &image : frames) {
int animation_delay = image.animationDelay();
old_delays.push_back(animation_delay);
}
for (Image &image : frames) {
int old_delay = image.animationDelay();
int new_delay = slow ? old_delay * speed : old_delay / speed;
if (!slow && new_delay <= 1) {
removeFrames = true;
break;
}
image.animationDelay(new_delay);
}
if (removeFrames) {
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; });
}
}
} 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; });
}
} else {
for_each(frames.begin(), frames.end(), animationDelayImage(new_delay));
}
}
for_each(frames.begin(), frames.end(), magickImage(type));
writeImages(frames.begin(), frames.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("type", type);
return result;
}

View file

@ -1,80 +1,67 @@
#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() {}
void Execute() {
list <Image> frames;
list <Image> coalesced;
list <Image> mid;
readImages(&frames, in_path);
coalesceImages(&coalesced, frames.begin(), frames.end());
if (type != "gif") {
list <Image>::iterator it = coalesced.begin();
for (int i = 0; i < 29; ++i) {
coalesced.push_back(*it);
}
}
int i = 0;
for (Image &image : coalesced) {
image.virtualPixelMethod(Magick::TransparentVirtualPixelMethod);
image.scale(Geometry("256x256"));
image.alphaChannel(Magick::SetAlphaChannel);
double rotation[1] = {360 * i / coalesced.size()};
image.distort(Magick::ScaleRotateTranslateDistortion, 1, rotation);
image.magick("GIF");
mid.push_back(image);
i++;
}
for_each(mid.begin(), mid.end(), gifDisposeMethodImage(Magick::BackgroundDispose));
optimizeTransparency(mid.begin(), mid.end());
if (delay != 0) {
for_each(mid.begin(), mid.end(), animationDelayImage(delay));
} else if (type != "gif") {
for_each(mid.begin(), mid.end(), animationDelayImage(5));
}
for (Image &image : mid) {
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
image.quantize();
}
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::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;
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();
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();
for (int i = 0; i < 29; ++i) {
coalesced.push_back(*it);
}
}
int i = 0;
for (Image &image : coalesced) {
image.virtualPixelMethod(Magick::TransparentVirtualPixelMethod);
image.scale(Geometry("256x256"));
image.alphaChannel(Magick::SetAlphaChannel);
double rotation[1] = {360 * i / coalesced.size()};
image.distort(Magick::ScaleRotateTranslateDistortion, 1, rotation);
image.magick("GIF");
mid.push_back(image);
i++;
}
for_each(mid.begin(), mid.end(),
gifDisposeMethodImage(Magick::BackgroundDispose));
optimizeTransparency(mid.begin(), mid.end());
if (delay != 0) {
for_each(mid.begin(), mid.end(), animationDelayImage(delay));
} else if (type != "gif") {
for_each(mid.begin(), mid.end(), animationDelayImage(5));
}
for (Image &image : mid) {
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
image.quantize();
}
writeImages(mid.begin(), mid.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("type", "gif");
return result;
}

49
natives/swirl.cc Normal file
View file

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

View file

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

View file

@ -1,77 +1,63 @@
#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() {}
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) {
list <Image> duplicated;
Image appended;
list <Image> montage;
Image frame;
image.magick(type);
for (int i = 0; i < 5; ++i) {
duplicated.push_back(image);
}
appendImages(&appended, duplicated.begin(), duplicated.end());
appended.repage();
for (int i = 0; i < 5; ++i) {
montage.push_back(appended);
}
appendImages(&frame, montage.begin(), montage.end(), true);
frame.repage();
frame.scale(Geometry("800x800>"));
frame.animationDelay(delay == 0 ? image.animationDelay() : delay);
mid.push_back(frame);
}
optimizeTransparency(mid.begin(), mid.end());
if (type == "gif") {
for (Image &image : mid) {
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
image.quantize();
}
}
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::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;
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();
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;
Image appended;
list<Image> montage;
Image frame;
image.magick(type);
for (int i = 0; i < 5; ++i) {
duplicated.push_back(image);
}
appendImages(&appended, duplicated.begin(), duplicated.end());
appended.repage();
for (int i = 0; i < 5; ++i) {
montage.push_back(appended);
}
appendImages(&frame, montage.begin(), montage.end(), true);
frame.repage();
frame.scale(Geometry("800x800>"));
frame.animationDelay(delay == 0 ? image.animationDelay() : delay);
mid.push_back(frame);
}
optimizeTransparency(mid.begin(), mid.end());
if (type == "gif") {
for (Image &image : mid) {
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
image.quantize();
}
}
writeImages(mid.begin(), mid.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("type", type);
return result;
}

View file

@ -1,72 +1,60 @@
#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() {}
void Execute() {
list <Image> frames;
list <Image> coalesced;
list <Image> mid;
Image watermark;
readImages(&frames, in_path);
watermark.read("./assets/images/trump.png");
coalesceImages(&coalesced, frames.begin(), frames.end());
for (Image &image : coalesced) {
Image watermark_new = watermark;
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};
image.distort(Magick::PerspectiveDistortion, 16, arguments, true);
image.extent(Geometry("800x450"), Magick::CenterGravity);
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);
}
optimizeTransparency(mid.begin(), mid.end());
if (type == "gif") {
for (Image &image : mid) {
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
image.quantize();
}
}
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::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;
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();
Blob blob;
list<Image> frames;
list<Image> coalesced;
list<Image> mid;
Image watermark;
readImages(&frames, path);
watermark.read("./assets/images/trump.png");
coalesceImages(&coalesced, frames.begin(), frames.end());
for (Image &image : coalesced) {
Image watermark_new = watermark;
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};
image.distort(Magick::PerspectiveDistortion, 16, arguments, true);
image.extent(Geometry("800x450"), Magick::CenterGravity);
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);
}
optimizeTransparency(mid.begin(), mid.end());
if (type == "gif") {
for (Image &image : mid) {
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
image.quantize();
}
}
writeImages(mid.begin(), mid.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("type", type);
return result;
}

View file

@ -1,70 +1,57 @@
#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() {}
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.resize(Geometry("128x128"));
image.virtualPixelMethod(Magick::TileVirtualPixelMethod);
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};
image.distort(Magick::PerspectiveDistortion, 16, arguments);
image.scale(Geometry("800x800>"));
image.magick(type);
mid.push_back(image);
}
optimizeTransparency(mid.begin(), mid.end());
if (type == "gif") {
for (Image &image : mid) {
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
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 Wall(const Napi::CallbackInfo &info)
{
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;
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();
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.resize(Geometry("128x128"));
image.virtualPixelMethod(Magick::TileVirtualPixelMethod);
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};
image.distort(Magick::PerspectiveDistortion, 16, arguments);
image.scale(Geometry("800x800>"));
image.magick(type);
mid.push_back(image);
}
optimizeTransparency(mid.begin(), mid.end());
if (type == "gif") {
for (Image &image : mid) {
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
image.quantize();
if (delay != 0) image.animationDelay(delay);
}
}
writeImages(mid.begin(), mid.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("type", type);
return result;
}

View file

@ -1,94 +1,83 @@
#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() {}
void Execute() {
list <Image> frames;
list <Image> coalesced;
list <Image> mid;
Image watermark;
readImages(&frames, in_path);
watermark.read(water_path);
if (resize && append) {
string query(to_string(frames.front().baseColumns()) + "x");
watermark.scale(Geometry(query));
} else if (resize) {
string query("x" + to_string(frames.front().baseRows()));
watermark.scale(Geometry(query));
}
coalesceImages(&coalesced, frames.begin(), frames.end());
for (Image &image : coalesced) {
Image final;
if (append) {
list <Image> to_append;
to_append.push_back(image);
to_append.push_back(watermark);
appendImages(&final, to_append.begin(), to_append.end(), true);
final.repage();
} else if (mc) {
image.backgroundColor("white");
image.extent(Geometry(image.columns(), image.rows() + 15));
image.composite(watermark, Magick::GravityType(gravity), Magick::OverCompositeOp);
final = image;
} else {
image.composite(watermark, Magick::GravityType(gravity), Magick::OverCompositeOp);
final = image;
}
image.magick(type);
final.animationDelay(delay == 0 ? image.animationDelay() : delay);
mid.push_back(final);
}
optimizeTransparency(mid.begin(), mid.end());
if (type == "gif") {
for (Image &image : mid) {
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
image.quantize();
}
}
writeImages(mid.begin(), mid.end(), &blob);
}
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::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 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;
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();
Blob blob;
list<Image> frames;
list<Image> coalesced;
list<Image> mid;
Image watermark;
readImages(&frames, path);
watermark.read(water);
if (resize && append) {
string query(to_string(frames.front().baseColumns()) + "x");
watermark.scale(Geometry(query));
} else if (resize) {
string query("x" + to_string(frames.front().baseRows()));
watermark.scale(Geometry(query));
}
coalesceImages(&coalesced, frames.begin(), frames.end());
for (Image &image : coalesced) {
Image final;
if (append) {
list<Image> to_append;
to_append.push_back(image);
to_append.push_back(watermark);
appendImages(&final, to_append.begin(), to_append.end(), true);
final.repage();
} else if (mc) {
image.backgroundColor("white");
image.extent(Geometry(image.columns(), image.rows() + 15));
image.composite(watermark, Magick::GravityType(gravity),
Magick::OverCompositeOp);
final = image;
} else {
image.composite(watermark, Magick::GravityType(gravity),
Magick::OverCompositeOp);
final = image;
}
image.magick(type);
final.animationDelay(delay == 0 ? image.animationDelay() : delay);
mid.push_back(final);
}
optimizeTransparency(mid.begin(), mid.end());
if (type == "gif") {
for (Image &image : mid) {
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
image.quantize();
}
}
writeImages(mid.begin(), mid.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("type", type);
return result;
}

View file

@ -1,67 +1,54 @@
#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() {}
void Execute() {
list <Image> frames;
list <Image> coalesced;
list <Image> mid;
Image watermark;
readImages(&frames, in_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.magick(type);
watermark_new.animationDelay(delay == 0 ? image.animationDelay() : delay);
mid.push_back(watermark_new);
}
optimizeTransparency(mid.begin(), mid.end());
if (type == "gif") {
for (Image &image : mid) {
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
image.quantize();
}
}
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::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;
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();
Blob blob;
list<Image> frames;
list<Image> coalesced;
list<Image> mid;
Image watermark;
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.magick(type);
watermark_new.animationDelay(delay == 0 ? image.animationDelay() : delay);
mid.push_back(watermark_new);
}
optimizeTransparency(mid.begin(), mid.end());
if (type == "gif") {
for (Image &image : mid) {
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
image.quantize();
}
}
writeImages(mid.begin(), mid.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("type", type);
return result;
}

View file

@ -15,14 +15,16 @@ exports.run = object => {
// If no image type is given (say, the command generates its own image), make it a PNG.
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);
}
});
};

View file

@ -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;