Added quality option to jpeg, adjusted CMakeLists, more tweaks
This commit is contained in:
parent
76fe5b6aa6
commit
715ed3bb7b
5 changed files with 26 additions and 14 deletions
|
@ -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
|
||||
)
|
||||
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})
|
||||
|
|
|
@ -1,11 +1,19 @@
|
|||
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";
|
||||
}
|
||||
|
||||
export default JPEGCommand;
|
||||
export default JPEGCommand;
|
||||
|
|
|
@ -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() {
|
||||
|
@ -16,4 +16,4 @@ class RedditCommand extends ImageCommand {
|
|||
static command = "reddit";
|
||||
}
|
||||
|
||||
export default RedditCommand;
|
||||
export default RedditCommand;
|
||||
|
|
|
@ -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) +
|
||||
|
|
|
@ -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);
|
||||
|
@ -75,4 +77,4 @@ Napi::Value Jpeg(const Napi::CallbackInfo &info) {
|
|||
} catch (...) {
|
||||
throw Napi::Error::New(env, "Unknown error");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue