Added grayscale and sepia
This commit is contained in:
parent
6494dcdcb4
commit
f71f18fc5d
8 changed files with 63 additions and 20 deletions
|
@ -1,5 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <napi.h>
|
||||
|
||||
Napi::Value Blurple(const Napi::CallbackInfo& info);
|
|
@ -7,7 +7,7 @@
|
|||
using namespace std;
|
||||
using namespace Magick;
|
||||
|
||||
Napi::Value Blurple(const Napi::CallbackInfo &info) {
|
||||
Napi::Value Colors(const Napi::CallbackInfo &info) {
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
try {
|
||||
|
@ -15,6 +15,7 @@ Napi::Value Blurple(const Napi::CallbackInfo &info) {
|
|||
Napi::Buffer<char> data = obj.Get("data").As<Napi::Buffer<char>>();
|
||||
bool old =
|
||||
obj.Has("old") ? obj.Get("old").As<Napi::Boolean>().Value() : false;
|
||||
string color = obj.Get("color").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;
|
||||
|
@ -23,7 +24,7 @@ Napi::Value Blurple(const Napi::CallbackInfo &info) {
|
|||
|
||||
list<Image> frames;
|
||||
list<Image> coalesced;
|
||||
list<Image> blurpled;
|
||||
list<Image> colored;
|
||||
try {
|
||||
readImages(&frames, Blob(data.Data(), data.Length()));
|
||||
} catch (Magick::WarningCoder &warning) {
|
||||
|
@ -34,23 +35,30 @@ Napi::Value Blurple(const Napi::CallbackInfo &info) {
|
|||
coalesceImages(&coalesced, frames.begin(), frames.end());
|
||||
|
||||
for (Image &image : coalesced) {
|
||||
image.threshold(49151.25);
|
||||
image.levelColors(old ? "#7289DA" : "#5865F2", "white");
|
||||
if (color == "blurple") {
|
||||
image.threshold(49151.25);
|
||||
image.levelColors(old ? "#7289DA" : "#5865F2", "white");
|
||||
} else if (color == "grayscale") {
|
||||
image.quantizeColorSpace(GRAYColorspace);
|
||||
image.quantizeColors(256);
|
||||
} else if (color == "sepia") {
|
||||
image.sepiaTone(49151.25);
|
||||
}
|
||||
image.magick(type);
|
||||
image.animationDelay(delay == 0 ? image.animationDelay() : delay);
|
||||
blurpled.push_back(image);
|
||||
colored.push_back(image);
|
||||
}
|
||||
|
||||
optimizeTransparency(blurpled.begin(), blurpled.end());
|
||||
optimizeTransparency(colored.begin(), colored.end());
|
||||
|
||||
if (type == "gif") {
|
||||
for (Image &image : blurpled) {
|
||||
for (Image &image : colored) {
|
||||
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
|
||||
image.quantize();
|
||||
}
|
||||
}
|
||||
|
||||
writeImages(blurpled.begin(), blurpled.end(), &blob);
|
||||
writeImages(colored.begin(), colored.end(), &blob);
|
||||
|
||||
Napi::Object result = Napi::Object::New(env);
|
||||
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
|
||||
|
@ -62,4 +70,4 @@ Napi::Value Blurple(const Napi::CallbackInfo &info) {
|
|||
} catch (...) {
|
||||
throw Napi::Error::New(env, "Unknown error");
|
||||
}
|
||||
}
|
||||
}
|
5
natives/colors.h
Normal file
5
natives/colors.h
Normal file
|
@ -0,0 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
#include <napi.h>
|
||||
|
||||
Napi::Value Colors(const Napi::CallbackInfo& info);
|
|
@ -1,7 +1,7 @@
|
|||
#include <napi.h>
|
||||
#include <list>
|
||||
#include "blur.h"
|
||||
#include "blurple.h"
|
||||
#include "colors.h"
|
||||
#include "caption.h"
|
||||
#include "caption2.h"
|
||||
#include "circle.h"
|
||||
|
@ -43,7 +43,7 @@
|
|||
Napi::Object Init(Napi::Env env, Napi::Object exports)
|
||||
{
|
||||
exports.Set(Napi::String::New(env, "blur"), Napi::Function::New(env, Blur));
|
||||
exports.Set(Napi::String::New(env, "blurple"), Napi::Function::New(env, Blurple));
|
||||
exports.Set(Napi::String::New(env, "colors"), Napi::Function::New(env, Colors));
|
||||
exports.Set(Napi::String::New(env, "caption"), Napi::Function::New(env, Caption));
|
||||
exports.Set(Napi::String::New(env, "captionTwo"), Napi::Function::New(env, CaptionTwo));
|
||||
exports.Set(Napi::String::New(env, "circle"), Napi::Function::New(env, Circle));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue