Calvin-LLC/illustrator-exporter
GitHub: Calvin-LLC/illustrator-exporter
一个无需 Adobe 许可证的 AI 文件解析与往返导出工具,解决 SVG 与 .ai 间颜色与元数据保真问题。
Stars: 0 | Forks: 0
# ai-exporter
解析并导出 Adobe Illustrator `.ai` 文件为 SVG、PNG 和 JSON,无需安装 Illustrator。同时支持从编辑后的 SVG 重建 `.ai` 文件,并保留 CMYK/专色信息。
## 功能
- 提取 `.ai` 文件中的矢量图形(PDF 包装、EPS 或原始 PostScript)
- 导出为 SVG、PNG 或 JSON
- 检查 `.ai` 文件结构与元数据
- 从 SVG 编辑重建 `.ai` 文件,通过侧边元数据文件保留 CMYK 和专色
- 支持 AI9 至 AI24+ 格式,包括 Zstandard 与 zlib 压缩
## 为何不直接使用 Inkscape / Ghostscript / pdftocairo?
大多数“将 .ai 转为 SVG”的工具只是将 `.ai` 当作 PDF 处理并通过 PDF-to-SVG 转换器转换。如果只需要页面上的形状,这没有问题。但你会丢失图层、CMYK 值、专色以及将文件另存为真实 `.ai` 的能力。
| | ai-exporter | Inkscape CLI | Ghostscript / pdftocairo | Adobe Illustrator scripting |
|-----------------------------------|:-----------:|:------------:|:------------------------:|:---------------------------:|
| 无需 Illustrator 许可证 | yes | yes | yes | no |
| 无需外部二进制文件 | yes | no | no | no |
| 解析原生 PGF PostScript | yes | no (PDF only)| no (PDF only) | yes |
| 保留 CMYK 颜色值 | yes | no (RGB) | no (RGB) | yes |
| 保留专色 | yes | no | no | yes |
| 处理 AI24+ Zstandard 流 | yes | no | no | yes |
| 往返:SVG → .ai | yes | no | no | yes |
| 许可证 | MIT | GPL | AGPL / commercial | proprietary |
反向路径是此工具存在的主要原因。打开 SVG 进行任意修改后,可以重建 `.ai` 并保持 CMYK 与专色完整。这是因为提取器会在 SVG 旁边生成一个 `.ai-meta.json` 侧边文件,保存 SVG 本身无法存储的配色信息。
## 安装
需要 Python 3.10+。
```
# 1. 创建并激活虚拟环境
python -m venv .venv
# macOS / Linux
source .venv/bin/activate
# Windows (cmd)
.venv\Scripts\activate
# 2. 安装软件包(可编辑模式,带开发依赖)
pip install -e ".[dev]"
# 3. (可选)复制环境模板用于批处理脚本
cp .env.example .env # macOS / Linux
copy .env.example .env # Windows
# 4. 验证所有连接正常
ai-export check
```
安装后,CLI 命令为 `ai-export`(或 `python -m ai_exporter.cli`)。
### 环境变量
在 `.env` 中设置这些变量(可选——仅在使用 `scripts/` 下的批处理脚本时需要):
```
# 包含 .ai 文件批处理的目录
AI_EXPORTER_SOURCE_DIR=/path/to/ai/files
# 集成测试使用的 .ai 文件目录
AI_EXPORTER_TEST_DIR=/path/to/test/ai/files
```
## 使用方法
```
# 导出为 SVG
ai-export extract design.ai --format svg --output-dir ./output
# 导出为 PNG
ai-export extract design.ai --format png --output-dir ./output
# 导出为 JSON
ai-export extract design.ai --format json --output-dir ./output
# 检查文件结构
ai-export inspect design.ai
# 从编辑后的 SVG 重建 .ai(使用 sidecar 元数据保证颜色保真)
ai-export rebuild edited.svg --original design.ai --output rebuilt.ai
# 验证依赖已安装
ai-export check
# 测试位于 `tests/_artifacts/`
python -m pytest
```
标签:Adobe Illustrator, AI24格式, AI9格式, AI文件解析, CMYK颜色, EPS解析, JSON导出, PDF解析, PNG导出, PostScript解析, SEO, Spot颜色, SVG导出, zlib压缩, Zstandard压缩, 元数据侧car, 反向重建, 导出器, 开源转换, 技术栈, 文件格式转换, 无损导出, 无需Illustrator, 无需外部二进制, 矢量图形, 色彩管理, 解析器, 逆向工具, 颜色保真