Recipe 6Compare Images

Problem

You’re using Cucumber to test an app that generates or manipulates images. You want to compare the result to a reference picture—with a little wiggle room for minor differences.

Ingredients

  • pdiff (short for “perceptual diff”),[37] a command-line image comparison tool that accounts for the way people perceive images

  • chunky_png[38] for generating PNG files in the example code

Solution

It sounds so simple, doesn’t it? “Compare these two pictures and tell me whether they match.” But the devil is in the details. What does it mean for two images to match?

Do they need to be pixel-for-pixel identical? If not, what percentage difference is acceptable? What about images that are slightly rotated or scaled? Or discolored ...

Get Cucumber Recipes now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.