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-image

Request body

PropertyTypeRequiredDescription
codestringYesSource code to render
langstringNoLanguage for highlighting (e.g. js, ts). Default: js
themestringNoShiki theme. Default: github-dark
formatpng | webp | jpegNoOutput format. Default: png (lossless)
widthnumberNoOptional width
heightnumberNoOptional height
qualitynumberNoOptional quality
showLineNumbersbooleanNoShow 1-based line numbers in a left gutter. Default: false
styleobjectNoOptional 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