Works on this device
Code to Image
Paste your code, choose its language and a colour theme, and the page draws it as a picture. You choose the font size, the padding and the line numbers. Download the picture as a PNG file or copy it to paste into a post, a slide or a chat. The picture is drawn in your browser and is not sent anywhere.
Your code
A whole number from 8 to 48.
The space round the code: 0 to 200.
Shown as one line above the code, such as app.js. Up to 80 characters.
A whole number from 1 to 1,000,000.
Up to 1,000 lines and 50,000 characters. The code is drawn on this device and is not sent anywhere.
UTF-8 text up to 1 MB. The language is chosen from the end of the file name.
Ready. Paste some code or choose Try an example.
Your picture
Your picture will show here.
- Size of the PNG
- Size on a page at scale 1
- Lines
How to make a picture of your code
- Choose the Language of your code and a Colour theme. If you open a file from your device, the language is chosen from the end of its name.
- Paste or type your code. The picture under Your picture is drawn again as you type.
- Set the Font size and the Padding (the space round the code) in pixels. Tick Show line numbers to number the lines, and set the first number if the code starts later in a file.
- Type a File name or title if you want one line at the top of the picture, such as
app.js. - Choose the Image scale. A scale of 2 makes a picture with twice as many pixels across and down, so it stays sharp on phones and high-resolution screens.
- Choose Download the PNG to save the picture, or Copy the picture to paste it into another program.
How the picture is laid out
- The colours of the code come from the Syntax Highlighter: the same small readers mark keywords, text in quotes, comments and the other parts, for the same 20 languages.
- The font is the fixed-width font of your device (for example Consolas on Windows or Menlo on a Mac). No font is downloaded, so the picture can look a little different on another device.
- Line height = the font size × 1.5, rounded to whole pixels. Each line of code takes one line height.
- Height = 2 × padding + the number of lines × line height. A title adds one and a half line heights.
- Width = 2 × padding + the width of the longest line (and of the line numbers, with one font size of space after them), rounded up to whole pixels.
- Pixels in the PNG = width and height × the image scale.
- A tab moves to the next tab stop of the tab width you choose (2, 4 or 8 spaces).
- Comments are drawn in italics, so they differ from the code by more than colour.
Worked example
Five lines of code with a font size of 16 pixels, padding of 32 pixels and no title: the line height is 16 × 1.5 = 24 pixels, and the height is 2 × 32 + 5 × 24 = 184 pixels. With the title fizzbuzz.js it is 184 + 24 + 12 = 220 pixels. At an image scale of 2, the PNG is 440 pixels high.
Limits you should know
- Up to 1,000 lines and 50,000 characters. The PNG can be at most 8,192 pixels on a side and 16,777,216 pixels in all, because some browsers cannot draw a larger picture. Choose a smaller scale or font size for long code.
- Long lines are not wrapped. A very long line makes a very wide picture.
- Letters of some languages and emoji can be wider than the other characters, so they may not line up in columns.
- A picture of code cannot be searched or copied as text. When you share code for others to use, share the text too, or use the HTML from the Syntax Highlighter.
- This page does not read text or QR codes from a picture, and it does not turn a picture of a design into HTML.