Code to Image Converter
Turn code into beautiful PNG images with 6 editor themes, syntax coloring, macOS window controls and gradient backgrounds. Great for sharing on social media.
Runs in your browser. No data leaves your device.
About this tool
Turns a code snippet into a PNG image styled like an editor window, with a theme, optional gradient backdrop and macOS-style window dots. Aimed at developers sharing code on social media, in slides or docs. Rendering is done directly on an HTML canvas with a simple built-in highlighter.
Features
- 6 themes: Midnight, Dracula, Monokai, GitHub Light, Solarized Dark, Ocean, selectable from a dropdown or clickable theme swatches
- Heuristic syntax coloring: // and # line comments (italic), single/double/backtick strings, and bold keywords from a fixed list covering common JavaScript, Python and C-style/Java-style words
- Optional free-text language label drawn in the top-right of the window (default "javascript")
- Font size 12-24 px, padding 16-64 px (step 4), border radius 0-16 px
- Background toggle: a diagonal gradient derived from the theme color around the window; off gives a tight crop
- Window Controls toggle: title bar with red/yellow/green dots
- Live canvas preview that updates on every change
- Exports at 2x scale for sharp text on high-DPI screens
How to use it
- Paste code into the Code box (a Fibonacci example is preloaded)
- Pick a theme and adjust font size, padding, radius, background and window controls
- Optionally type a language label
- Click Download PNG
Inputs
- Plain text code of any language, pasted or typed; lines are drawn as-is with no wrapping, and tabs are drawn as 2 spaces
- Only the first 300 lines are drawn (a note says so when more are pasted)
Outputs
- PNG file named code-snippet-<theme-id>.png at 2x pixel density
- Image width grows with the longest line as actually measured (wide CJK and emoji characters included; minimum 240 px window) and height with the line count
Limits and notes
- Highlighting is not language-aware: the language label is display text only and does not change coloring; there is no real parser, so numbers, functions and operators are not colored and block comments are not recognized
- Uses the first installed font from Fira Code, JetBrains Mono, Source Code Pro, Cascadia Code, Consolas, Courier New, monospace; no web font is loaded
- Long lines are not wrapped, so very wide code produces very wide images
- No copy-to-clipboard of the image; download only
- Settings are not saved between visits (no localStorage)
- Runs entirely in the browser; nothing is uploaded
Frequently Asked Questions
How does Code to Image work?
The tool draws your code directly onto an HTML canvas. Each line is split by a small built-in tokenizer into comments (// or #), strings (single, double or backtick quotes), keywords from a fixed list, and plain text, and each token is drawn in the selected theme's color (comments italic, keywords bold). The window, optional title bar with red/yellow/green dots, language label and optional gradient background are drawn on the same canvas, which is rendered at 2x scale and saved as a PNG. Everything happens in your browser.
What programming languages are supported?
You can paste code in any language. Coloring is heuristic rather than language-aware: it highlights // and # line comments, quoted strings, and a fixed set of common keywords from JavaScript, Python and C/Java-style languages. The Language Label field only sets the text shown in the corner of the image; it does not change the highlighting.
Can I customize the look?
Yes. Choose one of 6 themes (Midnight, Dracula, Monokai, GitHub Light, Solarized Dark, Ocean), set font size (12-24 px), padding (16-64 px) and border radius (0-16 px), toggle the macOS-style window controls, toggle the gradient background (its colors come from the theme), and add an optional language label.
What resolution is the exported image?
Images are exported as high-resolution PNGs suitable for presentations, blog posts, social media, and documentation. The text remains sharp and readable at any size.