Very small, Very fast, cross-platform library, to create a screenshot screenjs supports Mac, Windows, and Linux(X11).
For one project, I needed to make screenshots very quickly, and save them in an array of numbers (intmap), also it was necessary to sometimes save screenshots to the PNG file ...
MinGW or other GCC
Xcode Command Line Tools
sudo apt-get install gcc libc6-dev
sudo apt-get install libx11-dev
sudo apt-get install xorg-dev
npm install screenjs --save
or npm install -g screenjs --save
(from global)
const Screen = require('screenjs').Screen; // The object responsible for the screenshots
const Bitmap = require('screenjs').Bitmap; // Additional functionality, saving to file, or base64, etc.
Screen.getSize();
// Will return { width: 1366, height: 768 };
Screen.Capture();
/* Will return
{ width: 1366,
height: 768,
byteWidth: 5464,
bitsPerPixel: 32,
bytesPerPixel: 4,
image: <Buffer ... >,
intmap: Uint32Array [...] };
*/
Screen.Capture(x, y, width, height);
// Screen.Capture(10, 15, 100, 100);
/* Will return
{ width: 100,
height: 100,
byteWidth: 400,
bitsPerPixel: 32,
bytesPerPixel: 4,
image: <Buffer ... >,
intmap: Uint32Array [...] };
*/
Screen.CaptureGetIntMap();
/* Will return
{ width: 1366,
height: 768,
byteWidth: 5464,
bitsPerPixel: 32,
bytesPerPixel: 4,
intmap: Uint32Array [...] };
*/
Screen.CaptureGetIntMap(x, y, width, height);
// Screen.CaptureGetIntMap(10, 15, 100, 100);
/* Will return
{ width: 100,
height: 100,
byteWidth: 400,
bitsPerPixel: 32,
bytesPerPixel: 4,
intmap: Uint32Array [...] };
*/
Screen.CaptureGetImage();
/* Will return
{ width: 1366,
height: 768,
byteWidth: 5464,
bitsPerPixel: 32,
bytesPerPixel: 4,
image: <Buffer ... > };
*/
Screen.CaptureGetImage(x, y, width, height);
// Screen.CaptureGetImage(10, 15, 100, 100);
/* Will return
{ width: 100,
height: 100,
byteWidth: 400,
bitsPerPixel: 32,
bytesPerPixel: 4,
image: <Buffer ... > };
*/
Bitmap(img);
// return js bitmap object
Bitmap.rgbaToInt(red, green, blue, alpha);
// return number
Bitmap.intToRGBA(num);
// return rgba object
Bitmap.getBuffer();
// return buffer PNG image
Bitmap.getBase64();
// return base64 string (data:image/png;base64,...etc.)
Bitmap.write(pathFile, callback);
// save from file Async
Bitmap.writeSync(pathFile);
// save from file Sync
const Screen = require('screenjs').Screen;
const Bitmap = require('screenjs').Bitmap;
const pic = Screen.Capture(); // It will work very quickly
console.log(pic); // And this will work slowly
const image = Bitmap(pic); // It will work very quickly
console.log(image); // And this will work slowly
const Screen = require('screenjs').Screen;
const Bitmap = require('screenjs').Bitmap;
const pic = Screen.CaptureGetImage(); // It will work very quickly
const image = Bitmap(pic); // It will work very quickly
image.writeSync('test.png'); //And this will work very slowly
const Screen = require('screenjs').Screen;
const pic = Screen.CaptureGetIntMap(); // It will work very quickly
console.log(image.intmap.length); //It will work very quickly
MIT