1.0.3 • Published 8 years ago
screenjs v1.0.3
screenjs
Very small, Very fast, cross-platform library, to create a screenshot screenjs supports Mac, Windows, and Linux(X11).
What is created for?
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 ...
Contents
Installation:
For Windows:
MinGW or other GCCFor Mac OS X:
Xcode Command Line ToolsFor Ubuntu:
sudo apt-get install gcc libc6-dev
sudo apt-get install libx11-dev
sudo apt-get install xorg-devAfter all this:
npm install screenjs --save or npm install -g screenjs --save (from global)
API:
Import:
const Screen = require('screenjs').Screen; // The object responsible for the screenshots
const Bitmap = require('screenjs').Bitmap; // Additional functionality, saving to file, or base64, etc.Methods:
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 objectBitmap.rgbaToInt(red, green, blue, alpha);
// return numberBitmap.intToRGBA(num);
// return rgba objectBitmap.getBuffer();
// return buffer PNG imageBitmap.getBase64();
// return base64 string (data:image/png;base64,...etc.)Bitmap.write(pathFile, callback);
// save from file AsyncBitmap.writeSync(pathFile);
// save from file SyncExamples:
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 slowlyconst 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 slowlyconst Screen = require('screenjs').Screen;
const pic = Screen.CaptureGetIntMap(); // It will work very quickly
console.log(image.intmap.length); //It will work very quicklyLicense:
MIT