Added quality option to jpeg, adjusted CMakeLists, more tweaks

This commit is contained in:
Essem 2022-01-20 22:52:29 -06:00
parent 76fe5b6aa6
commit 715ed3bb7b
No known key found for this signature in database
GPG key ID: 7D497397CC3A2A8C
5 changed files with 26 additions and 14 deletions

View file

@ -7,8 +7,10 @@ add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES} ${CMAKE_JS_SRC})
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node") set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node")
target_link_libraries(${PROJECT_NAME} ${CMAKE_JS_LIB}) target_link_libraries(${PROJECT_NAME} ${CMAKE_JS_LIB})
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17) target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
add_definitions(-DNAPI_CPP_EXCEPTIONS) set(CMAKE_CXX_FLAGS "-Wall -Wextra -Werror=format-security -Wno-cast-function-type -fexceptions -D_GLIBCXX_ASSERTIONS -fstack-clash-protection -pedantic -D_GLIBCXX_USE_CXX11_ABI=1")
add_definitions(-DNAPI_VERSION=3) set(CMAKE_CXX_FLAGS_DEBUG "-g")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
add_definitions(-DNAPI_VERSION=5)
execute_process(COMMAND node -p "require('node-addon-api').include" execute_process(COMMAND node -p "require('node-addon-api').include"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}

View file

@ -1,8 +1,16 @@
import ImageCommand from "../../classes/imageCommand.js"; import ImageCommand from "../../classes/imageCommand.js";
class JPEGCommand extends ImageCommand { class JPEGCommand extends ImageCommand {
static description = "Adds max JPEG compression to an image"; params() {
static aliases = ["needsmorejpeg", "jpegify", "magik2", "morejpeg", "jpg"]; const quality = parseInt(this.args[0]);
return {
quality: isNaN(quality) ? 1 : Math.max(1, Math.min(quality, 100))
};
}
static description = "Adds JPEG compression to an image";
static aliases = ["needsmorejpeg", "jpegify", "magik2", "morejpeg", "jpg", "quality"];
static arguments = ["{quality}"];
static noImage = "You need to provide an image to add more JPEG!"; static noImage = "You need to provide an image to add more JPEG!";
static command = "jpeg"; static command = "jpeg";

View file

@ -1,6 +1,6 @@
import ImageCommand from "../../classes/imageCommand.js"; import ImageCommand from "../../classes/imageCommand.js";
import { random } from "../../utils/misc.js"; import { random } from "../../utils/misc.js";
const names = ["esmBot", "me_irl", "dankmemes", "hmmm", "gaming", "wholesome", "chonkers", "memes", "funny", "pcmasterrace", "bellybros"]; const names = ["esmBot", "me_irl", "dankmemes", "hmmm", "gaming", "wholesome", "chonkers", "memes", "funny", "pcmasterrace", "thomastheplankengine"];
class RedditCommand extends ImageCommand { class RedditCommand extends ImageCommand {
params() { params() {

View file

@ -37,7 +37,7 @@ Napi::Value Caption(const Napi::CallbackInfo &info) {
Image caption_image(Geometry(query), Color("white")); Image caption_image(Geometry(query), Color("white"));
caption_image.fillColor("black"); caption_image.fillColor("black");
caption_image.alpha(true); caption_image.alpha(true);
caption_image.fontPointsize(width / 13); caption_image.fontPointsize((double)width / 13);
caption_image.textGravity(Magick::CenterGravity); caption_image.textGravity(Magick::CenterGravity);
caption_image.read("pango:<span font_family=\"" + caption_image.read("pango:<span font_family=\"" +
(font == "roboto" ? "Roboto Condensed" : font) + (font == "roboto" ? "Roboto Condensed" : font) +

View file

@ -13,6 +13,8 @@ Napi::Value Jpeg(const Napi::CallbackInfo &info) {
try { try {
Napi::Object obj = info[0].As<Napi::Object>(); Napi::Object obj = info[0].As<Napi::Object>();
Napi::Buffer<char> data = obj.Get("data").As<Napi::Buffer<char>>(); Napi::Buffer<char> data = obj.Get("data").As<Napi::Buffer<char>>();
int quality =
obj.Has("quality") ? obj.Get("quality").As<Napi::Number>().Int32Value() : 0;
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;
@ -36,7 +38,7 @@ Napi::Value Jpeg(const Napi::CallbackInfo &info) {
for (Image &image : coalesced) { for (Image &image : coalesced) {
Blob temp; Blob temp;
image.quality(1); image.quality(quality);
image.magick("JPEG"); image.magick("JPEG");
image.write(&temp); image.write(&temp);
Image newImage(temp); Image newImage(temp);