🚀 Experience the new and improved APIVoid! Check out what's new

HTML to PNG API: Convert HTML code to PNG image

A JSON API to convert HTML to a PNG or JPG image file, take a screenshot of a custom HTML code. Use this API to convert HTML to high-quality PNG images, perfect for sharing, archiving, and presentations.

Consumes 20 credits per API call

# Example Curl request from the command line:
                          
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=="}'

# Example JSON output for a 200 HTTP status code:

{
    "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
}
Code analysis

Key Features

Convert custom HTML code into high-quality PNG image

Businesses and startups use this HTML to PNG API to convert custom HTML code (such as a newsletter template, a HTML template page, a HTML invoice, an so on) into PNG image.

HTML Code to image

This API can efficiently convert custom HTML code into a PNG (or other formats) image file.

PNG, JPEG, WEBP, AVIF

The generated image file can be in different formats, such as PNG (default), JPEG, WEBP, AVIF.

High-Quality Screenshot

The API will create a high-quality image screenshot of your custom HTML code, you'll love it!

Fast Response

The image is generated in 10-15 seconds on average, depends on the complexity of the HTML code.

Common Use Cases

Take a look at some real-world use cases of this API service

Our API can be used in many ways, from cybersecurity tasks to marketing/research tasks. Here we showcase the most popular use cases according to our customers usage:

HTML Invoice to Image

Convert custom HTML invoice-like web pages into high-quality images for testing how it looks.

Test HTML Code

Easily take a screenshot of a custom HTML code, e.g a web template page or a newsletter template.

Render HTML to Image

Need to rended some HTML code to image? Just send it encoded in base64 and wait a few seconds.

Automate Tasks

Use this API to effortlessly automate any manual task of converting HTML to images in no time.

Use cases

USAGE EXAMPLE

Learn how seamless it is to add and use HTML to PNG API anywhere you want

All it takes is a HTTPS POST request with JSON payload to our endpoint, and you’ll receive the response within seconds, usually within 10-15 seconds. Here are a few code examples to use the API:

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

$apiUrl = 'https://api.apivoid.com/v2/html-to-png';
$apiKey = 'your_api_key_here';

$ch = curl_init($apiUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json', 'X-API-Key: ' . $apiKey]);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['html_base64' => $html_base64]));
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

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'])) {
        $save_as = realpath(dirname(__FILE__)) . "/screenshot.png";
    
        file_put_contents($save_as, base64_decode($responseData['rendered_file']['base64_file']));
    
        if (file_exists($save_as)) {
            echo '<p><img src="screenshot.png" alt="screenshot" class="img-responsive" /></p>';
        } else {
            echo '<p>Failed to create screenshot.png file.</p>';
        }
    }
}

Start using our API services, it takes just a few minutes

Create your account, pick a subscription plan, and make your first API call instantly with your API key—simple as that!

Get started now