Even more Magick++ ports
This commit is contained in:
parent
78dbeabd39
commit
e860aee986
21 changed files with 372 additions and 69 deletions
|
@ -5,7 +5,7 @@ exports.run = async (message) => {
|
|||
message.channel.sendTyping();
|
||||
const image = await require("../utils/imagedetect.js")(message);
|
||||
if (image === undefined) return `${message.author.mention}, you need to provide an image to pixelate!`;
|
||||
const buffer = await promisify(magick.resize)(image.path, image.type.toUpperCase(), image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0);
|
||||
const buffer = await promisify(magick.resize)(image.path, false, image.type.toUpperCase(), image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0);
|
||||
return {
|
||||
file: buffer,
|
||||
name: `pixelate.${image.type}`
|
||||
|
|
|
@ -6,7 +6,7 @@ exports.run = async (message) => {
|
|||
const image = await require("../utils/imagedetect.js")(message);
|
||||
if (image === undefined) return `${message.author.mention}, you need to provide a GIF to reverse!`;
|
||||
if (image.type !== "gif") return `${message.author.mention}, that isn't a GIF!`;
|
||||
const buffer = await promisify(magick.reverse)(image.path, image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0);
|
||||
const buffer = await promisify(magick.reverse)(image.path, false, image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0);
|
||||
return {
|
||||
file: buffer,
|
||||
name: "reverse.gif"
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
const gm = require("gm").subClass({
|
||||
imageMagick: true
|
||||
});
|
||||
const magick = require("../build/Release/image.node");
|
||||
const { promisify } = require("util");
|
||||
|
||||
exports.run = async (message) => {
|
||||
message.channel.sendTyping();
|
||||
const image = await require("../utils/imagedetect.js")(message);
|
||||
if (image === undefined) return `${message.author.mention}, you need to provide a GIF to loop!`;
|
||||
if (image.type !== "gif") return `${message.author.mention}, that isn't a GIF!`;
|
||||
const buffer = await gm(image.path).coalesce().out("-duplicate", "1,-2-1").bufferPromise(image.type, image.delay);
|
||||
const buffer = await promisify(magick.reverse)(image.path, true, image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0);
|
||||
return {
|
||||
file: buffer,
|
||||
name: "soos.gif"
|
||||
|
|
|
@ -1,33 +1,16 @@
|
|||
const {
|
||||
exec
|
||||
} = require("child_process");
|
||||
const util = require("util");
|
||||
const gm = require("gm").subClass({
|
||||
imageMagick: true
|
||||
});
|
||||
const magick = require("../build/Release/image.node");
|
||||
const { promisify } = require("util");
|
||||
|
||||
exports.run = async (message) => {
|
||||
message.channel.sendTyping();
|
||||
const image = await require("../utils/imagedetect.js")(message);
|
||||
if (image === undefined) return `${message.author.mention}, you need to provide a GIF to speed up!`;
|
||||
if (image.type !== "gif") return `${message.author.mention}, that isn't a GIF!`;
|
||||
const value = await gm(image.path).identifyPromise();
|
||||
const delay = value.Delay ? value.Delay[0].split("x") : [0, 100];
|
||||
if (Math.round(parseInt(delay[0]) / 2) >= 2) {
|
||||
const buffer = await gm().delay(`${parseInt(delay[0]) / 2}x${delay[1]}`).out(image.path).bufferPromise(image.type, image.delay);
|
||||
return {
|
||||
file: buffer,
|
||||
name: "speed.gif"
|
||||
};
|
||||
} else {
|
||||
if (!value.Scene) return `${message.author.mention}, that GIF is already too fast!`;
|
||||
const numbers = (await util.promisify(exec)(`seq 0 2 ${value.Scene.length}`)).stdout.split("\n").join(",");
|
||||
const buffer = await gm().out("(").out(image.path).coalesce().out(")").out("-delete", numbers).bufferPromise(image.type, image.delay);
|
||||
return {
|
||||
file: buffer,
|
||||
name: "speed.gif"
|
||||
};
|
||||
}
|
||||
const buffer = await promisify(magick.speed)(image.path, false, image.type.toUpperCase(), image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0);
|
||||
return {
|
||||
file: buffer,
|
||||
name: "speed.gif"
|
||||
};
|
||||
};
|
||||
|
||||
exports.aliases = ["speedup", "fast", "gifspeed"];
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
const gm = require("gm").subClass({
|
||||
imageMagick: true
|
||||
});
|
||||
const magick = require("../build/Release/image.node");
|
||||
const { promisify } = require("util");
|
||||
|
||||
exports.run = async (message) => {
|
||||
const image = await require("../utils/imagedetect.js")(message);
|
||||
if (image === undefined) return `${message.author.mention}, you need to provide an image to spin!`;
|
||||
const processMessage = await message.channel.createMessage("<a:processing:479351417102925854> Processing... This might take a while");
|
||||
const seq = await gm(image.path).coalesce().out("-duplicate", "29").scale("256x256>").scale("256x256<").out("-alpha", "set").virtualPixel("transparent").out("-distort", "SRT", "%[fx:360*t/n]").set("delay", "5").out("-loop", "0").streamPromise("miff");
|
||||
const resultBuffer = await gm(seq).in("-dispose", "background").bufferPromise("gif");
|
||||
//const seq = await gm(image.path).coalesce().out("-duplicate", "29").scale("256x256>").scale("256x256<").out("-alpha", "set").virtualPixel("transparent").out("-distort", "SRT", "%[fx:360*t/n]").set("delay", "5").out("-loop", "0").streamPromise("miff");
|
||||
//const resultBuffer = await gm(seq).in("-dispose", "background").bufferPromise("gif");
|
||||
const buffer = await promisify(magick.spin)(image.path, image.type.toUpperCase(), image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0);
|
||||
await processMessage.delete();
|
||||
return {
|
||||
file: resultBuffer,
|
||||
file: buffer,
|
||||
name: "spin.gif"
|
||||
};
|
||||
};
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
const gm = require("gm").subClass({
|
||||
imageMagick: true
|
||||
});
|
||||
const magick = require("../build/Release/image.node");
|
||||
const { promisify } = require("util");
|
||||
|
||||
exports.run = async (message) => {
|
||||
message.channel.sendTyping();
|
||||
const image = await require("../utils/imagedetect.js")(message);
|
||||
if (image === undefined) return `${message.author.mention}, you need to provide an image to stretch!`;
|
||||
const buffer = await gm(image.path).coalesce().resize("512x512!").bufferPromise(image.type, image.delay);
|
||||
const buffer = await promisify(magick.resize)(image.path, true, image.type.toUpperCase(), image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0);
|
||||
return {
|
||||
file: buffer,
|
||||
name: `stretch.${image.type}`
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
const gm = require("gm").subClass({
|
||||
imageMagick: true
|
||||
});
|
||||
const magick = require("../build/Release/image.node");
|
||||
const { promisify } = require("util");
|
||||
|
||||
exports.run = async (message) => {
|
||||
message.channel.sendTyping();
|
||||
const image = await require("../utils/imagedetect.js")(message);
|
||||
if (image === undefined) return `${message.author.mention}, you need to provide an image to swirl!`;
|
||||
const buffer = await gm(image.path).coalesce().swirl(180).bufferPromise(image.type, image.delay);
|
||||
const buffer = await promisify(magick.swirl)(image.path, image.type.toUpperCase(), image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0);
|
||||
return {
|
||||
file: buffer,
|
||||
name: `swirl.${image.type}`
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
const gm = require("gm").subClass({
|
||||
imageMagick: true
|
||||
});
|
||||
const magick = require("../build/Release/image.node");
|
||||
const { promisify } = require("util");
|
||||
|
||||
exports.run = async (message) => {
|
||||
message.channel.sendTyping();
|
||||
const image = await require("../utils/imagedetect.js")(message);
|
||||
if (image === undefined) return `${message.author.mention}, you need to provide an image to tile!`;
|
||||
const output = await gm(image.path).coalesce().command("montage").out("-duplicate").out(24).tile("5x5").geometry("+0+0").streamPromise("miff");
|
||||
const buffer = await gm(output).coalesce().resize("800x800>").bufferPromise(image.type, image.delay);
|
||||
//const output = await gm(image.path).coalesce().command("montage").out("-duplicate").out(24).tile("5x5").geometry("+0+0").streamPromise("miff");
|
||||
//const buffer = await gm(output).coalesce().resize("800x800>").bufferPromise(image.type, image.delay);
|
||||
const buffer = await promisify(magick.tile)(image.path, image.type.toUpperCase(), image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0);
|
||||
return {
|
||||
file: buffer,
|
||||
name: `tile.${image.type}`
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
const gm = require("gm").subClass({
|
||||
imageMagick: true
|
||||
});
|
||||
const magick = require("../build/Release/image.node");
|
||||
const { promisify } = require("util");
|
||||
|
||||
exports.run = async (message) => {
|
||||
message.channel.sendTyping();
|
||||
const image = await require("../utils/imagedetect.js")(message);
|
||||
if (image === undefined) return `${message.author.mention}, you need to provide an image to make a Trump meme!`;
|
||||
const template = "./assets/images/trump.png";
|
||||
const buffer = await gm(template).background("white").out("null:").out("(").out(image.path).coalesce().out("-virtual-pixel", "transparent").resize("365x179!").out("+distort", "Perspective", "0,0 207,268 365,0 548,271 365,179 558,450 0,179 193,450").out(")").compose("over").gravity("Center").geometry("-217-135").out("-layers", "composite").bufferPromise(image.type, image.delay);
|
||||
//const buffer = await gm(template).background("white").out("null:").out("(").out(image.path).coalesce().out("-virtual-pixel", "transparent").resize("365x179!").out("+distort", "Perspective", "0,0 207,268 365,0 548,271 365,179 558,450 0,179 193,450").out(")").compose("over").gravity("Center").geometry("-217-135").out("-layers", "composite").bufferPromise(image.type, image.delay);
|
||||
const buffer = await promisify(magick.trump)(image.path, image.type.toUpperCase(), image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0);
|
||||
return {
|
||||
file: buffer,
|
||||
name: `trump.${image.type}`
|
||||
|
|
|
@ -18,12 +18,16 @@
|
|||
#include "magik.h"
|
||||
#include "meme.h"
|
||||
#include "mirror.h"
|
||||
#include "misc.h"
|
||||
#include "motivate.h"
|
||||
#include "resize.h"
|
||||
#include "reverse.h"
|
||||
#include "scott.h"
|
||||
#include "speed.h"
|
||||
#include "sonic.h"
|
||||
#include "spin.h"
|
||||
#include "tile.h"
|
||||
#include "trump.h"
|
||||
#include "watermark.h"
|
||||
|
||||
Napi::Object Init(Napi::Env env, Napi::Object exports)
|
||||
|
@ -53,6 +57,10 @@ Napi::Object Init(Napi::Env env, Napi::Object exports)
|
|||
exports.Set(Napi::String::New(env, "scott"), Napi::Function::New(env, Scott));
|
||||
exports.Set(Napi::String::New(env, "speed"), Napi::Function::New(env, Speed));
|
||||
exports.Set(Napi::String::New(env, "sonic"), Napi::Function::New(env, Sonic));
|
||||
exports.Set(Napi::String::New(env, "spin"), Napi::Function::New(env, Spin));
|
||||
exports.Set(Napi::String::New(env, "swirl"), Napi::Function::New(env, Swirl));
|
||||
exports.Set(Napi::String::New(env, "tile"), Napi::Function::New(env, Tile));
|
||||
exports.Set(Napi::String::New(env, "trump"), Napi::Function::New(env, Trump));
|
||||
exports.Set(Napi::String::New(env, "watermark"), Napi::Function::New(env, Watermark));
|
||||
return exports;
|
||||
}
|
||||
|
|
56
natives/misc.cc
Normal file
56
natives/misc.cc
Normal file
|
@ -0,0 +1,56 @@
|
|||
#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;
|
||||
list<Image> result;
|
||||
readImages(&frames, in_path);
|
||||
coalesceImages(&coalesced, frames.begin(), frames.end());
|
||||
|
||||
for (Image &image : coalesced) {
|
||||
image.swirl(180);
|
||||
image.magick(type);
|
||||
mid.push_back(image);
|
||||
}
|
||||
|
||||
optimizeImageLayers(&result, mid.begin(), mid.end());
|
||||
if (delay != 0) for_each(result.begin(), result.end(), animationDelayImage(delay));
|
||||
writeImages(result.begin(), result.end(), &blob);
|
||||
}
|
||||
|
||||
void OnOK() {
|
||||
Callback().Call({Env().Undefined(), Napi::Buffer<char>::Copy(Env(), (char *)blob.data(), blob.length())});
|
||||
}
|
||||
|
||||
private:
|
||||
string in_path, type;
|
||||
int delay, wordlength, i, n;
|
||||
size_t bytes, type_size;
|
||||
Blob blob;
|
||||
};
|
||||
|
||||
Napi::Value Swirl(const Napi::CallbackInfo &info)
|
||||
{
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
string in_path = info[0].As<Napi::String>().Utf8Value();
|
||||
string type = info[1].As<Napi::String>().Utf8Value();
|
||||
int delay = info[2].As<Napi::Number>().Int32Value();
|
||||
Napi::Function cb = info[3].As<Napi::Function>();
|
||||
|
||||
SwirlWorker* flopWorker = new SwirlWorker(cb, in_path, type, delay);
|
||||
flopWorker->Queue();
|
||||
return env.Undefined();
|
||||
}
|
8
natives/misc.h
Normal file
8
natives/misc.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifndef ESMBOT_NATIVES_MISC_H_
|
||||
#define ESMBOT_NATIVES_MISC_H_
|
||||
|
||||
#include <napi.h>
|
||||
|
||||
Napi::Value Swirl(const Napi::CallbackInfo& info);
|
||||
|
||||
#endif
|
|
@ -7,8 +7,8 @@ using namespace Magick;
|
|||
|
||||
class ResizeWorker : public Napi::AsyncWorker {
|
||||
public:
|
||||
ResizeWorker(Napi::Function& callback, string in_path, string type, int delay)
|
||||
: Napi::AsyncWorker(callback), in_path(in_path), type(type), delay(delay) {}
|
||||
ResizeWorker(Napi::Function& callback, string in_path, bool stretch, string type, int delay)
|
||||
: Napi::AsyncWorker(callback), in_path(in_path), stretch(stretch), type(type), delay(delay) {}
|
||||
~ResizeWorker() {}
|
||||
|
||||
void Execute() {
|
||||
|
@ -20,8 +20,12 @@ class ResizeWorker : public Napi::AsyncWorker {
|
|||
coalesceImages(&coalesced, frames.begin(), frames.end());
|
||||
|
||||
for (Image &image : coalesced) {
|
||||
image.scale(Geometry("10%"));
|
||||
image.scale(Geometry("1000%"));
|
||||
if (stretch) {
|
||||
image.resize(Geometry("512x512!"));
|
||||
} else {
|
||||
image.scale(Geometry("10%"));
|
||||
image.scale(Geometry("1000%"));
|
||||
}
|
||||
image.magick(type);
|
||||
blurred.push_back(image);
|
||||
}
|
||||
|
@ -40,6 +44,7 @@ class ResizeWorker : public Napi::AsyncWorker {
|
|||
int delay, wordlength, i, n, amount;
|
||||
size_t bytes, type_size;
|
||||
Blob blob;
|
||||
bool stretch;
|
||||
};
|
||||
|
||||
Napi::Value Resize(const Napi::CallbackInfo &info)
|
||||
|
@ -47,11 +52,12 @@ Napi::Value Resize(const Napi::CallbackInfo &info)
|
|||
Napi::Env env = info.Env();
|
||||
|
||||
string in_path = info[0].As<Napi::String>().Utf8Value();
|
||||
string type = info[1].As<Napi::String>().Utf8Value();
|
||||
int delay = info[2].As<Napi::Number>().Int32Value();
|
||||
Napi::Function cb = info[3].As<Napi::Function>();
|
||||
bool stretch = info[1].As<Napi::Boolean>().Value();
|
||||
string type = info[2].As<Napi::String>().Utf8Value();
|
||||
int delay = info[3].As<Napi::Number>().Int32Value();
|
||||
Napi::Function cb = info[4].As<Napi::Function>();
|
||||
|
||||
ResizeWorker* explodeWorker = new ResizeWorker(cb, in_path, type, delay);
|
||||
ResizeWorker* explodeWorker = new ResizeWorker(cb, in_path, stretch, type, delay);
|
||||
explodeWorker->Queue();
|
||||
return env.Undefined();
|
||||
}
|
|
@ -7,8 +7,8 @@ using namespace Magick;
|
|||
|
||||
class ReverseWorker : public Napi::AsyncWorker {
|
||||
public:
|
||||
ReverseWorker(Napi::Function& callback, string in_path, int delay)
|
||||
: Napi::AsyncWorker(callback), in_path(in_path), delay(delay) {}
|
||||
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() {
|
||||
|
@ -18,7 +18,13 @@ class ReverseWorker : public Napi::AsyncWorker {
|
|||
readImages(&frames, in_path);
|
||||
coalesceImages(&coalesced, frames.begin(), frames.end());
|
||||
|
||||
coalesced.reverse();
|
||||
if (soos) {
|
||||
list<Image> copy = coalesced;
|
||||
copy.reverse();
|
||||
coalesced.insert(coalesced.end(), copy.begin(), copy.end());
|
||||
} else {
|
||||
coalesced.reverse();
|
||||
}
|
||||
|
||||
optimizeImageLayers(&result, coalesced.begin(), coalesced.end());
|
||||
if (delay != 0) for_each(result.begin(), result.end(), animationDelayImage(delay));
|
||||
|
@ -34,6 +40,7 @@ class ReverseWorker : public Napi::AsyncWorker {
|
|||
int delay, wordlength, i, n, amount;
|
||||
size_t bytes, type_size;
|
||||
Blob blob;
|
||||
bool soos;
|
||||
};
|
||||
|
||||
Napi::Value Reverse(const Napi::CallbackInfo &info)
|
||||
|
@ -41,10 +48,11 @@ Napi::Value Reverse(const Napi::CallbackInfo &info)
|
|||
Napi::Env env = info.Env();
|
||||
|
||||
string in_path = info[0].As<Napi::String>().Utf8Value();
|
||||
int delay = info[1].As<Napi::Number>().Int32Value();
|
||||
Napi::Function cb = info[2].As<Napi::Function>();
|
||||
bool soos = info[1].As<Napi::Boolean>().Value();
|
||||
int delay = info[2].As<Napi::Number>().Int32Value();
|
||||
Napi::Function cb = info[3].As<Napi::Function>();
|
||||
|
||||
ReverseWorker* explodeWorker = new ReverseWorker(cb, in_path, delay);
|
||||
ReverseWorker* explodeWorker = new ReverseWorker(cb, in_path, soos, delay);
|
||||
explodeWorker->Queue();
|
||||
return env.Undefined();
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
#include <napi.h>
|
||||
#include <list>
|
||||
#include <iostream>
|
||||
#include <Magick++.h>
|
||||
|
||||
using namespace std;
|
||||
|
@ -16,7 +17,14 @@ class SpeedWorker : public Napi::AsyncWorker {
|
|||
list<Image> blurred;
|
||||
readImages(&frames, in_path);
|
||||
|
||||
for_each(frames.begin(), frames.end(), animationDelayImage(slow ? delay * 2 : delay / 2));
|
||||
int new_delay = slow ? delay * 2 : delay / 2;
|
||||
if (new_delay <= 1) {
|
||||
new_delay = delay;
|
||||
auto it = frames.begin();
|
||||
while(it != frames.end() && ++it != frames.end()) it = frames.erase(it);
|
||||
} else {
|
||||
for_each(frames.begin(), frames.end(), animationDelayImage(new_delay));
|
||||
}
|
||||
|
||||
writeImages(frames.begin(), frames.end(), &blob);
|
||||
}
|
||||
|
|
73
natives/spin.cc
Normal file
73
natives/spin.cc
Normal file
|
@ -0,0 +1,73 @@
|
|||
#include <napi.h>
|
||||
#include <list>
|
||||
#include <iostream>
|
||||
#include <Magick++.h>
|
||||
|
||||
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;
|
||||
list<Image> result;
|
||||
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.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++;
|
||||
}
|
||||
|
||||
optimizeImageLayers(&result, mid.begin(), mid.end());
|
||||
if (delay != 0) {
|
||||
for_each(result.begin(), result.end(), animationDelayImage(delay));
|
||||
} else if (type != "GIF") {
|
||||
for_each(result.begin(), result.end(), animationDelayImage(5));
|
||||
}
|
||||
writeImages(result.begin(), result.end(), &blob);
|
||||
}
|
||||
|
||||
void OnOK() {
|
||||
Callback().Call({Env().Undefined(), Napi::Buffer<char>::Copy(Env(), (char *)blob.data(), blob.length())});
|
||||
}
|
||||
|
||||
private:
|
||||
string in_path, type;
|
||||
int delay, wordlength, n;
|
||||
size_t bytes, type_size;
|
||||
Blob blob;
|
||||
};
|
||||
|
||||
Napi::Value Spin(const Napi::CallbackInfo &info)
|
||||
{
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
string in_path = info[0].As<Napi::String>().Utf8Value();
|
||||
string type = info[1].As<Napi::String>().Utf8Value();
|
||||
int delay = info[2].As<Napi::Number>().Int32Value();
|
||||
Napi::Function cb = info[3].As<Napi::Function>();
|
||||
|
||||
SpinWorker* blurWorker = new SpinWorker(cb, in_path, type, delay);
|
||||
blurWorker->Queue();
|
||||
return env.Undefined();
|
||||
}
|
8
natives/spin.h
Normal file
8
natives/spin.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifndef ESMBOT_NATIVES_SPIN_H_
|
||||
#define ESMBOT_NATIVES_SPIN_H_
|
||||
|
||||
#include <napi.h>
|
||||
|
||||
Napi::Value Spin(const Napi::CallbackInfo& info);
|
||||
|
||||
#endif
|
68
natives/tile.cc
Normal file
68
natives/tile.cc
Normal file
|
@ -0,0 +1,68 @@
|
|||
#include <napi.h>
|
||||
#include <list>
|
||||
#include <Magick++.h>
|
||||
|
||||
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;
|
||||
list<Image> result;
|
||||
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());
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
montage.push_back(appended);
|
||||
}
|
||||
appendImages(&frame, montage.begin(), montage.end(), true);
|
||||
frame.scale(Geometry("800x800>"));
|
||||
mid.push_back(frame);
|
||||
}
|
||||
|
||||
optimizeImageLayers(&result, mid.begin(), mid.end());
|
||||
if (delay != 0) for_each(result.begin(), result.end(), animationDelayImage(delay));
|
||||
writeImages(result.begin(), result.end(), &blob);
|
||||
}
|
||||
|
||||
void OnOK() {
|
||||
Callback().Call({Env().Undefined(), Napi::Buffer<char>::Copy(Env(), (char *)blob.data(), blob.length())});
|
||||
}
|
||||
|
||||
private:
|
||||
string in_path, type;
|
||||
int delay, wordlength, i, n;
|
||||
size_t bytes, type_size;
|
||||
Blob blob;
|
||||
};
|
||||
|
||||
Napi::Value Tile(const Napi::CallbackInfo &info)
|
||||
{
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
string in_path = info[0].As<Napi::String>().Utf8Value();
|
||||
string type = info[1].As<Napi::String>().Utf8Value();
|
||||
int delay = info[2].As<Napi::Number>().Int32Value();
|
||||
Napi::Function cb = info[3].As<Napi::Function>();
|
||||
|
||||
TileWorker* flopWorker = new TileWorker(cb, in_path, type, delay);
|
||||
flopWorker->Queue();
|
||||
return env.Undefined();
|
||||
}
|
8
natives/tile.h
Normal file
8
natives/tile.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifndef ESMBOT_NATIVES_TILE_H_
|
||||
#define ESMBOT_NATIVES_TILE_H_
|
||||
|
||||
#include <napi.h>
|
||||
|
||||
Napi::Value Tile(const Napi::CallbackInfo& info);
|
||||
|
||||
#endif
|
65
natives/trump.cc
Normal file
65
natives/trump.cc
Normal file
|
@ -0,0 +1,65 @@
|
|||
#include <napi.h>
|
||||
#include <list>
|
||||
#include <Magick++.h>
|
||||
|
||||
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;
|
||||
list<Image> result;
|
||||
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);
|
||||
mid.push_back(watermark_new);
|
||||
}
|
||||
|
||||
optimizeImageLayers(&result, mid.begin(), mid.end());
|
||||
if (delay != 0) for_each(result.begin(), result.end(), animationDelayImage(delay));
|
||||
writeImages(result.begin(), result.end(), &blob);
|
||||
}
|
||||
|
||||
void OnOK() {
|
||||
Callback().Call({Env().Undefined(), Napi::Buffer<char>::Copy(Env(), (char *)blob.data(), blob.length())});
|
||||
}
|
||||
|
||||
private:
|
||||
string in_path, type;
|
||||
int delay, wordlength, i, n;
|
||||
size_t bytes, type_size;
|
||||
Blob blob;
|
||||
};
|
||||
|
||||
Napi::Value Trump(const Napi::CallbackInfo &info)
|
||||
{
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
string in_path = info[0].As<Napi::String>().Utf8Value();
|
||||
string type = info[1].As<Napi::String>().Utf8Value();
|
||||
int delay = info[2].As<Napi::Number>().Int32Value();
|
||||
Napi::Function cb = info[3].As<Napi::Function>();
|
||||
|
||||
TrumpWorker* blurWorker = new TrumpWorker(cb, in_path, type, delay);
|
||||
blurWorker->Queue();
|
||||
return env.Undefined();
|
||||
}
|
8
natives/trump.h
Normal file
8
natives/trump.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifndef ESMBOT_NATIVES_TRUMP_H_
|
||||
#define ESMBOT_NATIVES_TRUMP_H_
|
||||
|
||||
#include <napi.h>
|
||||
|
||||
Napi::Value Trump(const Napi::CallbackInfo& info);
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue