API reference

Data Types

Image

nut.js enables you to search for images on your screen.

To represent image data, nut.js provides the Image datatype.

Image Properties


An Image holds all the data required to perform on-screen search.

That is:

  • the image width
  • the image height
  • a buffer storing raw image data
  • the amount of color channels
  • an id

ColorMode

Additionally, it also stores information about the order of color channels. By default, nut.js images are stored using the BGR color mode. This mode was chosen to align with a well known computer vision library.

However, since not every image processing library expects image data in BGR ordering, nut.js images provide methods to convert between BGR and RGB mode.

const bgrImage = new Image(...);

const rgbImage = bgrImage.toRGB();
const rgbImage = new Image(..., ColorMode.RGB);

const bgrImage = rgbImage.toBGR();

Region

When searching for images on your screen, nut.js uses the Region datatype to represent a 2D area on your screen.

A Region holds a left, top, width and height property to represent its size and location, as well as an area() method that calculates the area occupied by a particular Region.

Sample

const r = new Region(10, 100, 400, 300);

console.log(r);

const regionArea = r.area();

Point

When navigating your screen, nut.js relies on the Point datatype to represent points in 2D space.

A Point is a simple data structure holding an x and y coordinate.

Sample

const p = new Point(10, 100);

console.log(p);

RGBA

The RGBA class is used to represent RGBA color information. It is returned from screen.colorAt and can be used to search for pixels of a certain color on screen via screen.find with a pixelWithColor query.

Sample

const colorToSearch = new RGBA(255, 0, 255, 255);

const colorLocation = await screen.find(pixelWithColor(colorToSearch));
Previous
Plugins