Added grayscale and sepia
This commit is contained in:
parent
6494dcdcb4
commit
f71f18fc5d
8 changed files with 63 additions and 20 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -39,3 +39,4 @@ todo.txt
|
||||||
migratedb.js
|
migratedb.js
|
||||||
processed.txt
|
processed.txt
|
||||||
data.sqlite
|
data.sqlite
|
||||||
|
.cache
|
||||||
|
|
|
@ -3,7 +3,8 @@ import ImageCommand from "../../classes/imageCommand.js";
|
||||||
class BlurpleCommand extends ImageCommand {
|
class BlurpleCommand extends ImageCommand {
|
||||||
params() {
|
params() {
|
||||||
return {
|
return {
|
||||||
old: !!this.specialArgs.old
|
old: !!this.specialArgs.old,
|
||||||
|
color: "blurple"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +15,7 @@ class BlurpleCommand extends ImageCommand {
|
||||||
}];
|
}];
|
||||||
|
|
||||||
static noImage = "You need to provide an image to make blurple!";
|
static noImage = "You need to provide an image to make blurple!";
|
||||||
static command = "blurple";
|
static command = "colors";
|
||||||
static aliases = ["blurp"];
|
static aliases = ["blurp"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
17
commands/image-editing/grayscale.js
Normal file
17
commands/image-editing/grayscale.js
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
import ImageCommand from "../../classes/imageCommand.js";
|
||||||
|
|
||||||
|
class GrayscaleCommand extends ImageCommand {
|
||||||
|
params() {
|
||||||
|
return {
|
||||||
|
color: "grayscale"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
static description = "Adds a grayscale filter";
|
||||||
|
|
||||||
|
static noImage = "You need to provide an image to turn grayscale!";
|
||||||
|
static command = "colors";
|
||||||
|
static aliases = ["gray", "greyscale", "grey"];
|
||||||
|
}
|
||||||
|
|
||||||
|
export default GrayscaleCommand;
|
16
commands/image-editing/sepia.js
Normal file
16
commands/image-editing/sepia.js
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
import ImageCommand from "../../classes/imageCommand.js";
|
||||||
|
|
||||||
|
class SepiaCommand extends ImageCommand {
|
||||||
|
params() {
|
||||||
|
return {
|
||||||
|
color: "sepia"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
static description = "Adds a sepia filter";
|
||||||
|
|
||||||
|
static noImage = "You need to provide an image to add a sepia filter!";
|
||||||
|
static command = "colors";
|
||||||
|
}
|
||||||
|
|
||||||
|
export default SepiaCommand;
|
|
@ -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 std;
|
||||||
using namespace Magick;
|
using namespace Magick;
|
||||||
|
|
||||||
Napi::Value Blurple(const Napi::CallbackInfo &info) {
|
Napi::Value Colors(const Napi::CallbackInfo &info) {
|
||||||
Napi::Env env = info.Env();
|
Napi::Env env = info.Env();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -15,6 +15,7 @@ Napi::Value Blurple(const Napi::CallbackInfo &info) {
|
||||||
Napi::Buffer<char> data = obj.Get("data").As<Napi::Buffer<char>>();
|
Napi::Buffer<char> data = obj.Get("data").As<Napi::Buffer<char>>();
|
||||||
bool old =
|
bool old =
|
||||||
obj.Has("old") ? obj.Get("old").As<Napi::Boolean>().Value() : false;
|
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();
|
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
||||||
int delay =
|
int delay =
|
||||||
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
|
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> frames;
|
||||||
list<Image> coalesced;
|
list<Image> coalesced;
|
||||||
list<Image> blurpled;
|
list<Image> colored;
|
||||||
try {
|
try {
|
||||||
readImages(&frames, Blob(data.Data(), data.Length()));
|
readImages(&frames, Blob(data.Data(), data.Length()));
|
||||||
} catch (Magick::WarningCoder &warning) {
|
} catch (Magick::WarningCoder &warning) {
|
||||||
|
@ -34,23 +35,30 @@ Napi::Value Blurple(const Napi::CallbackInfo &info) {
|
||||||
coalesceImages(&coalesced, frames.begin(), frames.end());
|
coalesceImages(&coalesced, frames.begin(), frames.end());
|
||||||
|
|
||||||
for (Image &image : coalesced) {
|
for (Image &image : coalesced) {
|
||||||
image.threshold(49151.25);
|
if (color == "blurple") {
|
||||||
image.levelColors(old ? "#7289DA" : "#5865F2", "white");
|
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.magick(type);
|
||||||
image.animationDelay(delay == 0 ? image.animationDelay() : delay);
|
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") {
|
if (type == "gif") {
|
||||||
for (Image &image : blurpled) {
|
for (Image &image : colored) {
|
||||||
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
|
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
|
||||||
image.quantize();
|
image.quantize();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
writeImages(blurpled.begin(), blurpled.end(), &blob);
|
writeImages(colored.begin(), colored.end(), &blob);
|
||||||
|
|
||||||
Napi::Object result = Napi::Object::New(env);
|
Napi::Object result = Napi::Object::New(env);
|
||||||
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
|
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
|
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 <napi.h>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include "blur.h"
|
#include "blur.h"
|
||||||
#include "blurple.h"
|
#include "colors.h"
|
||||||
#include "caption.h"
|
#include "caption.h"
|
||||||
#include "caption2.h"
|
#include "caption2.h"
|
||||||
#include "circle.h"
|
#include "circle.h"
|
||||||
|
@ -43,7 +43,7 @@
|
||||||
Napi::Object Init(Napi::Env env, Napi::Object exports)
|
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, "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, "caption"), Napi::Function::New(env, Caption));
|
||||||
exports.Set(Napi::String::New(env, "captionTwo"), Napi::Function::New(env, CaptionTwo));
|
exports.Set(Napi::String::New(env, "captionTwo"), Napi::Function::New(env, CaptionTwo));
|
||||||
exports.Set(Napi::String::New(env, "circle"), Napi::Function::New(env, Circle));
|
exports.Set(Napi::String::New(env, "circle"), Napi::Function::New(env, Circle));
|
||||||
|
|
Loading…
Reference in a new issue