Pillow icon indicating copy to clipboard operation
Pillow copied to clipboard

Added compare_images function to ImageChops

Open johnnygitgud opened this issue 2 weeks ago • 1 comments

This pull request implements the feature requested in issue #6478 by adding a new helper function compare_images to ImageChops.

The function compares two images pixel-by-pixel using ImageChops.difference and returns a dictionary containing:

different_pixels — the number of pixels that differ

percent_difference — the percentage of differing pixels

It raises a ValueError if the images have different modes or sizes, matching existing behavior elsewhere in Pillow.

A new test file (Tests/test_compare_images.py) is included to validate that:

identical images return zero difference

different images return nonzero values

This feature builds directly on existing ImageChops functionality and follows the project's testing and docstring conventions.

Closes #6478

johnnygitgud avatar Dec 05 '25 23:12 johnnygitgud

Hi. I don't think this does actually resolve #6478, as I think that issue wants to compare all frames of an image, and to have images automatically convert before comparison. That issue also only expected a boolean to be returned, rather than any information about how different the two images are.

So let me ask - ignoring #6478, do you personally think what you're put together would be a helpful addition to Pillow?

radarhere avatar Dec 06 '25 03:12 radarhere

Closing, as this doesn't resolve the issue. The suggestion here isn't wholly uninteresting by itself, but there's been no response, and I think there should be at least one advocate for any new functionality.

radarhere avatar Dec 15 '25 05:12 radarhere