Open Source JavaScript API to Compare Images

JavaScript Library enables Software programmers to compare two images in multiple environments like Node or browsers etc.

Sometimes it is required to compare two images to see how similar they are. It is a very complicated process and required good knowledge to accomplish it. The open source pixelmatch library can be a very useful choice for comparing two images in any environment.  As the library has no dependencies and works on raw typed arrays of image data, so can be used in multiple environments like Node or browsers, etc.

The pixelmatch is very small in size and very simple to use but is a very fast pixel-level image comparison library. It is written in JavaScript and initially created to compare screenshots in tests. The library supports features like anti-aliased pixels detection and perceptual color difference metrics.

The Anti-aliasing detection is a very useful feature because usually it has been observed that rendering the same data on different applications, devices, or operating systems can generate slightly dissimilar results. But mostly it is recommended to ignore these small differences or tests to capture more meaningful data.

Previous Next

Getting Started with pixelmatch

The recommended way to install pixelmatch is via NPM. Please use the following command to install it.

Install pixelmatch via NPM

 npm install pixelmatch 

What is Pixel Match Testing?

If you need to compare two images to check if there is any difference between then you can use pixel match testing for this purpose. There can be two types of images, the original image, and the modified image. You can use an application that can fetch images from the screenshot of your app and after that, the image comparison library can be used to compare these images and display the results.

Comparing Images via JavaScript Library

The open source library pixelmatch has provided complete functionality for comparing images inside JavaScript application with ease.  Software developers need to provide images data for comparing as well as the output place where it needs to write the image data with the differences. They also need to provide the dimension which is the width and height of the three images. You can use the threshold option that allows the images to be slightly different, which can be great in some cases. Please note that pixelmatch library needs that image must be of the same sizes.