Skip to content

Commit

Permalink
Merge pull request #136 from macmacs/add-bmp
Browse files Browse the repository at this point in the history
Added "bmp" as configurable image output format
  • Loading branch information
sibbl authored Jan 12, 2025
2 parents 1822d90 + 115ac7c commit e366db3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ schema:
ROTATION: "int?"
SCALING: "float?"
GRAYSCALE_DEPTH: "int?"
IMAGE_FORMAT: "list(png|jpeg)?"
IMAGE_FORMAT: "list(png|jpeg|bmp)?"
COLOR_MODE: "list(GrayScale|TrueColor)?"
REMOVE_GAMMA: "bool?"
PREFERS_COLOR_SCHEME: "list(light|dark)?"
Expand Down
30 changes: 17 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,13 @@ async function renderUrlToImageAsync(browser, pageConfig, url, path) {
}
await page.screenshot({
path,
type: pageConfig.imageFormat,
type: 'png', // Always use PNG for screenshot
captureBeyondViewport: false,
clip: {
x: 0,
y: 0,
...size
},
...(pageConfig.imageFormat=="jpeg") && {quality: 100}
}
});
} catch (e) {
console.error("Failed to render", e);
Expand All @@ -301,7 +300,7 @@ function convertImageToKindleCompatiblePngAsync(
outputPath
) {
return new Promise((resolve, reject) => {
gm(inputPath)
let gmInstance = gm(inputPath)
.options({
imageMagick: config.useImageMagick === true
})
Expand All @@ -312,14 +311,19 @@ function convertImageToKindleCompatiblePngAsync(
.rotate("white", pageConfig.rotation)
.type(pageConfig.colorMode)
.level(pageConfig.blackLevel, pageConfig.whiteLevel)
.bitdepth(pageConfig.grayscaleDepth)
.quality(100)
.write(outputPath, (err) => {
if (err) {
reject(err);
} else {
resolve();
}
});
.bitdepth(pageConfig.grayscaleDepth);

// For BMP format, we don't set quality since it's not applicable
if (pageConfig.imageFormat !== 'bmp') {
gmInstance = gmInstance.quality(100);
}

gmInstance.write(outputPath, (err) => {
if (err) {
reject(err);
} else {
resolve();
}
});
});
}

0 comments on commit e366db3

Please sign in to comment.