explaingit

rsmbl/resemble.js

4,608JavaScriptAudience · developerComplexity · 2/5LicenseSetup · easy

TLDR

JavaScript library that compares two images pixel by pixel and highlights the differences, most commonly used for automated visual regression testing in web apps.

Mindmap

mindmap
  root((repo))
    What it does
      Compare two images
      Measure pixel diff
      Highlight differences
    Comparison modes
      Ignore colors
      Ignore anti-aliasing
      Region-limited compare
    Output
      Diff percentage
      Highlighted diff image
    Platforms
      Browser canvas
      Node.js server
    Use cases
      Visual regression tests
      UI screenshot checks
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Compare screenshots before and after a code change to catch visual regressions automatically

USE CASE 2

Highlight exactly which pixels changed between two versions of a web page

USE CASE 3

Ignore anti-aliasing artifacts when comparing rendered UI screenshots to avoid false failures

USE CASE 4

Limit the comparison to a specific rectangular area of an image during visual tests

Tech stack

JavaScriptNode.jsHTML5 Canvas

Getting it running

Difficulty · easy Time to first run · 5min

node-canvas is a pre-built binary that can fail in some environments, check the README troubleshooting section if the install does not work.

Free to use in any project, including commercial ones, as long as you keep the copyright notice.

In plain English

Resemble.js is a JavaScript library for comparing two images and measuring the differences between them. You point it at two image files, and it produces a report showing what percentage of pixels differ, along with an output image where the differing areas are highlighted in a configurable color. The most common use case is automated visual testing, where you want to confirm that a web page or interface still looks the same after code changes. You compare a reference screenshot against a new one and fail the test if the difference exceeds a threshold you set. The library supports several comparison modes: you can ignore colors entirely and compare only structure, ignore anti-aliasing (the smoothing effect on edges that often causes false matches), or limit the comparison to a specific rectangular area within the image. It works both in a web browser using the HTML5 Canvas API and in Node.js, the server-side JavaScript runtime, through a dependency called node-canvas. The README notes that node-canvas is a pre-built binary that can fail in certain environments and gives specific troubleshooting options if the install does not work. The API is straightforward. You load two images, chain options onto the comparison call, and receive results in a callback or as a promise depending on which interface you use. Output settings like the highlight color, transparency of the diff overlay, and thresholds for skipping large images are all adjustable. The project is described as in "ultra low-maintenance mode," meaning the author responds to issues and contributions only once or twice a year. It is released under the MIT license, which allows free use in commercial and open-source projects. It was originally created by James Cryer and the Huddle development team.

Copy-paste prompts

Prompt 1
Using resemble.js in Node.js, write a script that compares two PNG screenshots and exits with an error if more than 2% of pixels differ.
Prompt 2
Show me how to use resemble.js to compare two images and save the diff image with changed pixels highlighted in red.
Prompt 3
Write a visual regression test using resemble.js that ignores anti-aliasing and only checks the main content region of a screenshot.
Prompt 4
How do I configure resemble.js to compare images by structure only, ignoring all color differences?
Prompt 5
Create a Node.js CI helper using resemble.js that compares a reference screenshot against a new capture and reports the percentage difference.
Open on GitHub → Explain another repo

← rsmbl on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.