Skip to content

Commit

Permalink
Merge pull request #135 from harry48225/contrast-and-saturation-adjust
Browse files Browse the repository at this point in the history
Contrast and saturation adjust
  • Loading branch information
sibbl authored Dec 27, 2024
2 parents a0111ca + d7ba1fa commit af1e72f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,8 @@ async function renderUrlToImageAsync(browser, pageConfig, url, path) {
x: 0,
y: 0,
...size
}
},
...(pageConfig.imageFormat=="jpeg") && {quality: 100}
});
} catch (e) {
console.error("Failed to render", e);
Expand All @@ -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)
Expand Down

0 comments on commit af1e72f

Please sign in to comment.