silicon
A source code to image generator — create beautiful, syntax-highlighted screenshots of code from the command line, like carbon.now.sh but offline.
silicon is a command-line tool for creating beautiful, syntax-highlighted
images of source code. It is the offline, scriptable equivalent of browser-based
tools like carbon.now.sh — give it a file or pipe in
some code, and it renders a polished PNG with a configurable colour theme, font,
background, and window chrome.
It is built on syntect for syntax highlighting and image-rs for image rendering, and supports hundreds of languages out of the box.
Features
- Syntax highlighting — over 150 languages supported via Sublime Text grammar files
- Theme support — any Sublime Text colour theme works; ships with popular defaults like Dracula, One Dark, and Solarized
- Window chrome — optional macOS-style title bar with traffic-light buttons for a polished look
- Line numbers — optionally include line numbers in the output
- Configurable fonts — specify any installed monospace font
- Background — solid colour, gradient, or transparent background
- Shadow — configurable drop shadow
- Clipboard output — write directly to the clipboard instead of a file (macOS and Linux with xclip/wl-copy)
- Pipe-friendly — reads from stdin, writes to a file or stdout
Installation
cargo install silicon
Or via your system package manager:
# macOS
brew install silicon
# Debian / Ubuntu (Debian 12+)
apt install silicon
# Fedora
dnf install silicon
# Arch Linux
pacman -S silicon
# Nix
nix-env -iA nixpkgs.siliconUsage
# Generate an image from a source file
silicon src/main.rs -o main.png
# Pipe code from stdin (language inferred or specified)
echo 'fn main() { println!("hello"); }' | silicon --language rust -o hello.png
# Use a specific theme
silicon src/main.rs --theme "Dracula" -o main.png
# Specify a font
silicon src/main.rs --font "JetBrains Mono" -o main.png
# Include line numbers
silicon src/main.rs --line-number -o main.png
# Highlight specific lines
silicon src/main.rs --highlight-lines "3-7;12" -o main.png
# Set a custom background colour
silicon src/main.rs --background "#1e1e2e" -o main.png
# No window chrome (just the code)
silicon src/main.rs --no-window-controls -o main.png
# Write to clipboard instead of a file
silicon src/main.rs --to-clipboard
# Set padding around the code
silicon src/main.rs --pad-horiz 80 --pad-vert 60 -o main.pngConfiguration
Silicon reads from ~/.config/silicon/config (or
$XDG_CONFIG_HOME/silicon/config). You can set defaults for any flag so you
don't have to repeat them every time:
--theme Dracula
--font "JetBrains Mono"
--line-number
--pad-horiz 80
--pad-vert 60
--shadow-blur-radius 20
--shadow-offset-x 10
--shadow-offset-y 10Editor Integration
Since silicon is a standard CLI tool, it integrates easily with editors:
# Neovim — visual selection to image (add to config)
# Select lines in visual mode, then run:
:'<,'>!silicon --language rust --to-clipboard
# Shell alias for quick code sharing
alias codesnap='silicon --theme Dracula --font "JetBrains Mono" --line-number'
codesnap src/main.rs -o snap.pngAdding Custom Themes
Silicon loads themes from ~/.config/silicon/themes/. Drop any .tmTheme file
there:
mkdir -p ~/.config/silicon/themes
cp my-theme.tmTheme ~/.config/silicon/themes/
silicon src/main.rs --theme "My Theme" -o output.pngAdding Custom Syntaxes
Similarly, custom .sublime-syntax or .tmLanguage files go in
~/.config/silicon/syntaxes/:
mkdir -p ~/.config/silicon/syntaxes
cp MyLang.sublime-syntax ~/.config/silicon/syntaxes/
silicon mycode.mylang --language MyLang -o output.png