Free tool · Developer tools
Code to image
Paste a snippet, choose a language and a theme, and download it as a PNG with colored syntax, optional line numbers and a window frame. The picture is drawn on your device, so the code is never uploaded.
- Free
- No sign-up
- Runs in your browser
1,332 × 654 pxPNG at 2×
- Night
- JavaScript
- Window frame
- Line numbers
- Lines
- 7
- Shape
- 2.04:1
- Language
- JavaScript
- File size
- shown after the picture is made
How to use the Code to Image
- Paste your code into Your code and pick its Language, so keywords, strings and comments get their colors.
- Choose a Color theme and a Background. Use Transparent if the picture will sit on a page of its own color.
- Set the Title on the window bar, switch Window frame and Line numbers on or off, and change the Space around the window and Text size.
- Pick the Sharpness, then press Download PNG, or Copy image to paste it straight into a chat or document.
How do I turn code into an image?
Paste the code into the box and the picture is drawn at once below it. Press Download PNG to save it. The page works like a screenshot of an editor window, except that you control the theme, the margin and the size, and no editor needs to be open. The example is 7 lines of JavaScript that total a shopping cart. At the default settings it comes out 1,332 × 654 pixels, a 2.04:1 shape.
The picture is a drawing made on a canvas in your browser, then saved as a PNG. PNG keeps the sharp edges of text without the smudges a JPEG adds around letters, and it can hold a transparent background. The file never leaves your device, so private code stays private.
Copy image puts the PNG on your clipboard so you can paste it into a chat, a slide or a document without saving a file first. Some browsers refuse clipboard images, and then the page says so. Download PNG works everywhere, and the file is named after the language, for example code-js.png.
Tabs are turned into four spaces so columns line up, and Windows line endings are read as ordinary line breaks. Up to 200 lines and 160 characters per line are drawn. A longer line ends with a dots mark, and a note under the picture says when that happened.
How do I add syntax highlighting, line numbers and a window frame?
Choose the language in the Language box. The page knows 8 of them (JavaScript, TypeScript, Python, SQL, HTML, CSS, JSON, Shell) plus plain text with no color. Highlighting is done by a small set of pattern rules written for this page, not by a full language parser. It colors keywords, strings, numbers, comments, function calls, capitalized names, tags and attributes. The JavaScript example uses 7 different colors.
Because the rules are simple, unusual syntax can be colored a little differently from your editor. A word followed by a bracket is shown as a function call, and a capitalized word is shown as a type. If a snippet looks wrong, check that the language matches, or choose Plain text to see the code uncolored.
The window frame adds a title bar with three dots and the title you type. Turning it off makes the picture 38 pixels shorter at the design size. Line numbers sit in a column on the left, and turning them off makes the example 21 pixels narrower. Numbers help when other people will talk about line 4. Leave them off for a short snippet.
There are 3 themes: Night, Paper, Mono. Night is light text on a dark navy window, Paper is dark text on white, and Mono uses grays only, which survives printing and low-color screens.
What size should a code image be?
The size follows the code. The window is as wide as the longest line and as tall as the number of lines, plus the margin you choose. The example is 666 × 327 pixels at its design size. Sharpness multiplies both numbers: 2× gives 1,332 × 654 pixels and 3× gives 1,998 × 981. Higher sharpness keeps small text clear when the picture is shown larger or on a high-density phone screen, at the cost of a bigger file.
The answer panel shows the exact pixels and the shape as a ratio before you download. A 30-line snippet is much taller than the example: 752 × 1,684 pixels, a 0.45:1 shape. If a platform crops pictures to a fixed shape, shorten the code or increase the margin until the ratio is close to what you need. Platforms change their own limits, so check the current size guidance of the place you post to.
Margin is the other lever. A margin of 0 gives a picture that is only the window, which is right when you will place it on a slide that has its own background. A margin of 48 or 64 pixels gives the backdrop room to show its gradient and the shadow under the window, which is the usual look for a social post.
The very largest sizes are guarded. A browser limits how big a canvas can be, so the page lowers the sharpness by one step at a time until the longest side fits, and the note under the answer says so.
| Setting | Image size | Shape |
|---|---|---|
| Default: frame, numbers, 48 px margin, 14 px text, 2× | 1,332 × 654 px | 2.04:1 |
| 1× sharpness | 666 × 327 px | 2.04:1 |
| 3× sharpness | 1,998 × 981 px | 2.04:1 |
| No margin around the window | 1,140 × 462 px | 2.47:1 |
| No window frame | 1,332 × 578 px | 2.30:1 |
| No line numbers | 1,290 × 654 px | 1.97:1 |
| 18 px text | 1,656 × 786 px | 2.11:1 |
Should I post code as an image?
An image is good for a short snippet that people only need to read: a slide, a social post, a tutorial thumbnail or a README illustration. It keeps your formatting and colors exactly, on every screen.
It is a poor choice when readers need to copy the code. They cannot select text in a picture, and a screen reader has nothing to read unless the picture carries alt text. Put the code in the post text as well, or use it as the alt text, and use a code block for anything longer than a screenful.
If the code is messy, tidy it first. The JavaScript beautifier, HTML beautifier, JSON formatter and SQL formatter each re-indent a snippet, and the result pastes straight into this page.
Is my code uploaded?
No. Pasting, coloring, drawing and saving all happen in your browser, and the page makes no request with your code. That also means the picture uses the monospace font of your own device, so text widths can differ a little between a phone and a laptop.
Clear removes the code from the box. Nothing is stored between visits.
Use it with
- JSON Formatter: format and validate JSON.
- JavaScript Beautifier: format or minify JS.
- HTML Beautifier: format or minify HTML.
Questions
How do I turn code into a nice image?
Paste it, choose the language and a theme, then press Download PNG. The 7-line example becomes a 1,332 × 654 pixel picture with a window frame and line numbers.
How do I make a code screenshot with syntax highlighting?
Pick the language so keywords, strings, numbers and comments get colors. 8 languages are covered, plus plain text.
Can I export the picture as SVG?
No. This page saves PNG only. Choose 3× sharpness if you need a larger, clearer picture.
Can I add line numbers and a window frame?
Yes, both are check boxes under Show. You can also type the title that appears on the window bar, such as a file name.
What image size works for posts?
It depends on the code and the platform. The page shows the exact pixel size and shape before you download, and 1×, 2× and 3× sharpness scale it. The example is 666 × 327 at 1×.
Is my code sent to a server?
No. The picture is drawn in your browser and saved on your device.
The tool's results are computed in your browser by the code on this page; the explanations are checked against the tool's own output.