Skip to content

Code to image converter

Turn code snippets into crisp, shareable images for documentation, slides and social posts.

Live preview

Paste code below, load the sample, or choose a source file to preview your card.

How to use Code to image

  1. Add your snippet. Paste source code into the editor, click Load sample, or drop a source file up to 2 MB.
  2. Style the frame. Pick a Theme, choose a Language or Auto-detect, and set Window header to macOS, Filename, or None.
  3. Emphasize key rows. Toggle Line numbers and enter ranges such as 2-4 in Highlight lines.
  4. Set export quality. Choose Padding from 0 px to 64 px, select 1x, 2x, or 4x Scale, and pick PNG, SVG, JPG, or WebP.
  5. Export or copy. Click Copy PNG for immediate clipboard pasting or Save image to download the finished file.

Everything runs in this browser tab. Nothing you paste or open is uploaded or logged, so it's safe for keys, tokens and private data.

How does local code-to-image rendering work?

The converter tokenizes source text in memory, computes fixed-width monospace metrics, and draws every glyph directly onto an HTML5 Canvas or into standalone SVG markup inside your browser tab. Proprietary API keys, internal functions, and unreleased configuration files never leave your device.

Deterministic tokenization without remote grammars

Traditional screenshot apps often spin up headless browsers on remote servers to render syntax themes. As a private Carbon and Ray.so alternative, this local converter runs without network latency or third-party logging.

Here, a zero-dependency tokenizer classifies keywords, strings, comments, numbers, types, and function names across 16 language modes, including TypeScript, Python, Rust, Go, SQL, YAML, and Bash. Line endings normalize to Unix newlines and tab characters expand to two spaces before layout begins.

Once layout coordinates are calculated, raster exports encode directly from the canvas buffer through the MDN HTMLCanvasElement.toBlob() API at 0.92 quality for lossy formats. If you need to capture styled markup rather than raw source text, you can render HTML and CSS snippets to PNG, JPG or WebP in a separate local workspace.

Opening source files up to 2 MB in one tab

You can paste code directly into the Source code box, click Load sample to inspect a TypeScript SHA-256 helper, or drop a file into the file zone. Accepted extensions cover .ts, .tsx, .js, .py, .rs, .go, .java, .c, .sql, .sh, .json, .yaml, .html, .css, .svelte, and .md up to 2 MB.

When a file loads, its filename populates the window header title and selects the corresponding language mode automatically. A Clear button resets the editor whenever you want to start a fresh snippet.

How do line highlights, window frames, and Retina scaling work?

Choosing consistent framing makes code cards readable across dark documentation sites, light slide decks, and mobile social feeds. Every visual control updates the live canvas preview immediately so you can check pixel dimensions before exporting at 1x, 2x, or 4x Retina scale.

Six built-in themes and three window chrome styles

The Theme selector offers six palettes: Paper light, Ink dark, GitHub light, GitHub dark, Nord slate, and Solarized warm. Light themes pair well with printed handouts and white slide decks, while dark themes stand out in engineering blogs and social timelines.

Under Window header, macOS adds three classic window dots beside an editable title bar, Filename displays a clean header label without dots, and None removes the top chrome entirely. Selecting 0 px (tight) under Padding strips the outer backdrop so the code block sits flush against your layout, while 24 px, 48 px, or 64 px frames the card with balanced breathing room.

Using line numbers and range syntax to call out edits

Toggling Line numbers adds a right-aligned gutter that helps readers follow stack traces or diff references. Leaving it off saves horizontal space when sharing narrow terminal commands or configuration blocks.

The Highlight lines input accepts comma-separated lines and ranges such as 2, 4-5 to tint specific rows and draw a vertical accent bar on the left edge. If your snippet belongs inside a broader README or tutorial card, switch to the Markdown to image converter to render headings, lists, and tables alongside fenced code blocks.

Should you export a code snippet to PNG, WebP, or SVG?

Choose PNG at 2x or 4x scale for social media, chat apps, and presentation slides that expect raster bitmaps, or choose SVG for documentation sites and print layouts that benefit from infinite vector scaling. JPG and WebP keep file sizes smaller when sharing tall snippets over bandwidth-constrained channels.

Raster scaling at 1x, 2x, and 4x for social feeds

Selecting 1x exports at standard 1:1 CSS pixel dimensions, which works for compact thumbnails but can appear soft on high-density displays. Choosing 2x doubles both width and height for sharp Retina rendering, while 4x produces ultra-high-resolution bitmaps suitable for 4K slides and cropped zoom-ins. On wide source files, clampCanvasSize caps output at the Safari 4096 px side limit (16,777,216 pixels) so exports never crash WebKit tabs.

Format Scale support Transparency Best use case
PNG 1x, 2x, 4x Supported Social posts, Slack, GitHub issues, and Retina slides
SVG Infinite vector Supported Technical docs, blogs, and Figma imports
JPG 1x, 2x, 4x Opaque backdrop Lightweight email attachments and legacy CMS uploads
WebP 1x, 2x, 4x Supported Fast-loading web articles with smaller byte size

Standalone SVG vectors without foreignObject

Many online code screenshot tools wrap HTML inside an SVG foreignObject tag, which frequently triggers tainted-canvas SecurityError failures or breaks custom fonts in Safari and vector design apps. This exporter builds pure SVG <rect> and <text> primitives aligned to the W3C Scalable Vector Graphics (SVG) 2 Specification, preventing tainted canvas errors during SVG code export.

Because vector geometry scales independently of pixel density, the Scale buttons disable automatically when SVG is active. If a downstream platform requires a bitmap version of an exported vector card later, pass the file through SVG to PNG to rasterize it at up to 8x resolution.

Tip: Long lines wrap automatically at 100 columns during layout, so keeping snippets under 80 characters per line avoids awkward mid-token wraps in narrow mobile previews.

Clipboard PNG copying and presentation workflows

When you are writing a pull request comment, Slack thread, or slide deck, downloading a file to disk adds unnecessary cleanup steps. The Copy PNG button above the preview renders a fresh bitmap at your chosen theme, padding, and scale, then places it directly onto your system clipboard.

Under the hood, the button invokes the MDN Clipboard.write() API with an image/png ClipboardItem. Once the label switches to Copied PNG, you can paste straight into Notion, Slack, Google Slides, or GitHub without touching your Downloads folder.

When building technical presentations that combine source code with mathematical proofs or algorithm complexity derivations, pair your code cards with clean equation graphics and convert LaTeX equations into transparent PNG figures. For repeatable exports across a team, keeping Padding at 48 px and Scale at 2x ensures every snippet shares uniform proportions.

Questions

Should I export a code screenshot as PNG or SVG?

Choose 2x or 4x PNG for Slack, X, LinkedIn, and slide decks that require bitmap uploads. Choose SVG for technical documentation, blog posts, and print layouts where crisp vector text at any zoom matters.

How do I highlight specific lines in a code image?

Enter single line numbers or hyphenated ranges separated by commas, such as 2, 4-5, inside the Highlight lines field. The renderer draws an accent bar and subtle background tint behind those rows.

Why do 1x code screenshots look blurry on Retina screens?

High-DPI displays pack four physical pixels into each CSS pixel, so a 1x bitmap stretches when viewed at native width. Switching Scale to 2x or 4x renders higher pixel density so monospace glyphs stay sharp.

Does the SVG export use HTML foreignObject?

No. The SVG exporter emits pure vector rect and text elements instead of foreignObject HTML wrappers, which prevents missing fonts and broken rendering in Safari, Figma, and vector editors.

What is the maximum source file size supported?

Dropped or selected source files can be up to 2 MB. Larger files are rejected before reading so the browser canvas and syntax tokenizer remain responsive.

How does language auto-detection work for uploaded files?

When you drop a file such as hash.ts or schema.sql, the editor reads the filename extension and maps it to the matching language grammar automatically, while still letting you override Language manually.

Updated