01What is Code to Image?
Social feeds, slide decks and many chat apps don't render code blocks. Paste a snippet there and you lose the indentation, the colors and half the readability. Code to Image fixes that by drawing your code as a PNG that looks like a small editor window. Here is how it works. You paste code into the Code box and pick one of twelve languages: JavaScript, TypeScript, Python, Go, Rust, Java, CSS, HTML, JSON, Bash, SQL or plain text. Each line runs through a small regular-expression tokenizer. It finds comments first, then quoted strings (double, single and backtick), then numbers and hex colors like #ff6b35, then HTML tags, and finally words. A word is colored as a keyword if it is on that language's keyword list. If it sits right before an opening parenthesis, it gets the function color instead. The image itself is drawn on an HTML canvas. You get a rounded window with the red, yellow and green dots, your file name centered in the title bar, and a two-color diagonal gradient behind it. There are five gradients (Sunset, Violet, Mint, Steel, Rose) plus None, which drops the padding and exports only the window. Four themes are available: Night, Ocean and Forest are dark, and Paper is light. Tabs become two spaces before drawing. The export scale (1x, 2x or 3x) multiplies the canvas pixels, so a 2x export is twice as wide in pixels as the preview. A quick example. Pick JavaScript and type const total = sum(items, 0.5); // add. The tool colors const as a keyword, sum as a function, 0.5 as a number and the trailing // add as a comment. The rest stays in the theme's plain text color. Download PNG saves the file named after your title, so debounce.js becomes debounce.png. Copy image uses the browser Clipboard API to put the PNG on your clipboard. Some browsers refuse image writes, and the page tells you when that happens. Your snippet never leaves the tab, because the canvas is rendered locally and nothing is uploaded. Now the honest part. The tokenizer works line by line, so a /* comment */ that spans several lines is only colored when it opens and closes on the same line. SQL keywords match in all lower case or all upper case only, so Select stays uncolored. Template literals are colored as one string, including any ${} inside. For a social card these rough edges rarely matter, but check the preview before you post.
Developers who post code tips on social media, and speakers or writers who need a crisp snippet image for slides and articles. The tool runs entirely in your browser, so your data never leaves your device.
02How to use Code to Image
- Paste your snippet into the Code box
- Pick the Language, Theme and Background from the dropdowns
- Type a name in File name / title, or clear it to leave the title bar empty
- Adjust the Padding and Font size sliders, and tick Line numbers if you want them
- Choose an Export scale of 1x, 2x or 3x
- Click Download PNG, or Copy image to paste it straight into another app
03Worked examples
- Input:
JavaScript: const total = sum(items, 0.5); // add - Result:
keyword: const | function: sum | number: 0.5 | comment: // add | plain: total, items, punctuation - Token classes from the tool's tokenizer. Each class gets its color from the chosen theme.
- Input:
Python: def greet(name): return f"hi {name}" # py - Result:
keyword: def, return | function: greet | string: "hi {name}" | comment: # py - The f prefix stays plain. Only the quoted part is colored as a string.
- Input:
SQL: SELECT id FROM users where age > 21 -- adults - Result:
keyword: SELECT, FROM, where | number: 21 | comment: -- adults - Upper and lower case keywords both match. Mixed case like Select does not.
- Input:
CSS: .btn { color: #ff6b35; } /* x */ - Result:
number: #ff6b35 | comment: /* x */ | everything else plain - Hex colors use the number color. The CSS keyword list is empty, so property names stay plain.
- Input:
HTML: <div class="x">hi</div> - Result:
tag: <div, >, </div, > | string: "x" | plain: class, =, hi - Tag names and brackets get the tag color. Attribute names are not colored separately.
- Input:
JavaScript, two lines: /* start of a / multi-line comment */ - Result:
Line 1: /* plain, start plain, of keyword, a plain | Line 2: all plain - Shows the line-by-line limit. A block comment split across lines is not colored as a comment.
04Common use cases
- Posting a short code tip on X or LinkedIn, where pasted code loses its indentation
- Dropping a colored snippet onto a light conference slide with the Paper theme and no background
- Showing the before and after of a small refactor in a chat thread or pull request comment
- Making a header image for a blog post or newsletter issue about a specific function
- Sharing a SQL query with a teammate on a tool that strips monospace formatting
- Building a series of cheat-sheet images with the same theme and gradient for a dev account
05Tips
- Choose Background None when you want a tight crop: it removes the padding entirely, not just the gradient
- The file name you type sets the download name, with the extension swapped for .png, so debounce.js saves as debounce.png
- Write SQL keywords in all caps or all lower case. Mixed case like Select is not on the keyword list and stays uncolored
- Close block comments on the same line they open. The tokenizer reads one line at a time, so multi-line comments come out in plain text
- Use 3x export for print or a projector, and 2x for social posts, since every step adds more pixels to upload
06Related concepts
code screenshot, syntax highlighting, HTML canvas, Clipboard API, canvas toBlob, device pixel ratio.
Frequently Asked Questions
What is Code to Image?
Code to Image is a free, browser-based developer tool on AIDToolStack. Turn a code snippet into a clean PNG with syntax colors, a window frame and a gradient background. It requires no installation or sign-up and works entirely in your browser.
Is Code to Image free to use?
Yes. No sign-up, no fees and no usage cap.
Does Code to Image store my data?
No. It runs in your browser; nothing is uploaded.