APIVoid logo

HTML to PNG API Reference

Convert custom HTML code into a PNG image rendered by a real browser.

Service details and pricing: HTML to PNG API

POSThttps://api.apivoid.com/v2/html-to-png
20 credits per successful requestCan take up to 150 secondsPOST · JSON

Request example

Query the endpoint via an HTTPS POST request (replace YOUR_API_KEY_HERE with your API key):

curl
curl -X POST "https://api.apivoid.com/v2/html-to-png" \
     -H "Content-Type: application/json" \
     -H "X-API-Key: YOUR_API_KEY_HERE" \
     -d '{"html_base64": "PGh0bWw+PGJvZHk+PGgxPlRlc3RpbmcgSFRNTCB0byBQTkcgQVBJPC9oMT48L2JvZHk+PC9odG1sPg=="}'

The same request in PHP:

php
$html = '<html><body><h1>Testing</h1><p>Example text...</p></body></html>';
$htmlBase64 = base64_encode($html);

$apiKey = 'YOUR_API_KEY_HERE';

$curl = curl_init('https://api.apivoid.com/v2/html-to-png');
curl_setopt($curl, CURLOPT_HTTPHEADER, ['Content-Type: application/json', 'X-API-Key: ' . $apiKey]);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode(['html_base64' => $htmlBase64]));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($curl);
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);

if ($httpCode === 200) {
    $responseData = json_decode($response, true);
    print_r($responseData);

    // Save the "base64_file" data as PNG file
    if (isset($responseData['rendered_file']['base64_file'])) {
        $saveAs = __DIR__ . '/screenshot.png';

        file_put_contents($saveAs, base64_decode($responseData['rendered_file']['base64_file']));

        if (file_exists($saveAs)) {
            echo '<p><img src="screenshot.png" alt="screenshot" class="img-responsive" /></p>';
        } else {
            echo '<p>Failed to create screenshot.png file.</p>';
        }
    }
} else {
    print_r('An error occurred: '.$response);
}

Request parameters

Required

html_base64stringRequired

HTML data encoded in base64.

Response example

A successful request returns HTTP 200 with a JSON body:

json · 200
{
    "rendered_file": {
        "format": "PNG",
        "date_time_utc": "2024-11-29 19:05:01",
        "base64_file": "iVBORw0KGgoAAAANSUhEUgAAB4AAAAQ4CAIAAABnsVYUAAAAAXNSR0IArs4c6QAAIABJREFUeJzs3WmYVOWd8OFqa...",
        "image_width": 1920,
        "image_height": 1080,
        "file_size_readable": "14.73 KB",
        "file_size_bytes": 15080
    },
    "elapsed_ms": 5485
}

Response fields

The fields returned in the JSON response:

rendered_file → formatstring

Format of the rendered file, e.g. PNG.

rendered_file → date_time_utcstring

Date and time (UTC) of when the file was rendered.

rendered_file → base64_filestring

The rendered PNG image encoded in base64.

rendered_file → image_widthinteger

Width of the rendered image in pixels.

rendered_file → image_heightinteger

Height of the rendered image in pixels.

rendered_file → file_size_readablestring

File size in human-readable format, e.g. 14.73 KB.

rendered_file → file_size_bytesinteger

File size in bytes.

elapsed_msinteger

Time taken to process the request, in milliseconds.