Open topic with navigation

# ImageUtils

## ImageUtils. ImageUtils

## new ImageUtils()

An ImageUtils class for image utilities, such as OCR, image comparisons, and image find operations.

# Methods

## compareImages(firstImage, secondImage, pixelToleranceopt, rgbToleranceopt) → {Promise.<boolean>}

Checks whether two images are a match, given the specified pixel and RGB tolerance values.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`firstImage` | string |  | A Base64 string representation of the expected image.
`secondImage` | string |  | A Base64 string representation of the image to compare to the expected image.
`pixelTolerance` | number | <optional> | The percentage of pixels that can differ between the two images, and still be considered a match. Default = 0.
`rgbTolerance` | number | <optional> | The percent by which the RGB values of the pixels in the two images can differ, and still be considered a match. Default = 0.

##### Returns:

a promise that is fulfilled with a boolean indicating if the images match.

Type
  Promise.<boolean>

## compareImagesWithMask(firstImage, secondImage, maskAreaImage, pixelToleranceopt, rgbToleranceopt) → {Promise.<boolean>}

Checks whether two images are a match, given the mask area image and specified pixel and RGB tolerance values.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`firstImage` | string |  | A Base64 string representation of the expected image.
`secondImage` | string |  | A Base64 string representation of the image to compare to the expected image.
`maskAreaImage` | string |  | A Base64 string representation of the mask area used for the comparison between the expected image and image to compare. This mask area is calculated based on the expected image and should have rectangle areas which specify which part of the image will be included or excluded from the comparison. The rectangle which should include the area in the comparison should be painted with white pixels. The rectangle which should exclude the area in the comparison should be painted with black pixels. If the full image is with white pixels means all the image will be included in the comparison. If the full image is with black pixels means all the image will be excluded in the comparison.
`pixelTolerance` | number | <optional> | The percentage of pixels that can differ between the two images, and still be considered a match. Default = 0.
`rgbTolerance` | number | <optional> | The percent by which the RGB values of the pixels in the two images can differ, and still be considered a match. Default = 0.

##### Returns:

a promise that is fulfilled with a boolean indicating if the images match.

Type
  Promise.<boolean>

## getImageLocations(sourceImage, imageToFind, similarityopt) → {Promise.<Array.<Object>>}

Returns the first 100 locations of an image inside the source image. If the number of images found exceeds 100 images, a GeneralReplayException is thrown.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`sourceImage` | string |  | A Base64 string representation of the source image to check.
`imageToFind` | string |  | A Base64 string representation of the image to locate within the sourceImage.
`similarity` | number | <optional> | The minimum similarity between the two images (as a percentage), above which the find is considered a match. Default = 100.

##### Returns:

a promise that is fulfilled with an array of objects representing the point where the image was located.

Type
  Promise.<Array.<Object>>

## getText(image, textAreaopt) → {Promise.<string>}

Returns all text within the supplied image.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`image` | string |  | A Base64 string representation of the image to use for the search.
`textArea` | Object | <optional> | An inner rectangle within the image.

##### Returns:

a promise that is fulfilled with all the visible text from the image.

Type
  Promise.<string>

## locateImage(sourceImage, imageToFind, similarityopt) → {Promise.<Object>}

Locates an image inside the provided source image.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`sourceImage` | string |  | A Base64 string representation of the source image to check.
`imageToFind` | string |  | A Base64 string representation of the image to locate within the sourceImage.
`similarity` | number | <optional> | The minimum similarity between the two images (as a percentage), above which the find is considered a match. Default = 100.

##### Returns:

a promise that is fulfilled with an object representing the point where the image was located, or null if it was not found.

Type
  Promise.<Object>

## locateText(image, textToFind, rectangleopt) → {Promise.<Object>}

Returns all rectangular areas within the supplied image that contain the specified text.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`image` | string |  | A Base64 string representation of the image to use for the search.
`textToFind` | string |  | The text to search for in the test object.
`rectangle` | Object | <optional> | An inner rectangle within the image.

##### Returns:

a promise that is fulfilled with rectangles array containing all rectangular areas containing the specified text within this image.

Type
  Promise.<Object>