qa-image-comparison
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

QA Image Comparison

QA Image Comparison is a library for comparing images, designed for quality assurance purposes. It leverages the Jimp library to provide utilities for comparing images provided as base64 strings, from file paths, or directly using Jimp objects.

Node.js Package

Installation

You can install the library via npm:

npm install qa-image-comparison

Usage

Initialization

import { CompareImages } from 'qa-image-comparison';

const comparer = new CompareImages();

Comparing Images from Base64 Strings

const image1Base64 = '...'; // Base64 string of the first image
const image2Base64 = '...'; // Base64 string of the second image

const result = await comparer.CompareImagesByBase64String(image1Base64, image2Base64);
console.log('Images match:', result);

Comparing Images from Disk

const imagePath1 = 'path/to/image1.jpg';
const imagePath2 = 'path/to/image2.jpg';

const result = await comparer.CompareImagesFromDisk(imagePath1, imagePath2);
console.log('Images match:', result);

Comparing Jimp Images Directly

import Jimp from 'jimp';

const image1 = await Jimp.read('path/to/image1.jpg');
const image2 = await Jimp.read('path/to/image2.jpg');

const result = await comparer.CompareJimpImages(image1, image2);
console.log('Images match:', result);

API Reference

CompareImages Class

CompareImagesByBase64String(imageExpectedString: string, imageActualString: string): Promise

Compares two images provided as base64 strings.

imageExpectedString: Base64 string of the expected image. imageActualString: Base64 string of the actual image to be compared.

Returns a Promise resolving to true if images match, false otherwise.

CompareImagesFromDisk(imageExpectedPath: string, imageActualPath: string): Promise

Compares images from file paths.

imageExpectedPath: Path to the expected image file. imageActualPath: Path to the actual image file to be compared.

Returns a Promise resolving to true if images match, false otherwise.

CompareJimpImages(imageExpected: Jimp, imageActual: Jimp): Promise

Compares two Jimp images directly.

imageExpected: The expected Jimp image. imageActual: The actual Jimp image to be compared.

Returns true if images match, false otherwise.

License

This library is licensed under the Apache-2.0 license.

Version

Current version: 1.0.3

Author

Radoslav Radoslavov

Package Sidebar

Install

npm i qa-image-comparison

Weekly Downloads

1

Version

1.0.5

License

Apache-2.0 license

Unpacked Size

15.1 kB

Total Files

3

Last publish

Collaborators

  • radobg