#!/usr/bin/env python3
"""Renderiza um arquivo HTML para PNG 500x300 (formato RCS)."""
import sys
from pathlib import Path
from playwright.sync_api import sync_playwright


def render(html_path: str, png_path: str, width: int = 500, height: int = 300):
    html = Path(html_path).read_text(encoding="utf-8")
    with sync_playwright() as p:
        browser = p.chromium.launch()
        page = browser.new_page(viewport={"width": width, "height": height},
                                device_scale_factor=2)
        page.set_content(html, wait_until="networkidle")
        # Espera fontes carregarem
        page.evaluate("document.fonts.ready")
        page.wait_for_timeout(500)
        page.screenshot(path=png_path,
                        clip={"x": 0, "y": 0, "width": width, "height": height},
                        omit_background=False)
        browser.close()
    print(f"OK -> {png_path}")


if __name__ == "__main__":
    render(sys.argv[1], sys.argv[2])
