Rendering
Render code snippets as images
Render source code with syntax highlighting to PNG, WebP, or JPEG. No API token required.
Rendering
Render code snippets as images
Render source code with syntax highlighting to PNG, WebP, or JPEG. No API token required.
POST
/api/code-to-imageRequest body
| Property | Type | Required | Description |
|---|---|---|---|
| code | string | Yes | Source code to render |
| lang | string | No | Language for highlighting (e.g. js, ts). Default: js |
| theme | string | No | Shiki theme. Default: github-dark |
| format | png | webp | jpeg | No | Output format. Default: png (lossless) |
| width | number | No | Optional width |
| height | number | No | Optional height |
| quality | number | No | Optional quality |
| showLineNumbers | boolean | No | Show 1-based line numbers in a left gutter. Default: false |
| style | object | No | Optional style options |
Responses
200
Image (data URL or binary depending on format)
400
Missing or invalid code
500
Failed to generate code image
Request
curl -X POST "https://bannx.com/api/code-to-image" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-d '{"code":"console.log(\"hello\")","lang":"string","theme":"string","format":"png","width":0}'Response
// Binary image (image/png, image/svg+xml, or image/webp)
// Or data URL for inline format