From 52c2ce10912b88825e16ed34e0e338cd510e9396 Mon Sep 17 00:00:00 2001 From: Hilal Alsibai Date: Thu, 3 Feb 2022 10:56:12 -0800 Subject: [PATCH] Ensure images are converted to RGB for diff checking + add image size check Summary: For some odd reason `ImageChops.difference` does not work at all with RGBA formatted images, so this forces images to be in RGB format prior to diffing (which may also indicate that we're dropping alpha only changes). This also adds a change to check for image dimension differences to partially address the concerns in #292 Differential Revision: D33961675 fbshipit-source-id: 893cb07568893e74a9717b6c90fc9b1ab065feb3 --- plugin/src/py/android_screenshot_tests/recorder.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/src/py/android_screenshot_tests/recorder.py b/plugin/src/py/android_screenshot_tests/recorder.py index d7e18bee..1df81c03 100644 --- a/plugin/src/py/android_screenshot_tests/recorder.py +++ b/plugin/src/py/android_screenshot_tests/recorder.py @@ -90,10 +90,10 @@ def _clean(self): def _is_image_same(self, file1, file2, failure_file): with Image.open(file1) as im1, Image.open(file2) as im2: - diff_image = ImageChops.difference(im1, im2) + diff_image = ImageChops.difference(im1.convert("RGB"), im2.convert("RGB")) try: diff = diff_image.getbbox() - if diff is None: + if diff is None and im1.size == im2.size: return True else: if failure_file: