Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix github actions image generation #131

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/diffenator2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
logger.setLevel(logging.INFO)


MAX_STYLES = 4
MAX_STYLES = 1
THRESHOLD = 0.90 # Percent difference
NINJA_BUILD_FILE = "build.ninja"

Expand Down
6 changes: 3 additions & 3 deletions src/diffenator2/screenshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import shutil
import tempfile
import sys
import time


class ScreenShotter:
Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/diffenator2/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
Loading