Upstreaming browser/ui/uikit_ui_util from iOS.
[chromium-blink-merge.git] / tools / site_compare / operators / equals.py
blob311f530a0596bc996750243a0db142968b19b00f
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."""
7 from PIL import Image
8 from PIL import ImageChops
11 def Compare(file1, file2, **kwargs):
12 """Compares two images to see if they're identical.
14 Args:
15 file1: path to first image to compare
16 file2: path to second image to compare
17 kwargs: unused for this operator
19 Returns:
20 None if the images are identical
21 A tuple of (errorstring, image) if they're not
22 """
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)
36 else:
37 return None