Skip to content

The plugin could have the feature to create PNG-8 greyscaled pictures #618

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/browser/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import * as path from 'path';
import * as fs from 'fs';
import * as promClient from 'prom-client';
import * as Jimp from 'jimp';
import configure from "@jimp/custom";
import png from "@jimp/png";
import { Logger } from '../logger';
import { RenderingConfig } from '../config/rendering';
import { ImageRenderOptions, RenderOptions } from '../types';
Expand Down Expand Up @@ -415,6 +417,22 @@ export class Browser {
});
}

if (options.greyScaleImage && !isPDF) {
await this.performStep('greyScale', options.url, signal, async () => {
const jimp = configure({ types: [png] }, Jimp);
const greyScaled = `${options.filePath}_${Date.now()}_greyscaled.png`;

const file = await jimp.read(options.filePath);
await file
.greyscale()
.deflateStrategy(0)
.colorType(0)
.writeAsync(greyScaled);

fs.renameSync(greyScaled, options.filePath);
});
}

return { filePath: options.filePath };
}

Expand Down
1 change: 1 addition & 0 deletions src/service/http-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ export class HttpServer {
timezone: req.query.timezone,
encoding: req.query.encoding,
deviceScaleFactor: req.query.deviceScaleFactor,
greyScaleImage: req.query.greyScaleImage,
headers: headers,
};

Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ export interface ImageRenderOptions extends RenderOptions {
// Runtime options derived from the input
fullPageImage?: boolean;
scaleImage?: number;
greyScaleImage?: boolean;
}