Compare two images
ai_image_diffCompare two images pixel by pixel and write a diff PNG with changed pixels in red over a faded reference; returns difference count and percentage for visual regression checks.
Instructions
Compare two images pixel by pixel (pixelmatch, anti-aliasing aware) and write a diff PNG with changed pixels in red over a faded copy of the first image. Returns the number and percentage of different pixels. Images must be the same size unless resize is true (the second is stretched to the first's size). Reads PNG, JPEG, WebP, AVIF, GIF (first frame), TIFF and SVG; file path or base64; up to 50 MP. Good for visual regression checks.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| a | Yes | The first (reference) image: a local file path (absolute, or relative to the server's --root) or base64 data (raw or a data: URI). | |
| b | Yes | The second image: a local file path (absolute, or relative to the server's --root) or base64 data (raw or a data: URI). | |
| output | No | Where to write the result: a file path, or a folder ending in "/". Default: the server output folder (a temp folder unless --out-dir is set). | |
| resize | No | Resize the second image to the first one's size when they differ (otherwise that is an error). | |
| includeAA | No | Count anti-aliased edge pixels as differences too. Default false. | |
| threshold | No | Colour difference tolerance 0..1; smaller is stricter. Default 0.1. | |
| returnBase64 | No | Also return the output as base64 in the result (only for small files). Default false. |