diff --git a/.gitignore b/.gitignore index db19d58..06b2fb9 100644 --- a/.gitignore +++ b/.gitignore @@ -38,4 +38,5 @@ todo.txt .vscode/ migratedb.js processed.txt -data.sqlite \ No newline at end of file +data.sqlite +.cache diff --git a/commands/image-editing/blurple.js b/commands/image-editing/blurple.js index 6dcef80..51bbd0b 100644 --- a/commands/image-editing/blurple.js +++ b/commands/image-editing/blurple.js @@ -3,7 +3,8 @@ import ImageCommand from "../../classes/imageCommand.js"; class BlurpleCommand extends ImageCommand { params() { return { - old: !!this.specialArgs.old + old: !!this.specialArgs.old, + color: "blurple" }; } @@ -14,8 +15,8 @@ class BlurpleCommand extends ImageCommand { }]; static noImage = "You need to provide an image to make blurple!"; - static command = "blurple"; + static command = "colors"; static aliases = ["blurp"]; } -export default BlurpleCommand; \ No newline at end of file +export default BlurpleCommand; diff --git a/commands/image-editing/grayscale.js b/commands/image-editing/grayscale.js new file mode 100644 index 0000000..1cce7d4 --- /dev/null +++ b/commands/image-editing/grayscale.js @@ -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; diff --git a/commands/image-editing/sepia.js b/commands/image-editing/sepia.js new file mode 100644 index 0000000..c515f14 --- /dev/null +++ b/commands/image-editing/sepia.js @@ -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; diff --git a/natives/blurple.h b/natives/blurple.h deleted file mode 100644 index bdc9964..0000000 --- a/natives/blurple.h +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once - -#include - -Napi::Value Blurple(const Napi::CallbackInfo& info); diff --git a/natives/blurple.cc b/natives/colors.cc similarity index 70% rename from natives/blurple.cc rename to natives/colors.cc index 4faab58..d1bd312 100644 --- a/natives/blurple.cc +++ b/natives/colors.cc @@ -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 data = obj.Get("data").As>(); bool old = obj.Has("old") ? obj.Get("old").As().Value() : false; + string color = obj.Get("color").As().Utf8Value(); string type = obj.Get("type").As().Utf8Value(); int delay = obj.Has("delay") ? obj.Get("delay").As().Int32Value() : 0; @@ -23,7 +24,7 @@ Napi::Value Blurple(const Napi::CallbackInfo &info) { list frames; list coalesced; - list blurpled; + list 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::Copy(env, (char *)blob.data(), @@ -62,4 +70,4 @@ Napi::Value Blurple(const Napi::CallbackInfo &info) { } catch (...) { throw Napi::Error::New(env, "Unknown error"); } -} \ No newline at end of file +} diff --git a/natives/colors.h b/natives/colors.h new file mode 100644 index 0000000..ef78bcf --- /dev/null +++ b/natives/colors.h @@ -0,0 +1,5 @@ +#pragma once + +#include + +Napi::Value Colors(const Napi::CallbackInfo& info); diff --git a/natives/image.cc b/natives/image.cc index 580d073..6516fd8 100644 --- a/natives/image.cc +++ b/natives/image.cc @@ -1,7 +1,7 @@ #include #include #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));