Examples
How to convert HTML to a base64 image with Playwright and Python
Install Playwright and the Playwright client for Python
pip install playwright
playwright install chromium Get the base64 encoded image of some HTML and print to screen
import base64
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.chromium.launch()
page = browser.new_page()
page.set_content('<html><body><h1>Hello World</h1></body></html>')
image = page.screenshot()
print(base64.b64encode(image).decode())
browser.close() Find out how to generate a PNG from HTML with Python and Playwright.
That was 11 lines of code — plus a browser to run in production
Keeping headless browsers fed, patched and scaled is a job in itself. We built Urlbox so the same screenshot is one API call:
curl "https://api.urlbox.com/v1/YOUR_API_KEY/png?url=https://example.com" Try the Urlbox screenshot API — free trial, no browser babysitting.