Library for taking screenshots of a specific window and returning a buffer (for Windows).
npm i screenshot-buffer --save
capture(processName: string, options: ScreenshotOptions)
-
grayscale: boolean = false
- grayscale mode toggle -
bringToFront: boolean = true
- bring the window to the front before taking a screenshot -
mime: string = "image/png"
- mime type of the image (available fromMIME
enum export in Typescript)
import { capture } from 'screenshot-buffer';
import { writeFileSync } from 'fs';
(async () => {
try {
const { data, width, height } = await capture('notepad.exe', { bringToFront: true, grayscale: true });
// Write file directly
writeFileSync('grayscale-notepad.jpg', data);
} catch(e) {
console.error(e);
}
})();
const screenshot = require('screenshot-buffer');
const { writeFileSync } = require('fs');
(async () => {
try {
const { data, width, height } = await screenshot.capture('notepad.exe', { bringToFront: true, grayscale: true });
// Write file directly
writeFileSync('grayscale-notepad.png', data);
} catch(e) {
console.error(e);
}
})();
Only works on Windows.
... Are very welcome!