@meheduz/code-to-image
v1.0.0
Published
Transform code into beautiful shareable images
Downloads
38
Maintainers
Readme
code-to-image
Transform your code into beautiful shareable images — perfect for Twitter, LinkedIn, and blogs!
Quick Start
npx code-to-image myfile.jsOr with custom options:
npx code-to-image code.py --theme dracula --output screenshot.pngFeatures
- 6 Beautiful Themes — Dracula, Monokai, GitHub, Nord, One Dark, Solarized Dark
- Syntax Highlighting — 180+ languages with accurate per-theme color maps
- Line Numbers — Toggle with
--no-line-numbers - Auto-sizing — Perfect dimensions every time
- Retina Ready —
--scale 1|2|3for crisp output (default: 2x) - PNG Export — High-quality output
- Fast — Generate in seconds
- Social Media Ready — Optimized for sharing
- macOS Window Style — Rounded corners, shadow, traffic-light controls
- Cross-Platform — Works on macOS, Linux, Windows
- Programmatic API — Use as a library in your own projects
Available Themes
| Theme | Style | Best For |
|-------|-------|----------|
| dracula | Dark purple | Twitter, Instagram |
| monokai | Classic dark | GitHub, Dev.to |
| github | Light | LinkedIn, Medium |
| nord | Cool blue | Personal blogs |
| one-dark | Atom-inspired | Clean dark look |
| solarized-dark | Warm dark | Terminal lovers |
Usage Examples
Basic Usage
npx code-to-image app.jsCustom Theme
npx code-to-image code.py --theme monokaiCustom Output Name
npx code-to-image index.ts --output my-awesome-code.pngSpecify Language
npx code-to-image script.txt --lang javascriptHigh-res Retina Output
npx code-to-image app.js --scale 3Hide Line Numbers
npx code-to-image app.js --no-line-numbersAll Options
npx code-to-image file.js --theme one-dark --output result.png --lang typescript --scale 2CLI Options
code-to-image <file> [options]
Options:
--theme <name> Theme (default: dracula)
dracula, monokai, github, nord, one-dark, solarized-dark
--output <file> Output filename (default: code-screenshot.png)
--lang <name> Force language for syntax highlighting
--scale <number> Resolution scale: 1, 2, or 3 (default: 2)
--no-line-numbers Hide line numbers
--tab-size <n> Tab width in spaces (default: 2)
--help, -h Show help
--version, -v Show versionSupported Languages
JavaScript, TypeScript, Python, Java, C++, C#, Go, Rust, Ruby, PHP, Swift, Kotlin, Scala, HTML, CSS, SQL, Bash, and 160+ more!
Use Cases
- Share code snippets on Twitter/LinkedIn
- Add beautiful code examples to blog posts
- Create programming tutorials
- Include in presentations
- Portfolio projects showcase
- Documentation with visual examples
Installation
NPX (Recommended)
npx code-to-image file.jsGlobal Install
npm install -g code-to-image
code-to-image file.jsAs a Library
npm install code-to-imageconst { generateImage, themes } = require('code-to-image');
const png = generateImage({
code: 'console.log("Hello, world!");',
language: 'javascript',
theme: 'dracula',
fileName: 'hello.js',
showLineNumbers: true,
scale: 2,
});
fs.writeFileSync('output.png', png);Contributing
Contributions welcome! Here's how:
- Fork the repository
- Create your feature branch (
git checkout -b feature/NewTheme) - Commit changes (
git commit -m 'Add new theme') - Push to branch (
git push origin feature/NewTheme) - Open a Pull Request
Ideas for contributions:
- Add new themes
- Support more languages
- Add custom fonts
- Add watermark option
- SVG / JPEG export formats
- Custom background images
License
MIT © meheduz
