1
0

feat: 移除图片适配模式功能

移除图片 fit 和 background 参数支持,简化图片渲染逻辑。系统恢复到直接使用 python-pptx 原生图片添加功能,图片将被拉伸到指定尺寸。

变更内容:
- 移除 ImageElement 的 fit 和 background 字段
- 移除 metadata.dpi 配置
- 删除 utils/image_utils.py 图片处理工具模块
- 删除 validators/image_config.py 验证器
- 简化 PPTX 和 HTML 渲染器的图片处理逻辑
- HTML 渲染器使用硬编码 DPI=96(Web 标准)
- 删除相关测试文件(单元测试、集成测试、e2e 测试)
- 更新规格文档和用户文档
- 保留 Pillow 依赖用于未来可能的图片处理需求

影响:
- 删除 11 个文件
- 修改 10 个文件
- 净减少 1558 行代码
- 所有 402 个测试通过

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-03-04 14:23:12 +08:00
parent 2fd8bc1b4a
commit f34405be36
31 changed files with 494 additions and 1556 deletions

View File

@@ -102,7 +102,6 @@ uv run yaml2pptx.py convert presentation.yaml --skip-validation
```yaml
metadata:
size: "16:9" # 或 "4:3"
dpi: 96 # 可选DPI 配置,默认 96
slides:
- background:
@@ -118,24 +117,6 @@ slides:
align: center
```
#### DPI 配置
`metadata.dpi` 参数控制图片处理的分辨率,影响图片质量和文件大小:
- **默认值**96 DPI标准屏幕分辨率
- **建议范围**72-300 DPI
- **常用值**
- 72 DPI网页显示
- 96 DPI标准屏幕默认
- 150 DPI高质量打印
- 300 DPI专业印刷
```yaml
metadata:
size: "16:9"
dpi: 150 # 高质量输出
```
#### description 字段
`metadata.description` 字段用于描述整个演示文稿的概要和用途,仅用于文档目的,不影响生成的 PPTX 文件:
@@ -189,64 +170,16 @@ slides:
- type: image
box: [x, y, width, height]
src: "path/to/image.png" # 支持相对路径和绝对路径
fit: contain # 可选:图片适配模式
background: "#f0f0f0" # 可选:背景色(仅对 contain 和 center 模式有效)
```
#### 图片适配模式
`fit` 参数控制图片如何适配到指定的 box 区域,支持以下模式:
- **stretch**(默认):拉伸图片以填满整个 box可能改变宽高比
- **contain**:保持宽高比,完整显示图片在 box 内,可能留白
- **cover**:保持宽高比,填满整个 box可能裁剪图片
- **center**:不缩放,居中显示,超出部分裁剪
**示例**
```yaml
slides:
- elements:
# 默认 stretch 模式
- type: image
src: "photo.jpg"
box: [1, 1, 4, 3]
# contain 模式,带灰色背景
- type: image
src: "photo.jpg"
box: [5, 1, 4, 3]
fit: contain
background: "#f0f0f0"
# cover 模式,填满区域
- type: image
src: "photo.jpg"
box: [1, 4, 4, 3]
fit: cover
# center 模式,不缩放
- type: image
src: "icon.png"
box: [5, 4, 2, 2]
fit: center
background: "#ffffff"
```
#### 背景色
`background` 参数为图片添加背景色,支持 `#RRGGBB``#RGB` 格式:
- 仅对 `contain``center` 模式有效
- 当图片小于 box 或保持宽高比时,背景色填充留白区域
- 默认为透明(无背景色)
```yaml
- type: image
src: "logo.png"
box: [1, 1, 3, 2]
fit: contain
background: "#ffffff" # 白色背景
```
### 形状元素