This API provides a service to convert HTML content or a URL into JPEG images using Playwright. It's designed to be simple, efficient, and deployable on platforms like Railway. Pre-built Docker images are available at bybetas/h2i:latest
.
- URL:
/convert
- Method:
POST
- Description: Converts provided HTML content, a URL, or a base64 HTML string into a JPEG image.
- Headers:
X-Render-Secret
(optional): The secret key for authentication ifH2I_RENDER_SECRET
is set
- Body:
- Content-Type:
application/json
- Required field: Either
html
(string) - The HTML content to be converted,url
(string) - The URL of the page to be converted, orhtml64
(string) - The base64 encoded HTML content to be converted
- Content-Type:
- Query Parameters:
width
(optional): Desired width of the output image in pixelsheight
(optional): Desired height of the output image in pixels
- Response:
- Content-Type:
image/jpeg
- The JPEG image of the rendered HTML, URL, or base64 HTML string
- Content-Type:
If the H2I_RENDER_SECRET
environment variable is set, clients must provide the correct secret in the X-Render-Secret
header when making requests to the /convert
endpoint. If the secret is not set (empty string), the server will allow all requests without checking for a secret.
To convert HTML to an image:
POST /convert
Content-Type: application/json
X-Render-Secret: your_secret_here
{
"html": "<html><body><h1>Hello, World!</h1></body></html>"
}
To convert a URL to an image:
POST /convert
Content-Type: application/json
X-Render-Secret: your_secret_here
{
"url": "https://example.com"
}
To convert HTML or a URL to an image with specific dimensions:
POST /convert?width=800&height=600
Content-Type: application/json
X-Render-Secret: your_secret_here
{
"html": "<html><body><h1>Hello, World!</h1></body></html>"
}
Or for a URL:
POST /convert?width=800&height=600
Content-Type: application/json
X-Render-Secret: your_secret_here
{
"url": "https://example.com"
}
MIT License: You can do almost anything with this software, as long as you include the original license and copyright notice.