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.

GETPOSThttps://apibox.io.vn/v1/code-image
Images & Codes▶ Try it online

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

NameInTypeRequiredDefault
codebody|querystringyesSource code (max 30,000 characters, 400 lines); a raw text/plain body also works.
languagequery|bodystringnoautoauto 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).
themequery|bodystringnodraculadracula, monokai, one-dark, github-dark, github-light, nord, night-owl, vscode-dark, solarized-light.
formatquery|bodystringnopngpng, svg or json.
titlequery|bodystringnoWindow title, e.g. a file name.
windowquery|bodybooleannotrueDraw the window bar with the three buttons.
line_numbersquery|bodybooleannofalseShow line numbers.
first_linequery|bodynumberno1Number of the first line.
highlight_linesquery|bodystringnoLines to highlight, e.g. 2,4-6.
font_sizequery|bodynumberno14Font size in px (8–40).
line_heightquery|bodynumberno1.6Line height as a multiple of the font size (1–3).
tab_sizequery|bodynumberno4Spaces per tab (1–8).
paddingquery|bodynumberno32Outer margin in px (0–200).
backgroundquery|bodystringno#abb8c3Outer background colour or transparent.
background2query|bodystringnoSecond colour for a diagonal gradient background.
shadowquery|bodybooleannotrueSoft shadow under the window.
max_columnsquery|bodynumberno160Longer lines are cut (20–400).
scalequery|bodynumberno2PNG 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"}'

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

Start with 1,000 free requests every month. Get free API key →