1 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 """Compare two images for equality."""
8 from PIL
import ImageChops
11 def Compare(file1
, file2
, **kwargs
):
12 """Compares two images to see if they're identical.
15 file1: path to first image to compare
16 file2: path to second image to compare
17 kwargs: unused for this operator
20 None if the images are identical
21 A tuple of (errorstring, image) if they're not
23 kwargs
= kwargs
# unused parameter
25 im1
= Image
.open(file1
)
26 im2
= Image
.open(file2
)
28 if im1
.size
!= im2
.size
:
29 return ("The images are of different size (%s vs %s)" %
30 (im1
.size
, im2
.size
), im1
)
32 diff
= ImageChops
.difference(im1
, im2
)
34 if max(diff
.getextrema()) != (0, 0):
35 return ("The images differ", diff
)