HTML to Image.Crisp and ready.

Back

HTML to Image

Send a complete HTML document (CSS included) and receive it back as a PNG or JPEG image, base64 encoded. Each successful render costs one file credit from your plan.

Authentication

Every request needs your API secret key in theAuthorization header as a Bearer token. Your email must be verified and your plan must include this feature with credit remaining.

Authorization: Bearer pigdf_your_api_secret_key

Endpoint

POSThttps://pigdf.com/api/render/html-to-image/

Request

The body is JSON with a required content field holding your HTML, and an optional options object.

curl -X POST https://pigdf.com/api/render/html-to-image/ \
  -H "Authorization: Bearer pigdf_your_api_secret_key" \
  -H "Content-Type: application/json" \
  -d '{
    "content": "<h1>Hello Image</h1>",
    "options": {
      "format": "png",
      "image_size": { "width": 1280 }
    }
  }'

All options, annotated

Every option is optional. This example sends all of them at once, with each default noted. Leave options out entirely and you get a full-page JPEG at 1280 pixels wide.

{
  "content": "<h1>Dashboard</h1>",               // required: your full HTML document (up to 25 MB)
  "options": {
    "format": "png",                              // default: "jpeg". Either "png" or "jpeg". Safe to delete.
    "image_size": { "width": 1280, "height": 720 }, // default: 1280 wide, full page. Both 1-20000 px. Width only = full page at that width. Safe to delete.
    "transparent": true,                          // default: false. PNG only, ignored for jpeg. Safe to delete.
    "quality": 80,                                // default: 80. JPEG only (1-100), ignored for png. Safe to delete.
    "scale": 2                                    // default: 1. Device pixel ratio 1-3 for sharper output. Safe to delete.
  }
}

// JSON does not allow comments. Remove the comments above before sending.

Options

OptionTypeRequiredDefaultExampleNotes
formatstringNo"jpeg""png"Either png or jpeg. Any other value falls back to jpeg.
image_sizeobjectNo1280 wide, full page{ "width": 1280, "height": 720 }width and height in pixels, each between 1 and 20000. Width only captures the full page at that width. Leave it out for a 1280 wide full-page capture.
qualitynumberNo8060JPEG quality between 1 and 100. Applies to jpeg only, ignored for png.
transparentbooleanNofalsetrueTransparent background. Applies to png only, ignored for jpeg.
scalenumberNo12Device pixel ratio between 1 and 3 for sharper, higher resolution output.

Response

Every response uses the same envelope: success, errors, and data. On success the image arrives base64 encoded in data.content; decode it and save it as a file.

{
  "success": true,
  "errors": [],
  "data": {
    "content": "iVBORw0KGgoAAAANSUhEUgAABAAAAAK8CAYAAA..."
  }
}

Errors

When something is wrong, success is false, data is empty, and errors holds one or more messages. The HTTP status tells you the category.

{
  "success": false,
  "errors": ["Your current plan does not include this feature."],
  "data": {}
}
StatusWhen it happensMessage
400The body is not valid JSON.Invalid JSON.
400The content field is missing or empty.A non-empty "content" field is required.
401The API secret key is missing or wrong.You are not authorized to use this API.
403Your email is not verified.Please verify your email address to use this API.
403Your plan does not include this feature.Your current plan does not include this feature.
408The render took longer than 30 seconds.Rendering took longer than 30 seconds.
413The HTML you sent, or the image produced, is larger than 25 MB.The content exceeds the 25 MB limit.
429You have used all your credit for this feature.You have used all your credit for this feature.
502The HTML could not be rendered.The content could not be rendered to an image.

Limits

The HTML you send and the image you receive are each limited to 25 MB.

Rendering is limited to 30 seconds per request.

Failed requests never spend a credit. Only a successful render does.