Image Diff API

Compare two images pixel by pixel (perceptual colour distance, anti-aliasing aware) and get the share of changed pixels, the changed area and a highlighted diff image.

POSThttps://apibox.io.vn/v1/image-diff

The image diff API compares two PNG or JPEG images of the same size, such as screenshots of a page before and after a change. It uses pixelmatch, the algorithm of many visual regression tools: colours are compared in a perceptual space with a threshold (0 = exact, default 0.1), and differences caused by anti-aliasing are ignored unless include_aa=true.

The JSON result says whether the images are identical, how many pixels differ and what percentage of the image that is, and the bounding box of the changes. output=image returns the diff image itself: the first image faded, with changed pixels in red and anti-aliasing in yellow; include_image=true adds it as base64 to the JSON.

Images of different sizes are reported as such; resize=true scales the second image to the first one before comparing. Each image may have up to 12.5 megapixels.

Parameters

NameInTypeRequiredDefault
abodyfileyesFirst image (multipart field a, or a_base64).
bbodyfileyesSecond image (b / b_base64).
thresholdbody|querynumberno0.1Colour distance threshold 0–1.
include_aabody|querybooleannofalseCount anti-aliasing as differences.
outputbody|querystringnojsonjson or image (diff PNG).
resizebody|querybooleannofalseScale b to a when sizes differ.

Example

curl -X POST "https://apibox.io.vn/v1/image-diff" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -F "0=@./my-file"

Response

{
  "identical": false,
  "width": 1200,
  "height": 630,
  "diff_pixels": 758,
  "diff_percent": 0.1003,
  "threshold": 0.1,
  "bounding_box": {
    "x": 409,
    "y": 327,
    "width": 324,
    "height": 58
  }
}

Use cases

  • Visual regression tests in CI
  • Detect unexpected changes on monitored web pages
  • Compare design mock-ups with implementation
  • Check that image processing keeps quality

FAQ

What threshold should I use?

0.1 for screenshots; 0 to detect any change; 0.2–0.3 for photos and JPEGs with compression noise.

Do I need screenshots of the same size?

Yes for exact comparisons; resize=true makes them comparable but adds interpolation differences.

Can it take screenshots for me?

No, send the images; screenshots need a browser service.

Related APIs

Start with 1,000 free requests every month. Get free API key →