Skip to content

Commit e366db3

Browse files
authored
Merge pull request #136 from macmacs/add-bmp
Added "bmp" as configurable image output format
2 parents 1822d90 + 115ac7c commit e366db3

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ schema:
5757
ROTATION: "int?"
5858
SCALING: "float?"
5959
GRAYSCALE_DEPTH: "int?"
60-
IMAGE_FORMAT: "list(png|jpeg)?"
60+
IMAGE_FORMAT: "list(png|jpeg|bmp)?"
6161
COLOR_MODE: "list(GrayScale|TrueColor)?"
6262
REMOVE_GAMMA: "bool?"
6363
PREFERS_COLOR_SCHEME: "list(light|dark)?"

index.js

+17-13
Original file line numberDiff line numberDiff line change
@@ -277,14 +277,13 @@ async function renderUrlToImageAsync(browser, pageConfig, url, path) {
277277
}
278278
await page.screenshot({
279279
path,
280-
type: pageConfig.imageFormat,
280+
type: 'png', // Always use PNG for screenshot
281281
captureBeyondViewport: false,
282282
clip: {
283283
x: 0,
284284
y: 0,
285285
...size
286-
},
287-
...(pageConfig.imageFormat=="jpeg") && {quality: 100}
286+
}
288287
});
289288
} catch (e) {
290289
console.error("Failed to render", e);
@@ -301,7 +300,7 @@ function convertImageToKindleCompatiblePngAsync(
301300
outputPath
302301
) {
303302
return new Promise((resolve, reject) => {
304-
gm(inputPath)
303+
let gmInstance = gm(inputPath)
305304
.options({
306305
imageMagick: config.useImageMagick === true
307306
})
@@ -312,14 +311,19 @@ function convertImageToKindleCompatiblePngAsync(
312311
.rotate("white", pageConfig.rotation)
313312
.type(pageConfig.colorMode)
314313
.level(pageConfig.blackLevel, pageConfig.whiteLevel)
315-
.bitdepth(pageConfig.grayscaleDepth)
316-
.quality(100)
317-
.write(outputPath, (err) => {
318-
if (err) {
319-
reject(err);
320-
} else {
321-
resolve();
322-
}
323-
});
314+
.bitdepth(pageConfig.grayscaleDepth);
315+
316+
// For BMP format, we don't set quality since it's not applicable
317+
if (pageConfig.imageFormat !== 'bmp') {
318+
gmInstance = gmInstance.quality(100);
319+
}
320+
321+
gmInstance.write(outputPath, (err) => {
322+
if (err) {
323+
reject(err);
324+
} else {
325+
resolve();
326+
}
327+
});
324328
});
325329
}

0 commit comments

Comments
 (0)