Convert HTML to an image with PHP.

To see it work, take a look at the Live demo.

Autogenerate images from code

  • Renders exactly like the latest version of Google Chrome

  • Convert HTML/CSS into PNG, JPG or WebP

  • Simple REST API

Plain PHP example

This script will send HTML/CSS to the API and get back a URL to your new image. You'll need an API key to use this example.

If you'd like to try it out first without writing any code, take a look at the demo.

$html = "<div class='box'>Generated from PHP ✅</div>";
$css = ".box { border: 4px solid #03B875; padding: 20px; font-family: 'Roboto'; }";
$google_fonts = "Roboto";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'html='.$html.'&css='.$css.'&google_fonts='.$google_fonts);
curl_setopt($ch, CURLOPT_POST, 1);
// Retrieve your user_id and api_key from
curl_setopt($ch, CURLOPT_USERPWD, "user_id" . ":" . "api_key");
$headers = array();
$headers[] = "Content-Type: application/x-www-form-urlencoded";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
curl_close ($ch);
$res = json_decode($result,true);
echo $res['url'];

PHP example with Guzzle library

This example uses the Guzzle library. Installation instructions are here.

require 'vendor/autoload.php';
$html = "<div class='ping'>Pong ✅</div>";
$css = ".ping { padding: 20px; font-family: 'sans-serif'; }";
$client = new GuzzleHttpClient();
// Retrieve your user_id and api_key from
$res = $client->request('POST', '', [
'auth' => ['user_id', 'api_key'],
'form_params' => ['html' => $html, 'css' => $css]
echo $res->getBody();
// {"url":""}

More examples

For more advanced examples, take a look here.