HTML to image converter
Paste HTML and CSS, preview it live, then download the image or copy a URL that renders a new one for every value you pass.
Generate it on demand
Variables
Image URL
Open Graph image templates
Start from a social card that already works as a link preview. Each one is plain HTML and CSS, so every word and color is yours to change.
How to convert HTML to an image
Paste your HTML
Set the size
Generate
Download or embed
Social media image sizes
HTML to image API
The image URL is one API call. scripts writes your HTML into the page and fills it from the url, screenshot captures it, and embed answers with the image itself.
The following examples show how to use the Microlink API with cURL, JavaScript, Python, Ruby, PHP & Golang, targeting 'https://example.com/?title=Hello%20from%20the%20URL' URL with 'scripts', 'viewport', 'screenshot', 'meta' & 'embed' API parameters:
cURL Microlink API example
curl -G "https://api.microlink.io" \
-d "url=https%3A%2F%2Fexample.com%2F%3Ftitle%3DHello%2520from%2520the%2520URL" \
-d "scripts=document.body.innerHTML%20%3D%20'%3Ch1%20style%3D%22font%3A%2072px%20system-ui%22%3E%3C%2Fh1%3E'%3B%20document.querySelector('h1').textContent%20%3D%20new%20URLSearchParams(location.search).get('title')" \
-d "viewport.width=1200" \
-d "viewport.height=630" \
-d "screenshot=true" \
-d "meta=false" \
-d "embed=screenshot.url"JavaScript Microlink API example
import createClient from 'microlink.io'
const microlink = createClient()
const data = await microlink.screenshot('https://example.com/?title=Hello%20from%20the%20URL', {
scripts: "document.body.innerHTML = '<h1 style=\"font: 72px system-ui\"></h1>'; document.querySelector('h1').textContent = new URLSearchParams(location.search).get('title')",
viewport: {
width: 1200,
height: 630
}
})Python Microlink API example
import requests
url = "https://api.microlink.io/"
querystring = {
"url": "https://example.com/?title=Hello%20from%20the%20URL",
"scripts": '''document.body.innerHTML = '<h1 style="font: 72px system-ui"></h1>'; document.querySelector('h1').textContent = new URLSearchParams(location.search).get('title')''',
"viewport.width": "1200",
"viewport.height": "630",
"screenshot": "true",
"meta": "false",
"embed": "screenshot.url"
}
response = requests.get(url, params=querystring)
print(response.content)Ruby Microlink API example
require 'uri'
require 'net/http'
base_url = "https://api.microlink.io/"
params = {
url: "https://example.com/?title=Hello%20from%20the%20URL",
scripts: 'document.body.innerHTML = \'<h1 style="font: 72px system-ui"></h1>\'; document.querySelector(\'h1\').textContent = new URLSearchParams(location.search).get(\'title\')',
"viewport.width": "1200",
"viewport.height": "630",
screenshot: "true",
meta: "false",
embed: "screenshot.url"
}
uri = URI(base_url)
uri.query = URI.encode_www_form(params)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri)
response = http.request(request)
puts response.bodyPHP Microlink API example
<?php
$baseUrl = "https://api.microlink.io/";
$params = [
"url" => "https://example.com/?title=Hello%20from%20the%20URL",
"scripts" => 'document.body.innerHTML = \'<h1 style="font: 72px system-ui"></h1>\'; document.querySelector(\'h1\').textContent = new URLSearchParams(location.search).get(\'title\')',
"viewport.width" => "1200",
"viewport.height" => "630",
"screenshot" => "true",
"meta" => "false",
"embed" => "screenshot.url"
];
$query = http_build_query($params);
$url = $baseUrl . '?' . $query;
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET"
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #: " . $err;
} else {
echo $response;
}Golang Microlink API example
package main
import (
"fmt"
"net/http"
"net/url"
"io"
)
func main() {
baseURL := "https://api.microlink.io"
u, err := url.Parse(baseURL)
if err != nil {
panic(err)
}
scriptsParam := `document.body.innerHTML = '<h1 style="font: 72px system-ui"></h1>'; document.querySelector('h1').textContent = new URLSearchParams(location.search).get('title')`
q := u.Query()
q.Set("url", "https://example.com/?title=Hello%20from%20the%20URL")
q.Set("scripts", scriptsParam)
q.Set("viewport.width", "1200")
q.Set("viewport.height", "630")
q.Set("screenshot", "true")
q.Set("meta", "false")
q.Set("embed", "screenshot.url")
u.RawQuery = q.Encode()
req, err := http.NewRequest("GET", u.String(), nil)
if err != nil {
panic(err)
}
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
panic(err)
}
fmt.Println(string(body))
}import createClient from 'microlink.io'
const microlink = createClient()
const data = await microlink.screenshot('https://example.com/?title=Hello%20from%20the%20URL', {
scripts: "document.body.innerHTML = '<h1 style=\"font: 72px system-ui\"></h1>'; document.querySelector('h1').textContent = new URLSearchParams(location.search).get('title')",
viewport: {
width: 1200,
height: 630
}
})