SnapCode-AI 是一款专为开发者打造的 AI 驱动代码截图美化工具,让你轻松将枯燥的代码片段转化为令人惊艳的精美图片,一键分享到各大社交平台。
| 痛点 | SnapCode-AI 的解决方案 |
|---|---|
| 😩 代码截图丑陋、不专业 | 🎨 21 款精心设计的主题,覆盖主流编辑器风格 |
| 😫 每个平台尺寸要求不同 | 📱 19 个社交平台预设,一键适配最佳尺寸 |
| 😰 语法高亮不完整 | 💻 支持 20+ 编程语言,精准着色 |
| 😭 安装依赖太多太麻烦 | ⚡ 零核心依赖,纯 Python 标准库实现 |
| 😵 工具太复杂不会用 | 🖱️ 交互式 Web UI + 简洁 CLI,上手即用 |
把代码变成艺术品,让分享成为一种享受。
从经典到潮流,总有一款适合你:
| 分类 | 主题 |
|---|---|
| 🌙 深色系 | Catppuccin Mocha、Dracula、Tokyo Night、Nord、Monokai、GitHub Dark、One Dark Pro、Gruvbox Dark、Solarized Dark、VS Code Dark、Atom One Dark、Palenight |
| ☀️ 浅色系 | GitHub Light、Solarized Light、One Light、VS Code Light、Atom One Light |
| 🌈 特色系 | Catppuccin Latte、Gruvbox Light、Snazzy、Ayu Dark |
完整支持以下语言的语法高亮:
Python · JavaScript · TypeScript · Go · Rust · Java · C · C++ · Ruby · PHP
Swift · Kotlin · HTML · CSS · JSON · SQL · Bash · Markdown · YAML · Dockerfile
一键生成适配各平台最佳尺寸的代码截图:
| 平台 | 分类 | 说明 |
|---|---|---|
| 🇨🇳 微信朋友圈 | 国内社交 | 1080×1080px,朋友圈最佳展示 |
| 📕 小红书 | 国内社交 | 1080×1440px,3:4 竖版卡片 |
| 📺 B 站 | 国内社交 | 1920×1080px,16:9 横版封面 |
| 🎵 抖音 | 国内社交 | 1080×1920px,9:16 竖版 |
| ❓ 知乎 | 国内社交 | 1200×675px,16:9 图文卡片 |
| 📢 微博 | 国内社交 | 1080×1080px,正方形配图 |
| 🐦 X / Twitter | 国际社交 | 1600×900px,Twitter 最佳比例 |
| 国际社交 | 1200×627px,LinkedIn 文章配图 | |
| 国际社交 | 1080×1080px,正方形帖子 | |
| 国际社交 | 1200×630px,Facebook 分享图 | |
| 🐙 GitHub README | 开发者 | 1280×640px,README Banner |
| 📝 DEV.to | 开发者 | 1000×420px,文章封面 |
| 🎥 YouTube | 视频平台 | 1280×720px,视频缩略图 |
| 📰 Medium | 博客平台 | 1200×630px,文章头图 |
| 📋 Discord | 社区平台 | 1200×675px,Discord 嵌入 |
| 💬 Telegram | 社区平台 | 1200×675px,消息预览 |
| 社区平台 | 1200×628px,帖子配图 | |
| 通讯工具 | 800×400px,邮件签名 | |
| 🌐 通用 | 通用场景 | 1200×800px,万能尺寸 |
内置 HTTP 服务器,提供实时预览的 Web 界面:
# 启动 Web UI,默认端口 8964
snapcode web
# 指定自定义端口
snapcode web --port 8080一行命令,搞定一切:
# 基础用法:美化代码截图
snapcode screenshot -f code.py
# 指定主题和平台预设
snapcode screenshot -f code.py --theme dracula --preset twitter-x
# 自定义窗口标题
snapcode screenshot -f code.py --title "My Awesome Code"
# 显示行号
snapcode screenshot -f code.py --line-numbers
# 高亮指定行
snapcode screenshot -f code.py --highlight 5,10,15-20
# 选择窗口样式
snapcode screenshot -f code.py --window-style macos纯 Python 标准库实现,无需安装任何第三方依赖:
pip install snapcode-ai # 仅此一步,开箱即用支持 macOS、Windows、Linux 三大操作系统的窗口外观:
snapcode screenshot -f code.py --window-style macos # macOS 风格
snapcode screenshot -f code.py --window-style windows # Windows 风格
snapcode screenshot -f code.py --window-style linux # Linux 风格- ✅ 行号显示 / 隐藏
- ✅ 指定行高亮(支持范围,如
5,10,15-20) - ✅ 自定义窗口标题
- ✅ HTML 输出格式
- ✅ 自定义输出路径
- Python 3.8 或更高版本
- pip 包管理器
方式一:通过 PyPI 安装(推荐)
pip install snapcode-ai方式二:从源码安装
git clone https://github.com/gitstq/snapcode-ai.git
cd snapcode-ai
pip install -e .# 1. 安装
pip install snapcode-ai
# 2. 创建一个示例代码文件
echo 'print("Hello, SnapCode-AI! 🚀")' > hello.py
# 3. 生成精美截图
snapcode screenshot -f hello.py --theme dracula --preset wechat
# 4. 查看生成的截图
# 输出文件默认保存在当前目录# 启动交互式 Web 界面
snapcode web --port 8964
# 打开浏览器访问
# http://localhost:8964核心命令,用于生成代码截图:
snapcode screenshot -f <文件路径> [选项]完整参数列表:
| 参数 | 缩写 | 说明 | 默认值 |
|---|---|---|---|
--file |
-f |
代码文件路径(必填) | - |
--theme |
-t |
主题名称 | dracula |
--preset |
-p |
社交平台预设 | wechat |
--output |
-o |
输出文件路径 | 自动生成 |
--title |
-T |
窗口标题 | 文件名 |
--line-numbers |
-n |
显示行号 | True |
--highlight |
-H |
高亮行(如 5,10,15-20) |
- |
--window-style |
-w |
窗口样式(macos/windows/linux) | macos |
--format |
-F |
输出格式(png/html) | png |
--padding |
-P |
内边距大小 | 40 |
使用示例:
# 生成适配 X/Twitter 的 Dracula 主题截图
snapcode screenshot -f main.py --theme dracula --preset twitter-x
# 生成小红书风格的代码卡片
snapcode screenshot -f app.ts --theme tokyo-night --preset xiaohongshu
# 生成 GitHub README Banner
snapcode screenshot -f config.json --theme github-dark --preset github-readme
# 高亮关键代码行
snapcode screenshot -f server.go --theme nord --highlight 10-25,30
# 导出为 HTML 格式
snapcode screenshot -f style.css --theme catppuccin-mocha --format html启动交互式 Web UI 服务器:
snapcode web [选项]| 参数 | 说明 | 默认值 |
|---|---|---|
--port |
服务端口 | 8964 |
--host |
绑定地址 | 127.0.0.1 |
查看所有可用主题:
snapcode themes输出示例:
🎨 Available Themes:
🌙 Dark: catppuccin-mocha, dracula, tokyo-night, nord, monokai, ...
☀️ Light: github-light, solarized-light, one-light, ...
🌈 Special: catppuccin-latte, gruvbox-light, snazzy, ...
查看所有可用平台预设:
snapcode presets输出示例:
📱 Available Presets:
🇨🇳 Domestic: wechat, xiaohongshu, bilibili, douyin, zhihu, weibo
🌍 Global: twitter-x, linkedin, instagram, facebook
👨💻 Developer: github-readme, dev-to
🎥 Video: youtube
📰 Blog: medium
💬 Community: discord, telegram, reddit
📧 Other: email, generic
查看所有支持的编程语言:
snapcode languages查看版本信息:
snapcode versionSnapCode-AI 的设计遵循以下核心原则:
-
零依赖哲学 📦
- 核心功能完全基于 Python 标准库实现
- 无需安装任何第三方包,降低环境配置成本
- 提升启动速度,减少潜在的安全风险
-
主题引擎解耦 🎨
- 主题与渲染引擎完全分离
- 采用 JSON 配置定义主题,便于社区贡献
- 支持用户自定义主题扩展
-
预设系统灵活 📱
- 社交平台预设独立于主题系统
- 预设定义了尺寸、圆角、阴影等布局参数
- 新增平台只需添加一个配置文件
-
双模式交互 🖱️
- CLI 模式:适合自动化脚本和 CI/CD 集成
- Web UI 模式:适合交互式探索和实时预览
- 两种模式共享同一套核心渲染引擎
- 21 款精美主题
- 20+ 编程语言语法高亮
- 19 个社交平台预设
- 交互式 Web UI
- CLI 命令行工具
- 零核心依赖
- 多种窗口样式
- 行号显示/隐藏、行高亮
- HTML 输出格式
- 自定义主题编辑器(Web UI 内置)
- 批量截图生成模式
- 更多编程语言支持(Scala、Elixir、Haskell 等)
- 渐变背景与自定义水印
- AI 智能主题推荐(根据代码内容自动匹配最佳主题)
- VS Code / JetBrains 插件集成
- API 服务模式(支持远程调用)
- 团队主题共享与协作
- 在线 SaaS 服务
- 代码动画 GIF 导出
- 深度编辑器集成(Cursor、Windsurf 等)
- 社区主题市场
# 1. 安装构建工具
pip install build twine
# 2. 构建分发包
python -m build
# 3. 检查包内容
twine check dist/*
# 4. 上传到 PyPI
twine upload dist/*FROM python:3.11-slim
WORKDIR /app
COPY . .
RUN pip install snapcode-ai
EXPOSE 8964
CMD ["snapcode", "web", "--port", "8964", "--host", "0.0.0.0"]构建与运行:
# 构建镜像
docker build -t snapcode-ai .
# 运行容器
docker run -p 8964:8964 snapcode-ai#!/bin/bash
# deploy.sh - SnapCode-AI 快速部署脚本
echo "🚀 正在部署 SnapCode-AI..."
# 安装
pip install snapcode-ai
# 验证安装
snapcode version
echo "✅ 部署完成!"
echo "💡 运行 'snapcode web' 启动 Web UI"
echo "💡 运行 'snapcode screenshot -f your_code.py' 生成截图"snapcode-ai/
├── snapcode_ai/ # 核心包
│ ├── __init__.py
│ ├── cli.py # CLI 入口
│ ├── web.py # Web UI 服务器
│ ├── renderer/ # 渲染引擎
│ │ ├── screenshot.py # 截图渲染
│ │ └── html.py # HTML 渲染
│ ├── themes/ # 主题定义
│ │ ├── dark/ # 深色主题
│ │ └── light/ # 浅色主题
│ ├── presets/ # 平台预设
│ ├── languages/ # 语法高亮定义
│ └── utils/ # 工具函数
├── tests/ # 测试
├── setup.py # 安装配置
├── pyproject.toml # 项目配置
├── Dockerfile # Docker 配置
└── README.md # 本文件
我们欢迎并感谢每一位贡献者!无论你是修复了一个 Bug、添加了一个新主题,还是改进了文档,每一份贡献都让 SnapCode-AI 变得更好。
1. Fork 并克隆项目
git clone https://github.com/gitstq/snapcode-ai.git
cd snapcode-ai2. 创建功能分支
git checkout -b feature/your-feature-name3. 开发与测试
# 安装开发依赖
pip install -e ".[dev]"
# 运行测试
python -m pytest tests/
# 代码格式化
python -m black snapcode_ai/4. 提交代码
git add .
git commit -m "feat: 添加新功能描述"
git push origin feature/your-feature-name5. 发起 Pull Request
在 GitHub 上创建 Pull Request,描述你的改动内容。
- 在
snapcode_ai/themes/目录下创建主题配置文件 - 定义背景色、前景色、语法高亮色等参数
- 提交 PR 并附带主题预览截图
- 在
snapcode_ai/presets/目录下创建预设配置文件 - 定义目标尺寸、圆角、阴影等参数
- 提交 PR 并说明平台适配细节
- 遵循 Conventional Commits 提交规范
- 代码风格遵循 PEP 8
- 添加充分的注释和文档
- 确保所有测试通过
本项目基于 MIT License 开源。
MIT License
Copyright (c) 2024 gitstq
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Made with ❤️ by gitstq
如果你觉得 SnapCode-AI 对你有帮助,请给项目一个 ⭐ Star!
⭐ Star this repo if you find it helpful!
SnapCode-AI 是一款專為開發者打造的 AI 驅動程式碼截圖美化工具,讓你輕鬆將枯燥的程式碼片段轉化為令人驚豔的精美圖片,一鍵分享到各大社群平台。
| 痛點 | SnapCode-AI 的解決方案 |
|---|---|
| 😩 程式碼截圖醜陋、不專業 | 🎨 21 款精心設計的主題,覆蓋主流編輯器風格 |
| 😫 每個平台尺寸要求不同 | 📱 19 個社群平台預設,一鍵適配最佳尺寸 |
| 😰 語法高亮不完整 | 💻 支援 20+ 程式語言,精準著色 |
| 😭 安裝依賴太多太麻煩 | ⚡ 零核心依賴,純 Python 標準函式庫實作 |
| 😵 工具太複雜不會用 | 🖱️ 互動式 Web UI + 簡潔 CLI,上手即用 |
把程式碼變成藝術品,讓分享成為一種享受。
從經典到潮流,總有一款適合你:
| 分類 | 主題 |
|---|---|
| 🌙 深色系 | Catppuccin Mocha、Dracula、Tokyo Night、Nord、Monokai、GitHub Dark、One Dark Pro、Gruvbox Dark、Solarized Dark、VS Code Dark、Atom One Dark、Palenight |
| ☀️ 淺色系 | GitHub Light、Solarized Light、One Light、VS Code Light、Atom One Light |
| 🌈 特色系 | Catppuccin Latte、Gruvbox Light、Snazzy、Ayu Dark |
完整支援以下語言的語法高亮:
Python · JavaScript · TypeScript · Go · Rust · Java · C · C++ · Ruby · PHP
Swift · Kotlin · HTML · CSS · JSON · SQL · Bash · Markdown · YAML · Dockerfile
一鍵生成適配各平台最佳尺寸的程式碼截圖:
| 平台 | 分類 | 說明 |
|---|---|---|
| 🇨🇳 微信朋友圈 | 國內社群 | 1080×1080px,朋友圈最佳展示 |
| 📕 小紅書 | 國內社群 | 1080×1440px,3:4 竪版卡片 |
| 📺 B 站 | 國內社群 | 1920×1080px,16:9 橫版封面 |
| 🎵 抖音 | 國內社群 | 1080×1920px,9:16 竪版 |
| ❓ 知乎 | 國內社群 | 1200×675px,16:9 圖文卡片 |
| 📢 微博 | 國內社群 | 1080×1080px,正方形配圖 |
| 🐦 X / Twitter | 國際社群 | 1600×900px,Twitter 最佳比例 |
| 國際社群 | 1200×627px,LinkedIn 文章配圖 | |
| 國際社群 | 1080×1080px,正方形貼文 | |
| 國際社群 | 1200×630px,Facebook 分享圖 | |
| 🐙 GitHub README | 開發者 | 1280×640px,README Banner |
| 📝 DEV.to | 開發者 | 1000×420px,文章封面 |
| 🎥 YouTube | 影片平台 | 1280×720px,影片縮圖 |
| 📰 Medium | 部落格平台 | 1200×630px,文章頭圖 |
| 📋 Discord | 社群平台 | 1200×675px,Discord 嵌入 |
| 💬 Telegram | 社群平台 | 1200×675px,訊息預覽 |
| 社群平台 | 1200×628px,貼文配圖 | |
| 通訊工具 | 800×400px,郵件簽名 | |
| 🌐 通用 | 通用場景 | 1200×800px,萬能尺寸 |
內建 HTTP 伺服器,提供即時預覽的 Web 介面:
# 啟動 Web UI,預設連接埠 8964
snapcode web
# 指定自訂連接埠
snapcode web --port 8080一行指令,搞定一切:
# 基礎用法:美化程式碼截圖
snapcode screenshot -f code.py
# 指定主題和平台預設
snapcode screenshot -f code.py --theme dracula --preset twitter-x
# 自訂視窗標題
snapcode screenshot -f code.py --title "My Awesome Code"
# 顯示行號
snapcode screenshot -f code.py --line-numbers
# 高亮指定行
snapcode screenshot -f code.py --highlight 5,10,15-20
# 選擇視窗樣式
snapcode screenshot -f code.py --window-style macos純 Python 標準函式庫實作,無需安裝任何第三方依賴:
pip install snapcode-ai # 僅此一步,開箱即用支援 macOS、Windows、Linux 三大作業系統的視窗外觀:
snapcode screenshot -f code.py --window-style macos # macOS 風格
snapcode screenshot -f code.py --window-style windows # Windows 風格
snapcode screenshot -f code.py --window-style linux # Linux 風格- ✅ 行號顯示 / 隱藏
- ✅ 指定行高亮(支援範圍,如
5,10,15-20) - ✅ 自訂視窗標題
- ✅ HTML 輸出格式
- ✅ 自訂輸出路徑
- Python 3.8 或更高版本
- pip 套件管理器
方式一:透過 PyPI 安裝(推薦)
pip install snapcode-ai方式二:從原始碼安裝
git clone https://github.com/gitstq/snapcode-ai.git
cd snapcode-ai
pip install -e .# 1. 安裝
pip install snapcode-ai
# 2. 建立一個範例程式碼檔案
echo 'print("Hello, SnapCode-AI! 🚀")' > hello.py
# 3. 生成精美截圖
snapcode screenshot -f hello.py --theme dracula --preset wechat
# 4. 查看生成的截圖
# 輸出檔案預設儲存在目前目錄# 啟動互動式 Web 介面
snapcode web --port 8964
# 開啟瀏覽器存取
# http://localhost:8964核心指令,用於生成程式碼截圖:
snapcode screenshot -f <檔案路徑> [選項]完整參數列表:
| 參數 | 縮寫 | 說明 | 預設值 |
|---|---|---|---|
--file |
-f |
程式碼檔案路徑(必填) | - |
--theme |
-t |
主題名稱 | dracula |
--preset |
-p |
社群平台預設 | wechat |
--output |
-o |
輸出檔案路徑 | 自動生成 |
--title |
-T |
視窗標題 | 檔案名稱 |
--line-numbers |
-n |
顯示行號 | True |
--highlight |
-H |
高亮行(如 5,10,15-20) |
- |
--window-style |
-w |
視窗樣式(macos/windows/linux) | macos |
--format |
-F |
輸出格式(png/html) | png |
--padding |
-P |
內邊距大小 | 40 |
使用範例:
# 生成適配 X/Twitter 的 Dracula 主題截圖
snapcode screenshot -f main.py --theme dracula --preset twitter-x
# 生成小紅書風格的程式碼卡片
snapcode screenshot -f app.ts --theme tokyo-night --preset xiaohongshu
# 生成 GitHub README Banner
snapcode screenshot -f config.json --theme github-dark --preset github-readme
# 高亮關鍵程式碼行
snapcode screenshot -f server.go --theme nord --highlight 10-25,30
# 匯出為 HTML 格式
snapcode screenshot -f style.css --theme catppuccin-mocha --format html啟動互動式 Web UI 伺服器:
snapcode web [選項]| 參數 | 說明 | 預設值 |
|---|---|---|
--port |
服務連接埠 | 8964 |
--host |
綁定位址 | 127.0.0.1 |
查看所有可用主題:
snapcode themes輸出範例:
🎨 Available Themes:
🌙 Dark: catppuccin-mocha, dracula, tokyo-night, nord, monokai, ...
☀️ Light: github-light, solarized-light, one-light, ...
🌈 Special: catppuccin-latte, gruvbox-light, snazzy, ...
查看所有可用平台預設:
snapcode presets輸出範例:
📱 Available Presets:
🇨🇳 Domestic: wechat, xiaohongshu, bilibili, douyin, zhihu, weibo
🌍 Global: twitter-x, linkedin, instagram, facebook
👨💻 Developer: github-readme, dev-to
🎥 Video: youtube
📰 Blog: medium
💬 Community: discord, telegram, reddit
📧 Other: email, generic
查看所有支援的程式語言:
snapcode languages查看版本資訊:
snapcode versionSnapCode-AI 的設計遵循以下核心原則:
-
零依賴哲學 📦
- 核心功能完全基於 Python 標準函式庫實作
- 無需安裝任何第三方套件,降低環境配置成本
- 提升啟動速度,減少潛在的安全風險
-
主題引擎解耦 🎨
- 主題與渲染引擎完全分離
- 採用 JSON 配置定義主題,便於社群貢獻
- 支援使用者自訂主題擴充
-
預設系統靈活 📱
- 社群平台預設獨立於主題系統
- 預設定義了尺寸、圓角、陰影等佈局參數
- 新增平台只需新增一個配置檔案
-
雙模式互動 🖱️
- CLI 模式:適合自動化腳本和 CI/CD 整合
- Web UI 模式:適合互動式探索和即時預覽
- 兩種模式共享同一套核心渲染引擎
- 21 款精美主題
- 20+ 程式語言語法高亮
- 19 個社群平台預設
- 互動式 Web UI
- CLI 命令列工具
- 零核心依賴
- 多種視窗樣式
- 行號顯示/隱藏、行高亮
- HTML 輸出格式
- 自訂主題編輯器(Web UI 內建)
- 批量截圖生成模式
- 更多程式語言支援(Scala、Elixir、Haskell 等)
- 漸層背景與自訂浮水印
- AI 智慧主題推薦(根據程式碼內容自動匹配最佳主題)
- VS Code / JetBrains 外掛整合
- API 服務模式(支援遠端呼叫)
- 團隊主題共享與協作
- 線上 SaaS 服務
- 程式碼動畫 GIF 匯出
- 深度編輯器整合(Cursor、Windsurf 等)
- 社群主題市場
# 1. 安裝建置工具
pip install build twine
# 2. 建置發行包
python -m build
# 3. 檢查套件內容
twine check dist/*
# 4. 上傳到 PyPI
twine upload dist/*FROM python:3.11-slim
WORKDIR /app
COPY . .
RUN pip install snapcode-ai
EXPOSE 8964
CMD ["snapcode", "web", "--port", "8964", "--host", "0.0.0.0"]建置與執行:
# 建置映像
docker build -t snapcode-ai .
# 執行容器
docker run -p 8964:8964 snapcode-ai#!/bin/bash
# deploy.sh - SnapCode-AI 快速部署腳本
echo "🚀 正在部署 SnapCode-AI..."
# 安裝
pip install snapcode-ai
# 驗證安裝
snapcode version
echo "✅ 部署完成!"
echo "💡 執行 'snapcode web' 啟動 Web UI"
echo "💡 執行 'snapcode screenshot -f your_code.py' 生成截圖"snapcode-ai/
├── snapcode_ai/ # 核心套件
│ ├── __init__.py
│ ├── cli.py # CLI 進入點
│ ├── web.py # Web UI 伺服器
│ ├── renderer/ # 渲染引擎
│ │ ├── screenshot.py # 截圖渲染
│ │ └── html.py # HTML 渲染
│ ├── themes/ # 主題定義
│ │ ├── dark/ # 深色主題
│ │ └── light/ # 淺色主題
│ ├── presets/ # 平台預設
│ ├── languages/ # 語法高亮定義
│ └── utils/ # 工具函式
├── tests/ # 測試
├── setup.py # 安裝配置
├── pyproject.toml # 專案配置
├── Dockerfile # Docker 配置
└── README.md # 本檔案
我們歡迎並感謝每一位貢獻者!無論你是修復了一個 Bug、新增了一個新主題,還是改進了文件,每一份貢獻都讓 SnapCode-AI 變得更好。
1. Fork 並克隆專案
git clone https://github.com/gitstq/snapcode-ai.git
cd snapcode-ai2. 建立功能分支
git checkout -b feature/your-feature-name3. 開發與測試
# 安裝開發依賴
pip install -e ".[dev]"
# 執行測試
python -m pytest tests/
# 程式碼格式化
python -m black snapcode_ai/4. 提交程式碼
git add .
git commit -m "feat: 新增新功能描述"
git push origin feature/your-feature-name5. 發起 Pull Request
在 GitHub 上建立 Pull Request,描述你的變更內容。
- 在
snapcode_ai/themes/目錄下建立主題配置檔案 - 定義背景色、前景色、語法高亮色等參數
- 提交 PR 並附帶主題預覽截圖
- 在
snapcode_ai/presets/目錄下建立預設配置檔案 - 定義目標尺寸、圓角、陰影等參數
- 提交 PR 並說明平台適配細節
- 遵循 Conventional Commits 提交規範
- 程式碼風格遵循 PEP 8
- 新增充分的註解和文件
- 確保所有測試通過
本專案基於 MIT License 開源。
MIT License
Copyright (c) 2024 gitstq
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Made with ❤️ by gitstq
如果你覺得 SnapCode-AI 對你有幫助,請給專案一個 ⭐ Star!
⭐ Star this repo if you find it helpful!
SnapCode-AI is an AI-powered code screenshot beautifier designed specifically for developers. It transforms boring code snippets into stunning visuals that you can share across social platforms with a single click.
| Pain Point | SnapCode-AI Solution |
|---|---|
| 😩 Ugly, unprofessional code screenshots | 🎨 21 beautifully crafted themes covering popular editor styles |
| 😫 Different size requirements per platform | 📱 19 social platform presets with one-click optimal sizing |
| 😰 Incomplete syntax highlighting | 💻 20+ programming languages with precise colorization |
| 😭 Too many dependencies to install | ⚡ Zero core dependencies, pure Python standard library |
| 😵 Tools too complex to use | 🖱️ Interactive Web UI + clean CLI, ready to use out of the box |
Turn code into art, make sharing a joy.
From classic to trendy, there's always one that fits your style:
| Category | Themes |
|---|---|
| 🌙 Dark | Catppuccin Mocha, Dracula, Tokyo Night, Nord, Monokai, GitHub Dark, One Dark Pro, Gruvbox Dark, Solarized Dark, VS Code Dark, Atom One Dark, Palenight |
| ☀️ Light | GitHub Light, Solarized Light, One Light, VS Code Light, Atom One Light |
| 🌈 Special | Catppuccin Latte, Gruvbox Light, Snazzy, Ayu Dark |
Full syntax highlighting support for the following languages:
Python · JavaScript · TypeScript · Go · Rust · Java · C · C++ · Ruby · PHP
Swift · Kotlin · HTML · CSS · JSON · SQL · Bash · Markdown · YAML · Dockerfile
Generate code screenshots optimized for each platform's ideal dimensions:
| Platform | Category | Description |
|---|---|---|
| 🇨🇳 WeChat Moments | Domestic (CN) | 1080×1080px, optimal for Moments |
| 📕 Xiaohongshu | Domestic (CN) | 1080×1440px, 3:4 portrait card |
| 📺 Bilibili | Domestic (CN) | 1920×1080px, 16:9 landscape cover |
| 🎵 TikTok / Douyin | Domestic (CN) | 1080×1920px, 9:16 portrait |
| ❓ Zhihu | Domestic (CN) | 1200×675px, 16:9 image card |
| Domestic (CN) | 1080×1080px, square image | |
| 🐦 X / Twitter | International | 1600×900px, Twitter optimal ratio |
| International | 1200×627px, LinkedIn article image | |
| International | 1080×1080px, square post | |
| International | 1200×630px, Facebook share image | |
| 🐙 GitHub README | Developer | 1280×640px, README Banner |
| 📝 DEV.to | Developer | 1000×420px, article cover |
| 🎥 YouTube | Video | 1280×720px, video thumbnail |
| 📰 Medium | Blog | 1200×630px, article header |
| 📋 Discord | Community | 1200×675px, Discord embed |
| 💬 Telegram | Community | 1200×675px, message preview |
| Community | 1200×628px, post image | |
| Communication | 800×400px, email signature | |
| 🌐 Generic | Universal | 1200×800px, all-purpose size |
Built-in HTTP server with a real-time preview web interface:
# Launch Web UI on default port 8964
snapcode web
# Specify a custom port
snapcode web --port 8080One command is all you need:
# Basic usage: beautify a code screenshot
snapcode screenshot -f code.py
# Specify theme and platform preset
snapcode screenshot -f code.py --theme dracula --preset twitter-x
# Custom window title
snapcode screenshot -f code.py --title "My Awesome Code"
# Show line numbers
snapcode screenshot -f code.py --line-numbers
# Highlight specific lines
snapcode screenshot -f code.py --highlight 5,10,15-20
# Choose window style
snapcode screenshot -f code.py --window-style macosBuilt entirely with the Python standard library — no third-party packages required:
pip install snapcode-ai # That's it, ready to goSupports macOS, Windows, and Linux window chrome appearances:
snapcode screenshot -f code.py --window-style macos # macOS style
snapcode screenshot -f code.py --window-style windows # Windows style
snapcode screenshot -f code.py --window-style linux # Linux style- ✅ Show / hide line numbers
- ✅ Highlight specific lines (supports ranges like
5,10,15-20) - ✅ Custom window title
- ✅ HTML output format
- ✅ Custom output path
- Python 3.8 or higher
- pip package manager
Option 1: Install via PyPI (Recommended)
pip install snapcode-aiOption 2: Install from Source
git clone https://github.com/gitstq/snapcode-ai.git
cd snapcode-ai
pip install -e .# 1. Install
pip install snapcode-ai
# 2. Create a sample code file
echo 'print("Hello, SnapCode-AI! 🚀")' > hello.py
# 3. Generate a beautiful screenshot
snapcode screenshot -f hello.py --theme dracula --preset wechat
# 4. Check the generated screenshot
# Output file is saved in the current directory by default# Start the interactive web interface
snapcode web --port 8964
# Open your browser and visit
# http://localhost:8964The core command for generating code screenshots:
snapcode screenshot -f <file_path> [options]Full Parameter List:
| Parameter | Short | Description | Default |
|---|---|---|---|
--file |
-f |
Code file path (required) | - |
--theme |
-t |
Theme name | dracula |
--preset |
-p |
Social platform preset | wechat |
--output |
-o |
Output file path | Auto-generated |
--title |
-T |
Window title | Filename |
--line-numbers |
-n |
Show line numbers | True |
--highlight |
-H |
Highlight lines (e.g. 5,10,15-20) |
- |
--window-style |
-w |
Window style (macos/windows/linux) | macos |
--format |
-F |
Output format (png/html) | png |
--padding |
-P |
Padding size | 40 |
Usage Examples:
# Generate a Dracula-themed screenshot optimized for X/Twitter
snapcode screenshot -f main.py --theme dracula --preset twitter-x
# Generate a Xiaohongshu-style code card
snapcode screenshot -f app.ts --theme tokyo-night --preset xiaohongshu
# Generate a GitHub README Banner
snapcode screenshot -f config.json --theme github-dark --preset github-readme
# Highlight key code lines
snapcode screenshot -f server.go --theme nord --highlight 10-25,30
# Export as HTML format
snapcode screenshot -f style.css --theme catppuccin-mocha --format htmlLaunch the interactive Web UI server:
snapcode web [options]| Parameter | Description | Default |
|---|---|---|
--port |
Server port | 8964 |
--host |
Bind address | 127.0.0.1 |
List all available themes:
snapcode themesSample output:
🎨 Available Themes:
🌙 Dark: catppuccin-mocha, dracula, tokyo-night, nord, monokai, ...
☀️ Light: github-light, solarized-light, one-light, ...
🌈 Special: catppuccin-latte, gruvbox-light, snazzy, ...
List all available platform presets:
snapcode presetsSample output:
📱 Available Presets:
🇨🇳 Domestic: wechat, xiaohongshu, bilibili, douyin, zhihu, weibo
🌍 Global: twitter-x, linkedin, instagram, facebook
👨💻 Developer: github-readme, dev-to
🎥 Video: youtube
📰 Blog: medium
💬 Community: discord, telegram, reddit
📧 Other: email, generic
List all supported programming languages:
snapcode languagesShow version information:
snapcode versionSnapCode-AI is designed around the following core principles:
-
Zero-Dependency Philosophy 📦
- Core functionality is built entirely on the Python standard library
- No third-party packages needed, reducing environment setup complexity
- Faster startup times and reduced security surface area
-
Decoupled Theme Engine 🎨
- Themes are completely separated from the rendering engine
- JSON-based theme definitions make community contributions easy
- Supports user-defined custom theme extensions
-
Flexible Preset System 📱
- Social platform presets are independent from the theme system
- Presets define dimensions, border radius, shadows, and other layout parameters
- Adding a new platform requires only a single configuration file
-
Dual-Mode Interaction 🖱️
- CLI mode: ideal for automation scripts and CI/CD integration
- Web UI mode: perfect for interactive exploration and real-time preview
- Both modes share the same core rendering engine
- 21 beautiful themes
- 20+ programming language syntax highlighting
- 19 social platform presets
- Interactive Web UI
- CLI command-line tool
- Zero core dependencies
- Multiple window styles
- Line number show/hide, line highlighting
- HTML output format
- Custom theme editor (built into Web UI)
- Batch screenshot generation mode
- Additional language support (Scala, Elixir, Haskell, etc.)
- Gradient backgrounds and custom watermarks
- AI-powered theme recommendations (auto-match best theme based on code content)
- VS Code / JetBrains plugin integration
- API service mode (remote invocation support)
- Team theme sharing and collaboration
- Online SaaS service
- Code animation GIF export
- Deep editor integration (Cursor, Windsurf, etc.)
- Community theme marketplace
# 1. Install build tools
pip install build twine
# 2. Build distribution packages
python -m build
# 3. Check package contents
twine check dist/*
# 4. Upload to PyPI
twine upload dist/*FROM python:3.11-slim
WORKDIR /app
COPY . .
RUN pip install snapcode-ai
EXPOSE 8964
CMD ["snapcode", "web", "--port", "8964", "--host", "0.0.0.0"]Build and run:
# Build the image
docker build -t snapcode-ai .
# Run the container
docker run -p 8964:8964 snapcode-ai#!/bin/bash
# deploy.sh - SnapCode-AI Quick Deployment Script
echo "🚀 Deploying SnapCode-AI..."
# Install
pip install snapcode-ai
# Verify installation
snapcode version
echo "✅ Deployment complete!"
echo "💡 Run 'snapcode web' to start the Web UI"
echo "💡 Run 'snapcode screenshot -f your_code.py' to generate screenshots"snapcode-ai/
├── snapcode_ai/ # Core package
│ ├── __init__.py
│ ├── cli.py # CLI entry point
│ ├── web.py # Web UI server
│ ├── renderer/ # Rendering engine
│ │ ├── screenshot.py # Screenshot renderer
│ │ └── html.py # HTML renderer
│ ├── themes/ # Theme definitions
│ │ ├── dark/ # Dark themes
│ │ └── light/ # Light themes
│ ├── presets/ # Platform presets
│ ├── languages/ # Syntax highlighting definitions
│ └── utils/ # Utility functions
├── tests/ # Tests
├── setup.py # Installation config
├── pyproject.toml # Project config
├── Dockerfile # Docker config
└── README.md # This file
We welcome and appreciate every contributor! Whether you fix a bug, add a new theme, or improve the documentation — every contribution makes SnapCode-AI better.
1. Fork and Clone the Repository
git clone https://github.com/gitstq/snapcode-ai.git
cd snapcode-ai2. Create a Feature Branch
git checkout -b feature/your-feature-name3. Develop and Test
# Install dev dependencies
pip install -e ".[dev]"
# Run tests
python -m pytest tests/
# Format code
python -m black snapcode_ai/4. Commit Your Changes
git add .
git commit -m "feat: add new feature description"
git push origin feature/your-feature-name5. Open a Pull Request
Create a Pull Request on GitHub describing your changes.
- Create a theme configuration file in the
snapcode_ai/themes/directory - Define background color, foreground color, syntax highlight colors, etc.
- Submit a PR with a preview screenshot of the theme
- Create a preset configuration file in the
snapcode_ai/presets/directory - Define target dimensions, border radius, shadows, and other parameters
- Submit a PR with details about the platform adaptation
- Follow the Conventional Commits specification
- Adhere to PEP 8 code style
- Add thorough comments and documentation
- Ensure all tests pass
This project is licensed under the MIT License.
MIT License
Copyright (c) 2024 gitstq
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Made with ❤️ by gitstq
If you find SnapCode-AI helpful, please give it a ⭐ Star!