diff --git a/src/inky_impression/render.py b/src/inky_impression/render.py index dfc3191..e5412ee 100644 --- a/src/inky_impression/render.py +++ b/src/inky_impression/render.py @@ -31,13 +31,24 @@ def screenshot_url(url: str, width: int, height: int, out: pathlib.Path) -> None ) -def show_url(url: str, *, saturation: float = 0.5) -> None: +def show_url(url: str, *, saturation: float = 0.5, rotate: int = 90) -> None: + """Screenshot `url` and push to the Inky. + + `rotate` is degrees CCW applied to the rendered image before it's sent to + the panel (0/90/180/270). 90 and 270 swap the viewport to portrait so the + web page is laid out for the rotated orientation, not letterboxed. + """ inky = auto(ask_user=False, verbose=False) - w, h = inky.resolution + panel_w, panel_h = inky.resolution + rotate = rotate % 360 + shot_w, shot_h = (panel_h, panel_w) if rotate in (90, 270) else (panel_w, panel_h) with tempfile.TemporaryDirectory() as tmp: out = pathlib.Path(tmp) / "screen.png" - screenshot_url(url, w, h, out) - img = Image.open(out).convert("RGB").resize((w, h)) + screenshot_url(url, shot_w, shot_h, out) + img = Image.open(out).convert("RGB") + if rotate: + img = img.rotate(rotate, expand=True) + img = img.resize((panel_w, panel_h)) try: inky.set_image(img, saturation=saturation) except TypeError: