Code to Image
Turn a code snippet into a clean PNG — pick a theme, font size and padding, preview it on canvas and download the image.
Code travels badly as text: chat apps mangle indentation, slides shrink it, and social feeds crop it. A rendered image keeps the layout exactly as you framed it. The sizing here is deliberately simple monospace maths, and the page shows its working. Each character is counted as 0.6 times the font size wide, the longest line sets the content width, and padding is added on both sides. Worked example: a snippet whose longest line is 10 characters, at a 16 px font size with 24 px padding, gives 2 × 24 + 10 × 16 × 0.6 = 144 px wide — the imageWidth result the result line reports before you download. Line counting is equally literal: a snippet of a, b and c on 3 separate lines counts as 3 lines, and even an empty snippet counts as 1 line, because an image still needs one line of height.
The image is rendered locally on a canvas in this browser from the code you paste. Your code is never uploaded, stored or put into a link; it stays in this page on your device, and the PNG is created only when you click Download.
Quick answers
How do I turn code into an image?
Paste the snippet, pick a theme, font size and padding, and download the PNG. The width follows the longest line: 10 characters at 16 px font with 24 px padding renders 144 px wide.
Rendering is plain single-colour monospace on a canvas in your browser — no highlighting library and no upload.
Why is my code image so wide?
Because one line is long. Width is 2 × padding plus the longest line times 0.6 × font size, with no wrapping, so a single 120-character line dominates the whole image.
Break or trim that line before pasting and the image shrinks proportionally — the result line previews the exact pixel size.
How to use
- Paste your code snippet into the box — keep it short; a function or a single example reads far better in an image than a whole file.
- Pick the dark or light theme, then set the font size and the padding around the code.
- Check the reported dimensions: the width is calculated from the longest line, so one very long line makes a very wide image — wrap or trim it first if that happens.
- Download the PNG. The image is rendered locally on a canvas; share it wherever an image can go.
About this tool
Two honest limits. First, this is a plain rendering, not a syntax highlighter: every character is drawn in one colour, which keeps the image clean and the tool dependency-free, but languages will not be colour-coded. Second, the 0.6 character-width factor is the standard monospace advance — it is exact for true monospace fonts, which is what the canvas uses here. If you need highlighted code for documentation, export from your editor instead; if you need a quick, tidy snippet image for a post or a slide, this is the right weight of tool. The image is rendered locally — your code never leaves the page.
Frequently asked questions
How is the image width calculated?
From the longest line: width = 2 × padding + longest line length × font size × 0.6. A 10-character longest line at 16 px font with 24 px padding is 2 × 24 + 96 = 144 px wide. The result line always shows the final dimensions before you download.
Does it syntax-highlight my code?
No — the snippet is drawn in a single colour on the theme background. That is a deliberate trade: no highlighting library, no dependencies, and a clean uniform look. For colour-coded documentation images, use your editor’s export instead.
What happens with a very long line?
It makes a very wide image, because the width follows the longest line exactly and nothing is wrapped or truncated — wrapping code silently would misrepresent it. Shorten or manually break long lines before pasting if the image comes out too wide.
Is my code uploaded to render the image?
No. The PNG is drawn on a canvas in this browser and created only when you click Download. Your code is never uploaded, stored or put into a link.
First time embedding? Read the step-by-step guide →
More free tools
UUID Generator
Generate random v4 UUIDs in bulk.
JSON Formatter & Validator
Format, minify and validate JSON in one click.
What Is My IP
See your public IP address instantly. No sign-up, nothing stored.
Regex Tester
Test, check and validate regular expressions with live highlighting.
JWT Decoder
Decode a JWT token without the secret — see its header and payload.
SHA-256 Hash Generator
Generate SHA-256 / SHA-512 hashes instantly.