or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-9/

Image Comparison Tool

Build a command-line image comparison utility that compares two PNG images and reports detailed comparison results with appropriate exit codes for automation workflows.

Requirements

Your tool should accept command-line arguments in the following format:

node compare-images.js <image1.png> <image2.png> [output-diff.png] [threshold]

Arguments

  • image1.png (required): Path to the first PNG image
  • image2.png (required): Path to the second PNG image
  • output-diff.png (optional): Path where the visual diff image should be saved
  • threshold (optional): Sensitivity threshold as a number (default: 0.1)

Output Requirements

The tool must print the following information to the console:

  1. Performance timing showing how long the comparison took
  2. If the images have different dimensions, report this and exit with code 65
  3. The number of mismatched pixels
  4. The error percentage (mismatched pixels / total pixels * 100)

Exit Codes

Your tool must use these specific exit codes for automation:

  • 0: Images match (0 mismatched pixels)
  • 64: Invalid number of arguments or file reading errors
  • 65: Image dimensions don't match
  • 66: Images differ (mismatched pixels > 0)

Test Cases

  • When comparing two identical PNG images, it reports 0 mismatched pixels and exits with code 0 @test
  • When comparing two different PNG images, it reports the number of mismatched pixels, calculates error percentage, and exits with code 66 @test
  • When comparing images with different dimensions, it reports dimension mismatch and exits with code 65 @test
  • When provided with invalid file paths, it exits with code 64 @test

Dependencies { .dependencies }

pixelmatch { .dependency }

Provides pixel-level image comparison functionality.

pngjs { .dependency }

Provides PNG image encoding and decoding support.

Implementation

@generates