feat: implement image composer with Pillow

- compose(): scales print to TransformState.width/height, rotates
  clockwise by TransformState.rotation (negated for Pillow), pastes
  onto a transparent layer via alpha_composite, saves PNG or JPG
- Rotation centre fixed at print bounding-box centre; paste_x/y
  computed from centre - rotated_size/2 per design doc §13.3
- JPG: flattens RGBA onto white RGB background before saving
- Out-of-bounds print clips silently via PIL paste; width/height<=0
  returns ComposeResult(success=False); file errors caught, never raise

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-15 17:28:02 +08:00
co-authored by Claude Sonnet 4.6
parent a6a8504ea8
commit 4b008a0dc8
2 changed files with 129 additions and 16 deletions
+14 -14
View File
@@ -210,23 +210,23 @@
任务:
- [ ] 先读取 `src/core/composer.py` 现有内容
- [ ] 完善 `src/core/composer.py`
- [ ] 使用 Pillow 读取衣服底图和印花图
- [ ] 支持透明 PNG alpha 合成
- [ ] 支持按 `TransformState` 缩放印花
- [ ] 支持按 `TransformState` 旋转印花
- [ ] 支持旋转后按中心点对齐粘贴
- [ ] 支持 PNG 导出
- [ ] 支持 JPG 导出
- [ ] 输出文件名避免默认覆盖
- [x] 先读取 `src/core/composer.py` 现有内容
- [x] 完善 `src/core/composer.py`
- [x] 使用 Pillow 读取衣服底图和印花图
- [x] 支持透明 PNG alpha 合成
- [x] 支持按 `TransformState` 缩放印花
- [x] 支持按 `TransformState` 旋转印花
- [x] 支持旋转后按中心点对齐粘贴
- [x] 支持 PNG 导出
- [x] 支持 JPG 导出
- [x] 输出文件名避免默认覆盖
验收:
- [ ] 合成逻辑不依赖 PySide6 UI 控件
- [ ] 输出尺寸默认与衣服底图一致
- [ ] 透明 PNG 不出现黑底或白底
- [ ] 印花部分超出画布时不会报错
- [x] 合成逻辑不依赖 PySide6 UI 控件
- [x] 输出尺寸默认与衣服底图一致
- [x] 透明 PNG 不出现黑底或白底
- [x] 印花部分超出画布时不会报错
## 6. 批量任务核心