LinuxCommandLibrary

diffimg

Visually compare two images for differences

TLDR

Compare two images and output the difference image to the specified file

$ diffimg [path/to/image1] [path/to/image2] [path/to/output_image]
copy

SYNOPSIS

diffimg [-o outfile.png] [-t threshold] [-s scale] [-m metric] img1.png img2.png

PARAMETERS

-o file
    Specify output PNG file; defaults to stdout

-t float
    Difference threshold (0.0-1.0, default 0.1); pixels below unchanged

-s float
    Output scale factor (default 1.0); useful for resizing

-m {mse,ssim}
    Metric for difference computation (default mse)

DESCRIPTION

diffimg is a lightweight command-line utility designed to compare two PNG images and generate a visual representation of their differences. Developed by Salvatore Sanfilippo (antirez), it blends the two input images, highlighting pixel differences in red where the variation exceeds a specified threshold. This makes it ideal for spotting subtle changes in screenshots, diagrams, or generated images during development or testing.

It uses simple metrics like Mean Squared Error (MSE) by default but supports others like SSIM. The output is a single PNG file showing the overlaid images with differences emphasized, scaled if needed. Unlike heavier tools like ImageMagick's compare, diffimg is fast, standalone (written in C), and requires no external dependencies beyond libpng and zlib.

Common use cases include UI testing, image regression in CI pipelines, or manual inspection of visual changes. It outputs to stdout by default or a specified file, making it script-friendly. Threshold and scale options allow fine-tuning sensitivity to noise or resolution differences.

CAVEATS

Supports only PNG input/output; ignores alpha channels; basic metrics may miss perceptual differences; compile from source for latest version.

INSTALLATION

Compile from https://github.com/antirez/diffimg: make after installing libpng-dev and zlib-dev.

EXAMPLE

diffimg -o diff.png -t 0.05 shot1.png shot2.png
Generates diff.png with sensitive threshold.

HISTORY

Created in 2014 by antirez (Redis author) as a minimal C tool using libpng. Hosted on GitHub; remains popular for its speed and simplicity in 2023+ CI workflows.

SEE ALSO

compare(1), identify(1), display(1)

Copied to clipboard