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

@ -1,19 +1,21 @@
cmake_minimum_required(VERSION 3.9)
cmake_policy(SET CMP0042 NEW)
project (image)
project(image)
include_directories(${CMAKE_JS_INC})
file(GLOB SOURCE_FILES "natives/*.cc" "natives/*.h")
add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES} ${CMAKE_JS_SRC})
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node")
target_link_libraries(${PROJECT_NAME} ${CMAKE_JS_LIB})
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
add_definitions(-DNAPI_CPP_EXCEPTIONS)
add_definitions(-DNAPI_VERSION=3)
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")
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"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE NODE_ADDON_API_DIR
)
)
string(REPLACE "\n" "" NODE_ADDON_API_DIR ${NODE_ADDON_API_DIR})
string(REPLACE "\"" "" NODE_ADDON_API_DIR ${NODE_ADDON_API_DIR})
target_include_directories(${PROJECT_NAME} PRIVATE ${NODE_ADDON_API_DIR})

View file

@ -1,8 +1,16 @@
import ImageCommand from "../../classes/imageCommand.js";
class JPEGCommand extends ImageCommand {
static description = "Adds max JPEG compression to an image";
static aliases = ["needsmorejpeg", "jpegify", "magik2", "morejpeg", "jpg"];
params() {
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 command = "jpeg";

View file

@ -1,6 +1,6 @@
import ImageCommand from "../../classes/imageCommand.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 {
params() {

View file

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

View file

@ -13,6 +13,8 @@ Napi::Value Jpeg(const Napi::CallbackInfo &info) {
try {
Napi::Object obj = info[0].As<Napi::Object>();
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();
int delay =
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) {
Blob temp;
image.quality(1);
image.quality(quality);
image.magick("JPEG");
image.write(&temp);
Image newImage(temp);