Example code
To get started quickly, take a look at our example code for generating images.
Using an AI coding assistant?
Skip writing code entirely. Connect our MCP Server to generate images directly from Cursor or Claude Code.
Works with any programming language
The HTML/CSS to Image API is a simple REST API. If your language can make an HTTP request, it can generate images.
We provide example code for popular languages, but the API works the same way everywhere:
- Send a
POSTrequest tohttps://hcti.io/v1/image - Include your HTML/CSS in the request body
- Authenticate with HTTP Basic Auth
- Receive a JSON response with your image URL
The API request
Here’s what a request to the API looks like:
| Property | Description |
|---|---|
| Endpoint | https://hcti.io/v1/image |
| Method | POST |
| Content-Type | application/json |
| Authentication | HTTP Basic Auth (User ID + API Key) |
Request body (JSON)
{
"html": "<div class='box'>Hello, world!</div>",
"css": ".box { padding: 20px; background: #03B875; color: white; }"
}
Response
{
"url": "https://hcti.io/v1/image/be4c5118-fe19-462b-a49e-48cf72697a9d"
}
The returned URL is your generated image. Append .png, .jpg, or .webp to the URL to get different formats.
Quick reference with cURL
The simplest way to test the API:
curl -X POST https://hcti.io/v1/image \
-u 'your-user-id:your-api-key' \
-H 'Content-Type: application/json' \
-d '{"html": "<h1>Hello!</h1>"}'
Available parameters
| Parameter | Required | Description |
|---|---|---|
html | Yes* | The HTML to render |
css | No | CSS styles for your HTML |
url | Yes* | URL of a webpage to screenshot |
google_fonts | No | Google Fonts to load (comma separated) |
ms_delay | No | Milliseconds to wait before capture |
device_scale | No | Device scale factor (1-3) for retina images |
full_screen | No | Capture the full scrollable page |
selector | No | CSS selector to screenshot a specific element |
*Either html or url is required.
For full parameter documentation, see Parameters.
Choose your language
Select your programming language below to see a complete working example:
Table of contents
- C# / .NET
- Curl
- Go - HTML to Image Example
- Google Apps Script
- JavaScript - HTML to Image Example
- PHP - HTML to Image Example
- Python - HTML to Image Example
- Ruby - HTML to Image Example
- TypeScript - HTML to Image Example
- VB.NET