Code to Image

Convert code snippets to beautiful images for sharing

By

Developer tools

Detected: stylus
Editor
Loading...
Canvas Preview
1// Try editing this!2function greet(name) {3  console.log('Hello, ' + name)4}5greet('UtilGenie')

Tip: Transparent background works best on PNG.

Runs in your browser. No signup required.

A snippet card rendered in the browser

You edit code in a Monaco pane, pick a language or leave Auto Detect, and choose a theme: Dracula, GitHub Light, Monokai, or Night Owl. The preview card is highlighted with highlight.js and drawn again by html2canvas when you export, so the download is a picture of that card rather than a photo of your whole monitor. Fonts are Fira Code, JetBrains Mono, and Source Code Pro.

Those three fonts are requested from Google Fonts when you select them. The snippet text is not uploaded as a document, but loading the font is a network request. If that request is blocked, the card falls back to whatever monospace the browser already has, and the export can look different from a machine that loaded the font.

Sharing a fragment in a chat or a slide

A pull-request comment, a talk slide, or a bug report often wants a picture instead of a fenced block that the destination will reflow. Set the background to solid, gradient, or transparent, check the preview, then export. Transparent is useful on a slide with its own color, and it is also easy to mis-see if the preview page is white.

Auto Detect is highlight.js guessing from the text. A short fragment can be guessed wrong. Pick JavaScript, Python, JSON, CSS, Bash, SQL, or one of the other listed languages when the colors look off. Unknown text still exports; it just will not be colored richly. The image does not include your editor’s file tree.

Export edges

html2canvas misses some CSS. A gradient that looks right on screen can shift in the PNG. Compare the download before you send it. Very long snippets make a tall image. Split them rather than expecting the card to paginate. Line numbers, when shown, are real text in the card, not a CSS counter, so they should appear in the picture.

Do not export a snippet that contains a live secret, a private key, or a customer token. The image is only as private as the place you paste it. The page does not keep a gallery. Leave the tab and the in-memory editor goes with it. Pair this with the image compressor if the PNG is heavier than the chat allows.

A DOM node, captured at double scale

The preview is a highlighted code block inside a framed div. Download calls html2canvas on that node with scale 2, so the PNG has twice the pixel width and height of the on-screen frame. If that capture throws, the page retries once at scale 1. A second failure produces no file. The default padding is 24 pixels, and the slider runs from 8 to 64. Line height is 1.4.

Themes recolor the highlight classes. The frame can be a solid color, a gradient, or transparent. Transparent capture passes a null background into html2canvas. Fonts are loaded before the capture when the browser exposes a font-ready promise. The code text is not sent to a server.

A frame you can size in your head

Padding is inside the captured node, so raising it from 24 to 48 adds 24 pixels on each side of the code before the scale. At scale 2 those extra 24 pixels become 48 pixels in the PNG. A shadow and a radius are CSS on the frame and are included when the capture can paint them. The window controls are decoration. They are not buttons that run the snippet.

The snippet is whatever you typed. The page does not execute it and does not minify it. JavaScript, CSS, and JSON are all just text for the highlighter. If you need a smaller file after the PNG exists, the image compressor can turn that PNG into a JPEG and will flatten transparency.

Privacy of a pasted snippet

The code stays in the browser. A secret, a token, or a customer query in the editor is still on screen and in the PNG if you download it. Clear the editor and delete the PNG when you are done on a shared machine. A refresh drops the unsaved text.

The capture can fail on a very large snippet because the canvas is big at scale 2. Shorten the code or accept the scale-1 retry. This page does not offer SVG. The color picker is a different tool, for a single color rather than a code card.

What changes the pixel size

Scale 2 multiplies the captured node. A frame that is 640 by 360 CSS pixels becomes a PNG near 1280 by 720, plus anything the browser adds for device pixels inside html2canvas. Padding of 24 on every side is 48 pixels of padding before that scale, and 96 pixels of padding in the file. Moving the slider to 8 shrinks that band. The code font size is a separate control and also scales.

The highlighter colors depend on the theme. They are CSS variables painted into the node, not a post-filter on the PNG. Transparent background passes null into html2canvas so the PNG can keep a clear frame. A JPEG tool later in the chain, including the image compressor, will flatten that clear area. Download only runs when the capture returns a canvas.

How to use Code to Image

  1. 1

    Type or paste your code into the Editor panel.

  2. 2

    Choose a Language, or leave Auto Detect on, then pick a Theme and Font Family.

  3. 3

    Adjust Font Size, Border Radius and Padding, and set the Background to Solid, Gradient or Transparent. Turn Shadow, Line Numbers and Watermark on or off as you like.

  4. 4

    Check the Canvas Preview, then press Download Image (PNG) or Copy to Clipboard.

FAQ

What does this export?

An image of your snippet with syntax highlighting. You can change the theme, font, and background before exporting.

Is the code sent to a server?

No. Highlighting and the image are made in the browser.

Which languages can be highlighted?

Languages supported by the highlighter in the page, including common ones such as JavaScript, Python, and JSON. Unknown code is still drawn as plain text.

Will the image include my editor UI?

The export is the snippet card, not your whole browser window. Check the preview before you download.

Does exporting the picture upload my code?

The image is built in the browser with html2canvas. Choosing Fira Code, JetBrains Mono, or Source Code Pro does load that font from Google Fonts.

Which themes can I use?

Dracula, GitHub Light, Monokai, and Night Owl. The background of the card can be solid, a gradient, or transparent. Check the downloaded PNG, because a gradient can shift in the export.

How large is the PNG compared with the preview?

The capture uses scale 2, so the PNG is twice the preview’s pixel width and height. If that fails, the page retries at scale 1.

What is the padding range?

8 to 64 pixels, opening at 24. Padding is part of the captured node, and scale 2 doubles it in the file.