Class: Image

Image


new Image(srcPath [, srcOpts] [, injects])

Creates new instance of Image.

Parameters:
Name Type Argument Description
srcPath string

path to processed image

srcOpts object <optional>

image options

Properties
Name Type Argument Default Description
scaleX number <optional>
1

image current scale value on X axis

scaleY number <optional>
1

image current scale value on Y axis

injects object <optional>

Dependency injections.

Properties
Name Type Argument Description
sharp object <optional>

Injected sharp module.

Source:

Methods


<protected> _cropPixels(pixels)

Crops pixels, removes empty rows and columns.

Parameters:
Name Type Description
pixels Array.<Array.<object>>

pixels matrix

Source:
Returns:
  • cropped pixels matrix
Type
Array.<Array.<object>>

<protected> _cropTop(pixels)

Crops top part of pixels matrix.

Parameters:
Name Type Description
pixels Array.<Array.<object>>

pixels matrix

Source:
Returns:
  • cropped pixels matrix
Type
Array.<Array.<object>>

<protected> _getDiffValue(srcPixels, dstPixels, offsetX, offsetY)

Calculates difference between source pixels and destination pixels.

Parameters:
Name Type Description
srcPixels Array.<Array.<object>>

source pixels matrix

dstPixels Array.<Array.<object>>

destination pixels matrix

offsetX number

source left border offset

offsetY number

source top border offset

Source:
Returns:
  • difference value
Type
number

<protected> _getPixels(img)

Retrieves pixels from image data.

Parameters:
Name Type Description
img object

image data

Source:
Returns:
  • pixels matrix
Type
Array.<Array.<object>>

<protected> _getUsedPixels(pixels)

Gets used pixels.

Parameters:
Name Type Description
pixels Array.<Array.<object>>

pixels matrix

Source:
Returns:

List of used pixels.

Type
Array.<object>

<protected> _includes(src, dst)

Defines whether one image data includes another.

Parameters:
Name Type Description
src object

source image data

dst object

destination image data, which is potentially included

Source:
Returns:
  • result
Type
object

<protected> _isPixelTolerant(srcPixel, dstPixel)

Defines whether source pixel is tolerant to destination pixel.

Parameters:
Name Type Description
srcPixel object

source pixel

dstPixel object

destination pixel

Source:
Returns:
  • true if pixels are tolerant, false otherwise
Type
boolean

<protected> _isPixelUsed(pixel)

Defines whether pixel should be used for difference calculation or no, according its alpha value.

Parameters:
Name Type Description
pixel object

pixel

Source:
Returns:
  • true if should be, false otherwise
Type
boolean

<async, protected> _loadImg(imgPath, imgOpts)

Loads image.

Parameters:
Name Type Description
imgPath string

path loaded image

imgOpts object

image options

Source:
Returns:
  • image data
Type
Promise.<object>

<async, protected> _saveMatchImage(left, top, width, height)

Saves matched part of image.

Parameters:
Name Type Description
left number

offset from left image border

top number

offset from top image border

width number

width of matched part

height number

height of matched part

Source:
Returns:
Type
Promise.<void>

_transpose(pixels)

Transposes pixels matrix.

Parameters:
Name Type Description
pixels Array.<Array.<object>>

pixels matrix

Source:
Returns:

transposed pixels matrix

Type
Array.<Array.<object>>

equalTo(dstPath [, dstOpts])

Defines if processed image equal to specified image.

Parameters:
Name Type Argument Description
dstPath string

path to potentially equal image

dstOpts object <optional>

included image options

Properties
Name Type Argument Default Description
tolerance number <optional>
0.05

comparison tolerance

diffPath string <optional>
<nullable>
null

path to save captured difference.

saveDiff boolean <optional>
false

flag to capture images intersection or no

Source:
Returns:

Ratio of difference.

Type
Promise.<number>

includes(dstPath [, dstOpts])

Defines if processed image includes specified image.

Parameters:
Name Type Argument Description
dstPath string

path to potentially included image

dstOpts object <optional>

included image options

Properties
Name Type Argument Default Description
tolerance number <optional>
0.05

comparison tolerance

matchedPath string <optional>
<nullable>
null

path to same captured place

saveMatch boolean <optional>
false

flag to capture images intersection or no

Source:
Returns:
  • result
Type
Promise.<object>

<async> isBlack()

Defines whether processed image is black.

Source:
Returns:
  • true if image is black, false otherwise.
Type
Promise.<boolean>

<async> isMonochrome()

Defines whether processed image is monochrome.

Source:
Returns:
  • true if image is monochrome, false otherwise.
Type
Promise.<boolean>

<async> isTransparent()

Defines whether processed image is transparent.

Source:
Returns:
  • true if image is transparent, false otherwise.
Type
Promise.<boolean>

<async> isWhite()

Defines whether processed image is white.

Source:
Returns:
  • true if image is white, false otherwise.
Type
Promise.<boolean>