• Stars
    star
    665
  • Rank 67,810 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 10 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Node.js library for comparing images

LooksSame

Build Status

Node.js library for comparing images, taking into account human color perception. It is created specially for the needs of visual regression testing for hermione utility, but can be used for other purposes.

Supported image formats

JPEG, PNG, WebP, GIF, AVIF, TIFF and SVG images are supported.

Note: If you want to compare jpeg files, you may encounter random differences due to the jpeg structure if they are not lossless jpeg files.

Comparing images

const looksSame = require('looks-same');

// equal will be true, if images looks the same
const {equal} = await looksSame('image1.png', 'image2.png');

Parameters can be paths to files or buffer with compressed image.

By default, it will detect only noticeable differences. If you wish to detect any difference, use strict options:

const {equal} = await looksSame('image1.png', 'image2.png', {strict: true});

You can also adjust the ΔE value that will be treated as error in non-strict mode:

const {equal} = await looksSame('image1.png', 'image2.png', {tolerance: 5});

Default tolerance in non-strict mode is 2.3 which is enough for the most cases. Setting tolerance to 0 will produce the same result as strict: true, but strict mode is faster. Attempt to set tolerance in strict mode will produce an error.

Some devices can have different proportion between physical and logical screen resolutions also known as pixel ratio. Default value for this proportion is 1. This param also affects the comparison result, so it can be set manually with pixelRatio option.

const {equal} = await looksSame('image1.png', 'image2.png', {pixelRatio: 2});

Comparing images with ignoring caret

Text caret in text input elements it is a pain for visual regression tasks, because it is always blinks. These diffs will be ignored by default. You can use ignoreCaret option with false value to disable ignoring such diffs. In that way text caret will be marked as diffs.

const {equal} = await looksSame('image1.png', 'image2.png', {ignoreCaret: true});

Both strict and ignoreCaret can be set independently of one another.

Comparing images with ignoring antialiasing

Some images has difference while comparing because of antialiasing. These diffs will be ignored by default. You can use ignoreAntialiasing option with false value to disable ignoring such diffs. In that way antialiased pixels will be marked as diffs. Read more about anti-aliasing algorithm.

const {equal} = await looksSame('image1.png', 'image2.png', {ignoreAntialiasing: true});

Sometimes the antialiasing algorithm can work incorrectly due to some features of the browser rendering engine. Use the option antialiasingTolerance to make the algorithm less strict. With this option you can specify the minimum difference in brightness (zero by default) between the darkest/lightest pixel (which is adjacent to the antialiasing pixel) and theirs adjacent pixels.

We recommend that you don't increase this value above 10. If you need to increase more than 10 then this is definitely not antialiasing.

Example:

const {equal} = await looksSame('image1.png', 'image2.png', {ignoreAntialiasing: true, antialiasingTolerance: 3});

Getting diff bounds

Looksame returns information about diff bounds. It returns only first pixel if you passed stopOnFirstFail option with true value. The whole diff area would be returned if stopOnFirstFail option is not passed or it's passed with false value.

Getting diff clusters

Looksame returns diff bounds divided into clusters if option shouldCluster passed with true value. Moreover you can pass clusters size using clustersSize option.

// {
//     equal: false,
//     diffBounds: {left: 10, top: 10, right: 20, bottom: 20}
//     diffClusters: [
//         {left: 10, top: 10, right: 14, bottom: 14},
//         {left: 16, top: 16, right: 20, bottom: 20}
//     ]
// }
const {equal, diffBounds, diffClusters} = await looksSame('image1.png', 'image2.png', {shouldCluster: true, clustersSize: 10});

Building diff image

await looksSame.createDiff({
    reference: '/path/to/reference/image.png',
    current: '/path/to/current/image.png',
    diff: '/path/to/save/diff/to.png',
    highlightColor: '#ff00ff', // color to highlight the differences
    strict: false, // strict comparsion
    tolerance: 2.5,
    antialiasingTolerance: 0,
    ignoreAntialiasing: true, // ignore antialising by default
    ignoreCaret: true // ignore caret by default
});

Building diff image as a Buffer

If you don't want the diff image to be written on disk, then simply don't pass any diff: path to the createDiff method. The method will then resolve a Buffer containing the diff. You can also specify buffer format with extension key. Default extension is png. List of supported formats: heic, heif, avif, jpeg, jpg, png, raw, tiff, tif, webp, gif, jp2, jpx, j2k, j2c

const buffer = await looksSame.createDiff({
    // exactly same options as above, but with optional extension and without diff
    extension: 'png'
});

Comparing colors

If you just need to compare two colors you can use colors function:

const equal = looksSame.colors(
    {R: 255, G: 0, B: 0},
    {R: 254, G: 1, B: 1},
    {tolerance: 2.5}
);

More Repositories

1

gemini

💀💀💀[DEPRECATED] Use hermione
JavaScript
1,497
star
2

testplane

Testplane (ex-hermione) browser test runner based on mocha and wdio
JavaScript
713
star
3

gemini-gui

GUI for gemini
JavaScript
69
star
4

html-reporter

Html reporter for Testplane (ex-hermione)
JavaScript
45
star
5

png-img

Lite libpng wrapper for node.js
JavaScript
29
star
6

ssh-tun

Establishes ssh tunnel for forwarding remote port to local one.
JavaScript
8
star
7

testplane-storybook

Storybook addon that makes it easy to write Testplane tests and speed up their execution time
TypeScript
6
star
8

testplane-passive-browsers

💀💀💀[DEPRECATED]💀💀💀 use option "passive" from [email protected] instead
JavaScript
4
star
9

testplane-retry-progressive

Testplane plugin to retry tests with error patterns
JavaScript
4
star
10

gemini-teamcity

Plugin for Gemini which enables reporting test results to TeamCity.
JavaScript
4
star
11

testplane-headless-chrome

Plugin for Testplane to run integration tests on downloaded headless Chromium.
JavaScript
4
star
12

testplane-safari-commands

Testplane plugin to add/wrap browser commands for iOS Safari
JavaScript
3
star
13

gemini-tunnel

DEPRECATED use https://github.com/gemini-testing/ssh-tunneler
JavaScript
3
star
14

hermione-allure-reporter

💀💀💀[DEPRECATED]💀💀💀 use this plugin instead –
JavaScript
3
star
15

stat-reporter

Testplane plugin which helps to collect test statistic by browsers
JavaScript
3
star
16

hermione-wdio-migrator

Testplane plugin to easily migrate from wdio@4 to wdio@7 without any changes
JavaScript
3
star
17

testplane-retry-command

Testplane plugin to retry commands at low level
JavaScript
3
star
18

create-testplane

A tool for fast and simple Testplane configuration
TypeScript
3
star
19

configparser

Parser for configurations
JavaScript
2
star
20

testplane-test-filter

Testplane plugin to filter tests specified in JSON-file.
JavaScript
2
star
21

gemini-core

[DEPRECATED] Utility which contains common modules for gemini and hermione.
JavaScript
2
star
22

json-reporter

Common json reporter for testplane and hermione
JavaScript
2
star
23

testplane-url-decorator

Tesplane plugin for url decorator
JavaScript
2
star
24

playwright-utils

Custom playwright utilities
TypeScript
2
star
25

plugins-loader

Plugins loader for gemini and hermione
JavaScript
1
star
26

vscode-testplane

Testplane Integration with VS Code
TypeScript
1
star
27

testplane-image-minifier

Testplane plugin for minification reference images
JavaScript
1
star
28

hermione-profiler

hermione profiler
JavaScript
1
star
29

testplane-oauth

Testplane plugin for authorization with OAuth
TypeScript
1
star
30

gemini-faildump

Plugin to collect information about test fails.
JavaScript
1
star
31

hermione-faildump

Testplane plugin to collect information about test fails
JavaScript
1
star
32

hermione-sauce-connect

JavaScript
1
star
33

hermione-tunnel

DEPRECATED use https://github.com/gemini-testing/ssh-tunneler
JavaScript
1
star
34

gemini-testing.github.io

https://gemini-testing.github.io
CSS
1
star
35

gemini-optipng

Plugin for Gemini which optimize reference images.
JavaScript
1
star
36

qemitter

EventEmitter, allowing to return promise from handlers
JavaScript
1
star
37

ssh-tunneler

Plugin for gemini and hermione to set up ssh tunnel while running tests
JavaScript
1
star
38

hermione-sequential-tests-run

Testplane plugin to run selected tests in sequence
JavaScript
1
star
39

testplane-retry-limiter

Testplane plugin to disable retries at runtime
JavaScript
1
star
40

hermione-teamcity-reporter

Testplane plugin to report results for TeamCity CI
JavaScript
1
star
41

hermione-hide-scrollbars

Plugin for hermione to hide scrollbars in browsers
JavaScript
1
star
42

console-notifier

Plugin for gemini and hermione to log some information to a console after tests finished
JavaScript
1
star