elefcode

Code to Image

Turn a code snippet into a PNG or SVG for a README, slide or social post.

Background
Code
Preview 0 × 0 px

Advertisement

Guide

About the Code to Image

Code pasted into a slide or a social post usually loses its formatting, its colours, or both. Exporting it as an image keeps it exactly as intended — and on platforms that show image previews, a screenshot of code reads far better than a wall of monospace text.

Paste a snippet, choose a theme and background, and download a PNG or SVG. Nothing is uploaded.

When an image is the right choice

Images are good for slides, social posts, blog headers and anywhere the code is being shown rather than used. They are the wrong choice when someone needs to copy the code — an PNG cannot be selected, searched, or read by a screen reader. In documentation and READMEs, a fenced code block is almost always better; save the image for the places that cannot render one. If you need both, the SVG export keeps the code as real, selectable text.

How the rendering works

The snippet is tokenised with a syntax highlighter, every run of text is measured, and the result is drawn onto a canvas (or written as SVG) rather than screenshotted from the page. Measuring matters: Chinese, Japanese and Korean characters and emoji are wider than other letters, and assuming a fixed width would push the rest of the line out of place. Because the preview and both exports come from the same layout, what you download is exactly what you saw. The text uses the same monospace font on every machine, so the image does not change with whatever fonts happen to be installed.

Themes and readability

Ten editor themes are included — One Dark, Dracula, GitHub Dark and Light, Nord, Monokai, Tokyo Night, Catppuccin Mocha and Solarized Dark and Light — and any of them can sit on any background. For presentations, a light theme usually projects better than a dark one, since projectors wash out dark backgrounds. For social posts the reverse tends to be true. Font size matters more than theme: 16px or larger survives being viewed on a phone.

Keep the snippet short

The most common mistake is pasting too much. An image of forty lines is unreadable at the size most people will see it. Ten to fifteen lines showing one idea works far better — trim the imports, drop the error handling, and keep only the part you are actually talking about. Highlighting the two or three lines that matter helps more than any theme. Code copied from deep inside a file keeps its indentation; “Remove common indent” shifts it back to the left edge.

How to use it

  1. 1Paste your code and pick the language, or leave it on auto-detect.
  2. 2Choose a theme, background and shape, and adjust the font size and padding.
  3. 3Highlight the lines that matter, and wrap long lines if the image gets too wide.
  4. 4Toggle the window bar, line numbers or background to taste.
  5. 5Download the PNG, or copy it straight to your clipboard.

Frequently asked questions

Is my code uploaded anywhere?

No. Highlighting and rendering both happen in your browser, and the PNG is produced locally from a canvas. Nothing is sent to a server.

What resolution is the exported image?

Choose 1×, 2× or 3× — 2× is the default and stays sharp on retina screens. The pixel dimensions are shown above the preview. For something that scales to any size, download the SVG instead.

Can I get a transparent background?

Yes. Choose “None” in the background row and only the code window remains, on transparency.

Can I highlight specific lines?

Yes. Type line numbers or ranges such as 3, 8-10 into “Highlight lines”. If your snippet comes from the middle of a file, set the first line number to match.

What size works for Twitter/X or LinkedIn?

Pick 16:9 for X and slides, 1:1 for a square post, or 4:5 for Instagram and LinkedIn. The background grows to that shape around the code.

Why does Copy image not work in my browser?

Writing images to the clipboard is restricted in some browsers, particularly older Firefox. The tool tells you when that happens; Download PNG works everywhere.

Which languages are supported?

About 40, including JavaScript, TypeScript, JSX, Python, Go, Rust, Java, C, C++, C#, PHP, Ruby, Swift, Kotlin, Dart, Scala, SQL, GraphQL, Bash, PowerShell, JSON, YAML, TOML, HTML, CSS, Dockerfile and diff. Auto-detect handles anything else.

Learn more