User Rating 0.0
Total Usage 0 times
Quick Examples
0 / 10,000
Is this tool helpful?

Your feedback helps us improve.

About

Sharing code as plain text on social media, presentations, or documentation strips away the syntax coloring that makes it readable. A misread operator or overlooked string literal in a screenshot of raw text costs debugging hours. This tool performs real tokenization of your source code using language-specific lexical rules, then renders each token with precise color mapping onto an HTML Canvas at 2× device pixel ratio for retina-sharp output. It supports 12 languages and 8 color themes calibrated to WCAG contrast ratios. The output is a lossless PNG with configurable padding p from 16 to 128px and font sizes from 12 to 32px.

The tokenizer uses greedy regex matching with priority ordering: comments and strings are captured first to prevent keyword false-positives inside literals. Line numbering is optional. Background supports solid colors, linear gradients, or transparent export. Note: this is a lexical highlighter, not a full parser. Nested template literals or polyglot files may produce approximate results. For standard single-language snippets, accuracy matches dedicated editors.

code to image code screenshot syntax highlighting code snippet carbon alternative code image generator png export

Formulas

The canvas dimensions are computed from the code content metrics. For a code block with L lines, font size f, line height multiplier h, and padding p:

W = 2 p + G + max(wi) + pright
H = 2 p + L f h

Where W is canvas width in CSS pixels, H is canvas height, G is the gutter width for line numbers (computed as measureText(L).width + 24px), wi is the pixel width of line i measured via Canvas measureText, and pright is extra trailing padding. For retina export, all dimensions are multiplied by device pixel ratio dpr = 2, then the canvas CSS size is set to logical dimensions via canvas.style.width.

Wphysical = W dpr

Tokenization priority order prevents false matches: 1) multi-line comments, 2) single-line comments, 3) strings (single, double, backtick), 4) numbers, 5) keywords, 6) functions (identifier followed by (), 7) operators, 8) punctuation, 9) plain identifiers.

Reference Data

LanguageToken TypesFile ExtensionsComment Syntax
JavaScriptkeyword, string, template, regex, comment, number, function, operator.js, .mjs// /* */
TypeScriptkeyword, type, string, comment, number, function, operator, decorator.ts, .tsx// /* */
Pythonkeyword, string, f-string, comment, number, decorator, function, builtin.py# """ """
HTMLtag, attribute, string, comment, entity, text.html, .htm<!-- -->
CSSselector, property, value, comment, unit, color, at-rule.css/* */
SQLkeyword, string, comment, number, function, operator.sql-- /* */
Javakeyword, string, comment, number, annotation, function, type.java// /* */
C / C++keyword, string, comment, number, preprocessor, function, type.c, .cpp, .h// /* */
Gokeyword, string, comment, number, function, type, package.go// /* */
Rustkeyword, string, comment, number, macro, lifetime, function, type.rs// /* */
JSONkey, string, number, boolean, null, punctuation.jsonNone
Bashkeyword, string, comment, variable, number, function, operator.sh, .bash#

Frequently Asked Questions

The tool renders at 2× device pixel ratio by default. If you resize the downloaded PNG in an image editor without using nearest-neighbor or bilinear scaling, anti-aliased text degrades. Always use the original exported dimensions, or re-export at a larger font size for higher resolution needs.
This tool uses a lexical tokenizer (regex-based), not an abstract syntax tree parser. It correctly handles 95%+ of standard code patterns including nested strings, multi-line comments, and decorators. Edge cases like heredocs, polyglot embedded languages, or context-dependent keywords (e.g., "type" in TypeScript used as a variable name) may be highlighted approximately. For presentation and social sharing, this level of accuracy is functionally equivalent to IDE output.
Yes. Select the "Transparent" background option. The exported PNG will have an alpha channel. Note that line numbers and code text will render on the transparent background, so ensure your slide background provides sufficient contrast with the theme's text colors.
The tool handles up to 10,000 characters (approximately 300-400 lines) with smooth real-time preview updates. Beyond that limit, the tokenizer and canvas rendering are debounced to 300ms. For extremely long files (1000+ lines), consider exporting only the relevant section, as the resulting PNG dimensions may exceed practical display sizes.
The optional macOS-style window chrome adds three colored circles (close, minimize, maximize) and an optional filename at the top of the code card. This adds approximately 40px of height. It is purely decorative and has no effect on tokenization. Disable it via the "Window Controls" toggle if you need a minimal output.
The tool uses the system monospace font stack: "SF Mono", "Fira Code", "JetBrains Mono", "Cascadia Code", Consolas, "Courier New", monospace. The first available font on your system is selected automatically. Custom font loading from URLs is not supported to maintain offline capability and prevent CORS failures.
No. All processing occurs entirely in your browser. The code never leaves your machine. Tokenization, rendering, and PNG export all happen client-side using the Canvas API. No network requests are made at any point.