HTML to Image API

Send HTML. Get back a pixel-perfect PNG, JPG, or PDF. Server-side rendering with headless Chromium — no browser required on your end.

What is an HTML to image API?

An HTML to image API renders HTML and CSS server-side — exactly as a browser would — and returns the result as an image file. Instead of generating images in a canvas or using a client-side library (which breaks on SSR, has font limitations, and produces inconsistent results across environments), you send a structured request to the API and receive a precisely-rendered image back.

SwarmGen uses headless Chromium under the hood, which means every web standard is supported: CSS Grid, Flexbox, custom fonts, gradients, border-radius, box-shadow, background-image, SVG — all rendered exactly as they appear in a modern browser, at whatever pixel density you need.

Why not use canvas or a client-side library?

No SSR support

Canvas-based libraries like html2canvas or dom-to-image don't work in server environments — they need a real DOM. SwarmGen renders entirely server-side.

Font and CSS limitations

Client-side image libraries have partial CSS support. Custom fonts, complex layouts, and CSS variables often render incorrectly. Chromium renders everything.

Environment inconsistency

Results from canvas libraries vary across browsers, OS versions, and screen DPRs. The SwarmGen renderer is fixed and deterministic — same input always produces the same output.

No server load on your end

Rendering is compute-intensive. Running it client-side degrades UX; running it on your own servers requires infrastructure. SwarmGen handles all of it.

API overview

The SwarmGen render API accepts a template ID and a map of merge field values. Templates are created and managed in the SwarmGen editor — your HTML, your CSS, your dimensions. The API then injects your data at render time and returns a CDN-hosted image URL.

POST /api/renders — request
POST https://swarmgen.io/api/renders
Content-Type: application/json
X-API-Key: YOUR_API_KEY

{
  "templateId": "tpl_YOUR_TEMPLATE_ID",
  "format": "png",
  "data": {
    "headline": "Summer Sale — 50% off",
    "sub":      "Valid until 31 August",
    "cta":      "Shop now",
    "bg_color": "#862ec6"
  }
}
Response
{
  "jobId":  "job_abc123",
  "status": "queued"
}

// Poll GET /api/renders/job_abc123 or use webhook_url
// for the final result:
{
  "jobId":  "job_abc123",
  "status": "complete",
  "url":    "https://cdn.swarmgen.io/renders/job_abc123.png"
}

// ⚠ Render URLs expire after 7 days.
// Download the image and re-host it on your own server or CDN
// before referencing it in meta tags, emails, or long-lived pages.

Supported output formats

.png

PNG

Lossless, transparent background support, ideal for OG images and social graphics.

.jpg

JPG

Smaller file size. Best for photographs and email attachments where transparency isn't needed.

.pdf

PDF

Print-quality vector output at any resolution. Ideal for invoices, reports, and certificates.

Rate limits

To maintain render quality and queue fairness, the API enforces two limits per workspace:

  • Maximum 5 render jobs queued or processing at any one time.
  • Maximum 10 render requests submitted per minute.

Requests that exceed either limit receive a 429 response and can be retried once your current jobs complete.

Start rendering HTML as images

Free account includes 50 renders. No credit card required.

Get your API key