MCPcopy Create free account
hub / github.com/Paper2Poster/Paper2Poster / rendered_dims

Function rendered_dims

utils/wei_utils.py:939–956  ·  view source on GitHub ↗
(html: Path)

Source from the content-addressed store, hash-verified

937 return ()
938
939async def rendered_dims(html: Path) -> tuple[int, int]:
940 async with async_playwright() as p:
941 browser = await p.chromium.launch()
942 page = await browser.new_page() # no fixed viewport yet
943 resolved = html.resolve()
944 # quote_from_bytes expects bytes, so we encode the path as UTF‐8:
945 url = "file://" + quote_from_bytes(str(resolved).encode("utf-8"), safe="/:")
946 await page.goto(url, wait_until="networkidle")
947
948 # 1) bounding-box of <body>
949 body_box = await page.eval_on_selector(
950 "body",
951 "el => el.getBoundingClientRect()")
952 w = int(body_box["width"])
953 h = int(body_box["height"])
954
955 await browser.close()
956 return w, h
957
958
959def html_to_png(html_abs_path, poster_width_default, poster_height_default, output_path):

Callers 1

html_to_pngFunction · 0.85

Calls 1

closeMethod · 0.45

Tested by

no test coverage detected