From 6e984a753ddce96828acc87832b61e7ab7526a79 Mon Sep 17 00:00:00 2001 From: Marc Foley Date: Wed, 14 Feb 2024 11:00:03 +0000 Subject: [PATCH] Fix github actions image generation --- src/diffenator2/__init__.py | 2 +- src/diffenator2/screenshot.py | 6 +++--- src/diffenator2/utils.py | 5 +++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/diffenator2/__init__.py b/src/diffenator2/__init__.py index 93a3877..98da207 100644 --- a/src/diffenator2/__init__.py +++ b/src/diffenator2/__init__.py @@ -16,7 +16,7 @@ logger.setLevel(logging.INFO) -MAX_STYLES = 4 +MAX_STYLES = 1 THRESHOLD = 0.90 # Percent difference NINJA_BUILD_FILE = "build.ninja" diff --git a/src/diffenator2/screenshot.py b/src/diffenator2/screenshot.py index adfb236..fd57f8b 100644 --- a/src/diffenator2/screenshot.py +++ b/src/diffenator2/screenshot.py @@ -8,6 +8,7 @@ import shutil import tempfile import sys +import time class ScreenShotter: @@ -62,7 +63,6 @@ def take_gif(self, url: str, dst_dir: str, font_toggle): if not os.path.exists(after_fp): os.mkdir(after_fp) - import time time.sleep(1) self.take_png(url, before_fp) time.sleep(1) @@ -77,7 +77,7 @@ def set_width(self, width: int): def _get_browsers(self): """Determine which browsers we can screenshot which exist on the system""" # We can add more webdrivers if needed. Let's focus on these first - supported = ["Chrome", "Firefox", "Safari"] + supported = ["Chrome", "Firefox"] has = [] driver = webdriver for browser in supported: @@ -100,7 +100,7 @@ def _get_browsers(self): browser_driver = getattr(driver, browser)(options=options) else: browser_driver = getattr(driver, browser)() - browser_driver.set_page_load_timeout(180) + browser_driver.set_page_load_timeout(30) has.append(browser_driver) except: pass diff --git a/src/diffenator2/utils.py b/src/diffenator2/utils.py index 8acfcbb..aab6176 100644 --- a/src/diffenator2/utils.py +++ b/src/diffenator2/utils.py @@ -129,6 +129,11 @@ def gen_gifs(dir1: str, dir2: str, dst_dir: str): def gen_gif(img_a_path: str, img_b_path: str, dst: str): with Image.open(img_a_path) as img_a, Image.open(img_b_path) as img_b: + # Images must have same dimensions in order for PIL to gen gif + # 4-tuple defining the left, upper, right, and lower + crop_box = (0, 0, min(img_a.width, img_b.width), min(img_a.height, img_b.height)) + img_a = img_a.crop(crop_box) + img_b = img_b.crop(crop_box) img_a.save(dst, save_all=True, append_images=[img_b], loop=10000, duration=1000)