diff --git a/src/diffenator2/__main__.py b/src/diffenator2/__main__.py index 99e1986..5bed861 100644 --- a/src/diffenator2/__main__.py +++ b/src/diffenator2/__main__.py @@ -58,9 +58,9 @@ def main(**kwargs): ) diff_parser.add_argument("--no-diffenator", default=False, action="store_true") diff_parser.add_argument("--threshold", "-t", type=float, default=THRESHOLD) - diff_parser.add_argument("--precision", default=FONT_SIZE) + diff_parser.add_argument("--precision", default=FONT_SIZE, type=int) # TODO this can just be precision - diff_parser.add_argument("--font-size", default=FONT_SIZE) + diff_parser.add_argument("--font-size", default=FONT_SIZE, type=int) diff_parser.add_argument( "--no-tables", action="store_true", help="Skip diffing font tables" ) diff --git a/src/diffenator2/screenshot.py b/src/diffenator2/screenshot.py index fd57f8b..b18b290 100644 --- a/src/diffenator2/screenshot.py +++ b/src/diffenator2/screenshot.py @@ -53,6 +53,7 @@ def take_png(self, browser: any, dst_dir: str, javascript: str = ""): body_el = browser.find_element(By.TAG_NAME, "html") browser.set_window_size(self.width, body_el.size["height"]) browser.save_screenshot(filename) + return filename def take_gif(self, url: str, dst_dir: str, font_toggle): before_fp = os.path.join(dst_dir, "before") diff --git a/src/diffenator2/utils.py b/src/diffenator2/utils.py index fa92b1a..10a7d50 100644 --- a/src/diffenator2/utils.py +++ b/src/diffenator2/utils.py @@ -125,8 +125,6 @@ def gen_gifs(dir1: str, dir2: str, dst_dir: str): dir2_imgs = set(f for f in os.listdir(dir2) if f.endswith(("jpg", "png"))) shared_imgs = dir1_imgs & dir2_imgs for img in shared_imgs: - # We use apng format since a gif's dimensions are limited to 64kx64k - # we have encountered many diffs which are taller than this. gif_filename = img[:-4] + ".gif" img_a_path = os.path.join(dir1, img) img_b_path = os.path.join(dir2, img) @@ -146,6 +144,15 @@ def gen_gif(img_a, img_b, dst): 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) + gen_img_difference(img_a, img_b, dst.replace(".gif", "_diff.png")) + + +def gen_img_difference(img_a, img_b, dst: str): + from PIL import ImageChops + img_a = img_a.convert("RGB") + img_b = img_b.convert("RGB") + img = ImageChops.difference(img_a, img_b) + img.save(dst) @lru_cache() diff --git a/tests/test_functional.py b/tests/test_functional.py index 06737ec..92b98b9 100644 --- a/tests/test_functional.py +++ b/tests/test_functional.py @@ -46,7 +46,7 @@ def test_run_diffbrowsers_proof_imgs(fp): else: imgs.append(f) # There should be images for the text, glyphs and waterfall page - assert len(imgs) == 3 + assert len(imgs) >= 3