SkillAgentSearch skills...

Odiff

A very fast SIMD-first image comparison library (with nodejs API)

Install / Use

/learn @dmtrKovalenko/Odiff
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

<p align="center"> <picture> <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/dmtrKovalenko/odiff/main/odiff-logo-dark.png"> <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/dmtrKovalenko/odiff/main/odiff-logo-light.png"> <img alt="pixeletad caml and odiff text with highlighted red pixels difference" src="https://raw.githubusercontent.com/dmtrKovalenko/odiff/main/odiff-logo-dark.png"> </picture> </p> <h3 align="center"> The fastest* (one-thread) pixel-by-pixel image difference tool in the world. </h3> <div align="center"> <img src="https://forthebadge.com/images/badges/made-with-reason.svg" alt="made with reason"> <img src="https://forthebadge.com/images/badges/gluten-free.svg" alt="npm"/> <img src="https://forthebadge.com/images/badges/powered-by-overtime.svg"> </div>

Why Odiff?

ODiff is a blazing fast native image comparison tool. Check benchmarks for the results, but it compares the visual difference between 2 images in milliseconds. ODiff is designed specifically to handle significantly similar images like screenshots, photos, AI-generated images and many more. ODiff is designed to be portable, fast, and memory efficient.

Originally written in OCaml, currently in Zig with SIMD optimizations for SSE2, AVX2, AVX512, and NEON.

Demo

| base | comparison | diff | | ------------------------------ | -------------------------------- | ------------------------------------- | | | | 1diff | | | | 1diff | | | | 1diff |

Features

  • ✅ Cross-format comparison - Yes .jpg vs .png comparison without any problems.
  • ✅ Support for .png, .jpeg, .jpg, .webp, and .tiff
  • ✅ Supports comparison of images with different layouts.
  • ✅ Anti-aliasing detection
  • ✅ Ignoring regions
  • ✅ Using YIQ NTSC transmission algorithm to determine visual difference.
  • ✅ SIMD optimized working for SSE2, AVX2, AVX512, and NEON
  • ✅ Controlled memory footprint
  • ✅ 100% test coverage and backward compatibility

Usage

Basic comparison

Run the simple comparison. Image paths can be one of supported formats, diff output is optional and can only be .png.

odiff <IMG1 path> <IMG2 path> [DIFF output path]

Node.js

We also provide direct node.js binding for the odiff. Run the odiff from nodejs:

const { compare } = require("odiff-bin");

const { match, reason } = await compare(
  "path/to/first/image.png",
  "path/to/second/image.png",
  "path/to/diff.png",
);

Server mode

Odiff provides a server mode for the long lasting runtime application to reduce a time you have to spend on forking and initializing child process on each odiff call. From node js it works as simply as

const { ODiffServer } = require("odiff-bin");

// it is safe to run from the module scope as it will automatically lazy load
// and will cleanup and gracefully close on exits/sigints
const odiffServer = new ODiffServer();

const { match, reason } = await odiffServer.compare(
  "path/to/first/image.png",
  "path/to/second/image.png",
  "path/to/diff.png",
);

For the pure binary usage this is a simple readline stdio protocol with JSON message, here is a simple example

odiff --server

$ odiff --server
{"ready":true} # ready signal

# your input
{"requestId":1,"base":"images/www.cypress.io.png","compare":"images/www.cypress.io-1.png","output":"images/www.cypress-diff.
png"}
# server response
{"requestId":1,"match":false,"reason":"pixel-diff","diffCount":1090946,"diffPercentage":2.95}

Using from other frameworks

Playwright

Just install playwright-odiff and simply

// in your setup file or test entrypoint
import "playwright-odiff/setup";

expect(page).toHaveScreenshotOdiff("screenshot-name", { /* any odiff and playwright options */ });

More details at playwright-odiff doc

Cypress

Checkout cypress-odiff, a cypress plugin to add visual regression tests using odiff-bin.

Visual regression services

Argos – Argos is the modern visual testing platform for websites, mobile apps and design systems. It uses odiff for comparison. (It became 8x faster with odiff)

LostPixel – Holistic visual testing for your Frontend that allows very easy integration with storybook and uses odiff for comparison

Visual Regression Tracker – Self hosted visual regression service that allows to use odiff as screenshot comparison engine

OSnap – Snapshot testing tool written in OCaml that uses config based declaration to define test and was built by odiff collaborator.

Api

Here is an api reference:

CLI

The best way to get up-to-date cli interface is just to type the

odiff --help

Node.js

NodeJS Api is pretty tiny as well. Here is a typescript interface we have:

<!--inline-interface-start-->
export type ODiffOptions = Partial<{
  /** Color used to highlight different pixels in the output (in hex format e.g. #cd2cc9). */
  diffColor: string;
  /** Output full diff image. */
  outputDiffMask: boolean;
  /** Outputs diff images with a white shaded overlay for easier diff reading */
  diffOverlay: boolean | number;
  /** Do not compare images and produce output if images layout is different. */
  failOnLayoutDiff: boolean;
  /** Return { match: false, reason: '...' } instead of throwing error if file is missing. */
  noFailOnFsErrors: boolean;
  /** Color difference threshold (from 0 to 1). Less more precise. */
  threshold: number;
  /** If this is true, antialiased pixels are not counted to the diff of an image */
  antialiasing: boolean;
  /** If `true` reason: "pixel-diff" output will contain the set of line indexes containing different pixels */
  captureDiffLines: boolean;
  /** If `true` odiff will use less memory but will be slower with larger images */
  reduceRamUsage: boolean;
  /** An array of regions to ignore in the diff. */
  ignoreRegions: Array<{
    x1: number;
    y1: number;
    x2: number;
    y2: number;
  }>;
}>;

export type ODiffResult =
  | { match: true }
  | { match: false; reason: "layout-diff" }
  | {
      match: false;
      reason: "pixel-diff";
      /** Amount of different pixels */
      diffCount: number;
      /** Percentage of different pixels in the whole image */
      diffPercentage: number;
      /** Individual line indexes containing different pixels. Guaranteed to be ordered and distinct.  */
      diffLines?: number[];
    }
  | {
      match: false;
      reason: "file-not-exists";
      /** Errored file path */
      file: string;
    };

declare function compare(
  basePath: string,
  comparePath: string,
  diffPath: string,
  options?: ODiffOptions,
): Promise<ODiffResult>;

/**
 * ODiffServer - Persistent server instance for multiple comparisons
 *
 * Use this when you need to perform multiple image comparisons to avoid
 * process spawn overhead. The server process stays alive and reuses resources.
 *
 * The server initializes automatically on first compare() call, so you can
 * create an instance and start using it immediately.
 *
 * @example
 * ```ts
 * const server = new ODiffServer();
 *
 * const result1 = await server.compare('a.png', 'b.png', 'diff1.png');
 * // add optional timeout to catch any possible crashes on the server side:
 * const result2 = await server.compare('c.png', 'd.png', 'diff2.png', { threshold: 0.3, timeout: 5000 });
 *
 * server.stop();
 * ```
 *
 * It is absolutely fine to keep odiff sever leaving in the module root
 * even if you have several independent workers, it will automatically spawn
 * a server process per each multiplexed core to work in parallel
 *
 * @example
 * ```typescript
 * const odiffServer = new ODiffServer();
 *
 * test('visual test 1', async () => {
 *   await odiffServer.compare('a.png', 'b.png', 'diff1.png');
 * });
 *
 * test('visual test 2', async () => {
 *   await odiffServer.compare('c.png', 'd.png', 'diff2.png');
 * });
 * ```
 */
export declare class ODiffServer {
  /**
   * Create a new ODiffServer instance
   * Server initialization begins immediately in the background
   * @param binaryPath - Optional path to odiff binary (defaults to bundled binary)
   */
  constructor(binaryPath?: string);

  /**
   * Compare two images using the persistent server
   * Automatically waits for server initialization if needed
   * @param basePath - Path to base image
   * @param comparePath - Path to comparison image
   * @param diffOutput - Path to output diff image
   * @param options - Comparison options with optional timeout for request
   * @returns Promise resolving to comparison result
   */
  compare(
    basePath:
View on GitHub
GitHub Stars2.9k
CategoryDevelopment
Updated9h ago
Forks99

Languages

Zig

Security Score

100/100

Audited on Apr 1, 2026

No findings