import asyncio
from playwright.async_api import async_playwright

async def render():
    async with async_playwright() as p:
        browser = await p.chromium.launch()
        for html_file, width, height in [
            ('/home/jay/workspace/output/banners/versions/v-round2/cell-4-ga-fair/meta-feed-1080x1080.html', 1080, 1080),
            ('/home/jay/workspace/output/banners/versions/v-round2/cell-4-ga-fair/google-resp-1200x628.html', 1200, 628),
        ]:
            page = await browser.new_page(viewport={'width': width, 'height': height})
            await page.goto(f'file://{html_file}')
            await page.wait_for_timeout(1500)
            png_path = html_file.replace('.html', '.png')
            await page.screenshot(path=png_path, full_page=False)
            print(f'Saved: {png_path}')
        await browser.close()

asyncio.run(render())
