Skip to content

Commit

Permalink
Added support to changing image format;
Browse files Browse the repository at this point in the history
  • Loading branch information
mkocus committed Oct 5, 2022
1 parent ef5dd59 commit 110e027
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lovelace-kindle-screensaver/config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Lovelace dashboard renderer",
"version": "1.1.8",
"version": "1.1.9",
"slug": "lovelace-dashboard-renderer",
"description": "Renders any lovelace dashboard to image and hosts it",
"url": "https://github.com/mkocus/hass-lovelace-kindle-screensaver/tree/master/lovelace-kindle-screensaver",
Expand Down
1 change: 1 addition & 0 deletions lovelace-kindle-screensaver/rootfs/app/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ module.exports = {
pages: getPagesConfig(),
port: process.env.PORT || 5000,
renderingTimeout: process.env.RENDERING_TIMEOUT || 10000,
imageFormat: process.env.IMAGE_FORMAT || "png",
language: process.env.LANGUAGE || "en",
debug: process.env.DEBUG === "true",
ignoreCertificateErrors:
Expand Down
5 changes: 3 additions & 2 deletions lovelace-kindle-screensaver/rootfs/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const batteryStore = {};
const lastModifiedTime = new Date(stat.mtime).toUTCString();

response.writeHead(200, {
"Content-Type": "image/png",
"Content-Type": `image/${config.imageFormat}`,
"Content-Length": Buffer.byteLength(data),
"Last-Modified": lastModifiedTime
});
Expand Down Expand Up @@ -170,7 +170,7 @@ async function renderAndConvertAsync(browser) {
console.log(`Rendering ${url} to image...`);
await renderUrlToImageAsync(browser, pageConfig, url, tempPath);

console.log(`Converting rendered screenshot of ${url} to requested parameters png...`);
console.log(`Converting rendered screenshot of ${url} to requested parameters ${config.imageFormat}...`);
await convertImageToKindleCompatiblePngAsync(
pageConfig,
tempPath,
Expand Down Expand Up @@ -310,6 +310,7 @@ function convertImageToKindleCompatiblePngAsync(
})
// .dither(pageConfig.dither)
.rotate("white", pageConfig.rotation)
.setFormat(config.imageFormat)
.type(pageConfig.colorMode)
.bitdepth(pageConfig.grayscaleDepth)
.quality(100)
Expand Down
2 changes: 1 addition & 1 deletion lovelace-kindle-screensaver/rootfs/app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lovelace-kindle-screensaver/rootfs/app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hass-lovelace-kindle-screensaver",
"version": "1.1.8",
"version": "1.1.9",
"description": "Renders any lovelace dashboard to image and hosts it",
"main": "index.js",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions lovelace-kindle-screensaver/rootfs/etc/services.d/node/run
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export RENDERING_TIMEOUT=$(bashio::config 'rendering_timeout')
export RENDERING_DELAY=$(bashio::config 'rendering_delay')
export RENDERING_SCREEN_HEIGHT=$(bashio::config 'rendering_screen_height')
export RENDERING_SCREEN_WIDTH=$(bashio::config 'rendering_screen_width')
export IMAGE_FORMAT=$(bashio::config 'image_format')
export GRAYSCALE_DEPTH=$(bashio::config 'grayscale_depth')
export ROTATION=$(bashio::config 'rotation')
export SCALING=$(bashio::config 'scaling')
Expand Down

0 comments on commit 110e027

Please sign in to comment.