From af6e15419bf2ce6c78f66935292bc1e8f67abab7 Mon Sep 17 00:00:00 2001 From: Harry Best Date: Mon, 23 Dec 2024 13:23:50 +0000 Subject: [PATCH 1/3] Add image controls including saturation and contrast --- README.md | 4 ++++ config.js | 2 ++ index.js | 7 +++++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6f85d60..3423531 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,10 @@ Home Assistant related stuff: | `IMAGE_FORMAT` | `png` | no | no | Format for the generated images. Acceptable values are `png` or `jpeg`. | | `DITHER` | `false` | no | yes | Apply a dither to the images. | | `REMOVE_GAMMA` | `true` | no | no | Remove gamma correction from image. Computer images are normally gamma corrected since monitors expect gamma corrected data, however some E-Ink displays expect images not to have gamma correction. | +| SATURATION | 2 | no | no | Saturation level multiplier, e.g. 2 doubles the saturation | +| CONTRAST | 2 | no | no | Contrast level multiplier, e.g. 2 doubles the contrast | +| BLACK_LEVEL | 30% | no | no | Black point as percentage of MaxRGB, i.e. crushes blacks below specified level | +| WHITE_LEVEL | 90% | no | no | White point as percentage of MaxRGB, i.e. crushes whites above specified level | **\* Array** means that you can set `HA_SCREENSHOT_URL_2`, `HA_SCREENSHOT_URL_3`, ... `HA_SCREENSHOT_URL_n` to render multiple pages within the same instance. If you use `HA_SCREENSHOT_URL_2`, you can also set `ROTATION_2=180`. If there is no `ROTATION_n` set, then `ROTATION` will be used as a fallback. diff --git a/config.js b/config.js index a0f2364..d94b9c8 100644 --- a/config.js +++ b/config.js @@ -35,6 +35,8 @@ function getPagesConfig() { rotation: getEnvironmentVariable("ROTATION", suffix) || 0, scaling: getEnvironmentVariable("SCALING", suffix) || 1, batteryWebHook: getEnvironmentVariable("HA_BATTERY_WEBHOOK", suffix) || null, + saturation: getEnvironmentVariable("SATURATION", suffix) || 1, + contrast: getEnvironmentVariable("CONTRAST", suffix) || 1, }); } return pages; diff --git a/index.js b/index.js index c94d9de..9ac15c7 100644 --- a/index.js +++ b/index.js @@ -283,7 +283,8 @@ async function renderUrlToImageAsync(browser, pageConfig, url, path) { x: 0, y: 0, ...size - } + }, + quality: 100 }); } catch (e) { console.error("Failed to render", e); @@ -304,7 +305,9 @@ function convertImageToKindleCompatiblePngAsync( .options({ imageMagick: config.useImageMagick === true }) - .gamma(pageConfig.removeGamma ? 1.0/2.2 : 1.0) + .gamma(pageConfig.removeGamma ? 1.0 / 2.2 : 1.0) + .modulate(100, 100 * pageConfig.saturation) + .contrast(pageConfig.contrast) .dither(pageConfig.dither) .rotate("white", pageConfig.rotation) .type(pageConfig.colorMode) From 836cd8757845073aca9890cd07d58aff5a6631db Mon Sep 17 00:00:00 2001 From: Harry Best Date: Mon, 23 Dec 2024 13:51:32 +0000 Subject: [PATCH 2/3] Add new variables to home assistant config --- config.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/config.yaml b/config.yaml index 3f888cd..46978a0 100644 --- a/config.yaml +++ b/config.yaml @@ -40,6 +40,8 @@ options: REMOVE_GAMMA: true PREFERS_COLOR_SCHEME: 'light' HA_BATTERY_WEBHOOK: '' + SATURATION: 1 + CONTRAST: 1 ADDITIONAL_ENV_VARS: [] schema: HA_BASE_URL: "url" @@ -60,6 +62,8 @@ schema: REMOVE_GAMMA: "bool?" PREFERS_COLOR_SCHEME: "list(light|dark)?" HA_BATTERY_WEBHOOK: "str?" + SATURATION: "int?" + CONTRAST: "int?" ADDITIONAL_ENV_VARS: - name: match(^[A-Z0-9_]+$) value: str From d7ba1faa09d89dfb2bf8de55aeb6d36f60da7c45 Mon Sep 17 00:00:00 2001 From: Harry Best Date: Mon, 23 Dec 2024 13:58:32 +0000 Subject: [PATCH 3/3] Only apply quality setting to screenshot if jpeg --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 9ac15c7..525667d 100644 --- a/index.js +++ b/index.js @@ -284,7 +284,7 @@ async function renderUrlToImageAsync(browser, pageConfig, url, path) { y: 0, ...size }, - quality: 100 + ...(pageConfig.imageFormat=="jpeg") && {quality: 100} }); } catch (e) { console.error("Failed to render", e);