ToolJutsu
All tools
Creative Tools

Code to Image Converter

Render syntax-highlighted code as a beautiful PNG.

15px
36px
Window chrome
Line numbers
Processed on your device. We never see your files.

How to use Code to Image Converter

What is a code screenshot?

A code screenshot is a still image of a code snippet — usually syntax-highlighted, often with rounded window chrome and a colourful background — designed for sharing somewhere a real <pre> block won’t render. Twitter / X, Instagram, Slack, LinkedIn, blog post hero images, conference talk slides, Notion docs, README banners, recruiter pitches, and bug-report attachments all reach for them. The format was popularised by Carbon (carbon.now.sh) in 2017, then refined by Ray.so, CodeSnap, Polacode and others. The shape is now familiar enough that a code screenshot looks “wrong” without it.

What makes a good code screenshot

Three things:

  • Honest syntax highlighting — keywords, strings, numbers and function names get different colours so the structure of the code reads at a glance, the same way it reads in a real editor.
  • Generous padding — the snippet sits inside a coloured frame so the eye lands on the code, not on the page edge. 24–48 pixels is the sweet spot.
  • High pixel density — code is mostly text, and text only looks sharp at 2× DPI or above. A 1× export looks fuzzy on every modern display; 2× looks crisp everywhere; 3× holds up when printed.

This tool defaults to all three. The five built-in themes — ToolJutsu, Dracula, Monokai, Nord, GitHub Light — cover the common preferences: warm contrast, vibrant pop, neutral pastel, high-contrast light.

How the highlighter works

Every language in the list has a hand-rolled tokeniser in src/lib/utils/code-highlight.ts. The tokeniser walks the source character by character, identifying:

  • Comments — line (//, #, --) and block (/* */, =begin/=end, """…""").
  • Strings — single, double, backtick, with escape-aware termination.
  • Numbers — including decimal points, exponents, and basic hex literals.
  • Keywords — language-specific reserved-word lists.
  • Type names — capitalised identifiers (a heuristic that fits the dominant convention in C-family and TypeScript-style languages).
  • Function calls — identifiers immediately followed by (.
  • Operators and punctuation — coloured slightly differently so the code’s “shape” stands out.

The result is then drawn onto a canvas with the theme’s colours, fixed-width font, and your chosen padding / window-chrome / line-numbers settings. The canvas is exported as a PNG at the chosen pixel ratio.

How to use this Code to Image converter

  1. Paste your code into the Code textarea, or accept the built-in JavaScript sample to see what the output looks like.
  2. Pick the Language. If yours isn’t listed, use “plain text” — the snippet still renders, just without coloured tokens.
  3. Pick a Theme. ToolJutsu is the brand default; Dracula and Monokai have the strongest contrast; Nord is the softest; GitHub Light is the best fit for light-mode posts.
  4. Tweak Font size and Padding to taste. Defaults of 15px font and 36px padding work for most snippets.
  5. Toggle Window chrome on for the macOS-style traffic-light dots, off for a cleaner look. Line numbers toggle is most useful when the snippet is more than ~10 lines.
  6. Pick a Pixel ratio. 2× is right for almost everything; 3× only matters when printing.
  7. Click Render image. The PNG preview appears below; click Download PNG to save.

Quality tips

For Twitter / X, a 2× export at ~12-line height and 600–800 px CSS width looks great in the timeline and crisp in expanded view. For Instagram and LinkedIn, prefer a square-ish aspect — break long lines manually before pasting so the snippet doesn’t stretch horizontally. For blog hero images, 3× DPI at 1200 px wide is the right amount of headroom for retina screens at desktop sizes.

If your code uses long lines that don’t break naturally, the tool will produce a very wide image. Editor-style soft-wrap isn’t done automatically — wrap deliberately in your source for the best visual result.

Privacy

Everything happens in your browser. The tokeniser, the canvas draw, and the PNG encode are all JavaScript on your device. Pasted code (which, in real work, is often proprietary, half-written, or contains credentials you forgot to scrub) never travels across the network. Confirm in the browser Network panel before sharing anything sensitive — but the answer doesn’t change: this page doesn’t talk to any server after it has loaded.

Compatibility notes

The output is a standard PNG. Every image viewer, social platform, chat app, slide deck and CMS displays it correctly. The tool needs a browser that supports canvas.toBlob and ResizeObserver — every browser released since 2020. Code rendered with high pixel ratios may take a moment to encode on older devices; that’s the only performance caveat.

Frequently asked questions

How is this different from Carbon.now.sh?
The output is the same shape — a syntax-highlighted code snippet on a rounded panel with optional macOS-style window chrome — but this converter runs entirely on your device. Carbon ships your code to a server to render. Here the tokeniser, the canvas drawing and the PNG export all run in JavaScript locally; pasted code (which is often proprietary or unfinished) never leaves the browser tab. The five themes are baked in, so there's no theme-server round-trip either.
Which languages does the highlighter support?
Twenty common languages out of the box: JavaScript, TypeScript, JSX, TSX, Python, Rust, Go, Java, C#, C++, Ruby, PHP, SQL, Shell, CSS, HTML, JSON, YAML, Markdown and plain text. The tokeniser is hand-rolled — good enough for screenshot output — and recognises comments, strings, numbers, keywords, type names (capitalised identifiers), and function-call sites. If your language isn't in the list, pick "plain text" — the code still renders with the chosen theme's foreground colour.
Why a hand-rolled tokeniser and not Prism / Shiki?
Prism and Shiki are designed to produce HTML for in-page display where every quirk of the source language is significant. For a static screenshot rendered to canvas, that fidelity is wasted — and Prism's ESM compatibility issues plus Shiki's 5–10 MB bundle weight are real costs. A ~300-line tokeniser specialised for screenshot output gives a comparable visual result at ~1 KB and zero new dependencies. Same precedent as our Excel formula engine and math evaluator — when a library is overkill, hand-roll the part that's actually used.
Can I pick the export size?
Indirectly, yes. The image's CSS dimensions are determined by the code itself (widest line + padding × 2; tallest line stack + padding × 2). The pixel ratio dropdown — 1× / 2× / 3× — controls how many physical pixels make up each CSS pixel. 2× (Retina) is the recommended default for most uses; 3× gives a print-ready result with crisp edges; 1× keeps the file small for chat and email.
Is the code I paste sent anywhere?
No. The tokeniser, canvas drawing, and PNG export are all JavaScript running in your browser tab. Pasted code does not travel across the network and is not logged or stored. The page makes one set of requests when it loads (the JavaScript bundle and stylesheet) and then nothing — you can confirm in your browser's Network panel, or simply switch off Wi-Fi after loading the page; the converter keeps working.

Related tools