Code screenshot (Carbon style) API
Turn source code into a beautiful image like carbon.now.sh: syntax highlighting for 29 languages, 9 themes, window, line numbers, highlighted lines.
Send code and get a picture of it in a macOS-style window, ready for a blog post, a slide, a tweet or a Zalo / Slack message. Highlighting uses highlight.js (BSD-3) with 29 grammars registered one by one (JavaScript, TypeScript, Python, Java, C, C++, C#, Go, Rust, PHP, Ruby, Swift, Kotlin, Dart, SQL, Bash, Shell, PowerShell, JSON, YAML, HTML / XML, CSS, SCSS, Markdown, Dockerfile, diff, INI / TOML, Lua, plain text) and language=auto detection. Themes: dracula (default), monokai, one-dark, github-dark, github-light, nord, night-owl, vscode-dark, solarized-light.
Options: title in the window bar, window=false for a plain card, line_numbers=true with first_line, highlight_lines=3,5-7, font_size, line_height, tab_size, outer padding with a background colour or a diagonal gradient (background2), shadow, and max_columns (longer lines are cut). Text is drawn from JetBrains Mono outlines (SIL OFL), which include Vietnamese, so comments such as // Tính tổng render correctly; characters outside the embedded fonts (emoji, CJK) are left blank with a warning.
Output: png (default, scale 2 for retina), svg (vector, glyphs as paths: identical everywhere) or json (SVG + PNG base64). No headless browser is used; up to 400 lines.
Parameters
| Name | In | Type | Required | Default | |
|---|---|---|---|---|---|
code | body|query | string | yes | Source code (max 30,000 characters, 400 lines); a raw text/plain body also works. | |
language | query|body | string | no | auto | auto or one of: javascript, typescript, python, java, c, cpp, csharp, go, rust, php, ruby, swift, kotlin, dart, sql, bash, shell, powershell, json, yaml, xml, css, scss, markdown, dockerfile, diff, ini, lua, plaintext (aliases such as js, ts, py, sh, html work). |
theme | query|body | string | no | dracula | dracula, monokai, one-dark, github-dark, github-light, nord, night-owl, vscode-dark, solarized-light. |
format | query|body | string | no | png | png, svg or json. |
title | query|body | string | no | Window title, e.g. a file name. | |
window | query|body | boolean | no | true | Draw the window bar with the three buttons. |
line_numbers | query|body | boolean | no | false | Show line numbers. |
first_line | query|body | number | no | 1 | Number of the first line. |
highlight_lines | query|body | string | no | Lines to highlight, e.g. 2,4-6. | |
font_size | query|body | number | no | 14 | Font size in px (8–40). |
line_height | query|body | number | no | 1.6 | Line height as a multiple of the font size (1–3). |
tab_size | query|body | number | no | 4 | Spaces per tab (1–8). |
padding | query|body | number | no | 32 | Outer margin in px (0–200). |
background | query|body | string | no | #abb8c3 | Outer background colour or transparent. |
background2 | query|body | string | no | Second colour for a diagonal gradient background. | |
shadow | query|body | boolean | no | true | Soft shadow under the window. |
max_columns | query|body | number | no | 160 | Longer lines are cut (20–400). |
scale | query|body | number | no | 2 | PNG pixel ratio (1–4). |
Example
curl -X POST "https://apibox.io.vn/v1/code-image" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"code":"const sum = (a, b) => a + b;\nconsole.log(sum(2, 3)); // 5","language":"javascript","format":"json"}'const res = await fetch('https://apibox.io.vn/v1/code-image', {
method: 'POST',
headers: {
Authorization: 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"code": "const sum = (a, b) => a + b;\nconsole.log(sum(2, 3)); // 5",
"language": "javascript",
"format": "json"
}),
});
const data = await res.json();
console.log(data);import requests
res = requests.post(
"https://apibox.io.vn/v1/code-image",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={"code": "const sum = (a, b) => a + b;\nconsole.log(sum(2, 3)); // 5", "language": "javascript", "format": "json"},
timeout=30,
)
print(res.json())<?php
$ch = curl_init('https://apibox.io.vn/v1/code-image');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => ['Authorization: Bearer YOUR_API_KEY', 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => '{"code":"const sum = (a, b) => a + b;\\nconsole.log(sum(2, 3)); // 5","language":"javascript","format":"json"}',
]);
$response = curl_exec($ch);
print_r(json_decode($response, true));Response
{
"language": "javascript",
"theme": "dracula",
"lines": 2,
"width": 344,
"height": 178,
"scale": 2,
"svg": "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"344\" height=\"178\" viewBox=\"0 0 344 178\">…</svg>",
"png_base64": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAArAAAAFkCAIAAABXYZ9F…",
"warnings": [],
"themes": [
"dracula",
"monokai",
"one-dark",
"github-dark",
"github-light",
"nord",
"night-owl",
"vscode-dark",
"solarized-light"
]
}
Use cases
- Code snippets for blog posts, slides and social media
- Bots that post code images to Slack, Discord, Telegram or Zalo
- Course and tutorial material with consistent styling
- Documentation images generated in CI
FAQ
Can I use my own font or theme?
Not yet: the image always uses JetBrains Mono and one of the 9 built-in themes, so the output looks the same everywhere. You can change the outer background and the window title.
How is the language detected?
With language=auto, highlight.js scores the code against the registered grammars and keeps the best one; the result reports it. Set language explicitly for short snippets.
Why is an emoji missing?
Only Latin (including Vietnamese), Greek, common symbols, box drawing and math characters are in the embedded fonts. Missing characters are left blank and a warning is returned with format=json.
Related APIs
QR Code Generator
Generate QR codes as PNG or SVG with one GET request: URLs, text, WiFi logins, vCards, e-mail, SMS, phone and geo links. Custom colours, size and ECC.
|||Barcode Generator
Create Code 128 barcodes for labels, SKUs and shipping with a single request. SVG with human-readable text or PNG, custom height, width and colours.
▭Placeholder Image
Get placeholder images of any size for mockups and tests: /v1/placeholder/600x400.png. SVG with custom text and colours, or a solid-colour PNG.