render: support 90-deg rotation; default to 90 CCW so panel works in portrait

This commit is contained in:
Padreug 2026-05-16 14:09:23 +02:00
commit a2d4d8b07e

View file

@ -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) 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: with tempfile.TemporaryDirectory() as tmp:
out = pathlib.Path(tmp) / "screen.png" out = pathlib.Path(tmp) / "screen.png"
screenshot_url(url, w, h, out) screenshot_url(url, shot_w, shot_h, out)
img = Image.open(out).convert("RGB").resize((w, h)) img = Image.open(out).convert("RGB")
if rotate:
img = img.rotate(rotate, expand=True)
img = img.resize((panel_w, panel_h))
try: try:
inky.set_image(img, saturation=saturation) inky.set_image(img, saturation=saturation)
except TypeError: except TypeError: