perf(图片): 接口2/3/5 返回 JPG(体积~9×↓),接口1 标注图仍 PNG(透明)
- app.py: 接口2(预览+生发)/3(生发)/5(发际线叠图) 编码改 JPG(质量90,env JPG_QUALITY); 接口1 annotated_image 含透明仍 PNG。_png_to_jpg_b64 把 ComfyUI 的 PNG 重编码为 JPG(无法解码则透传) - gateway/forward.py: 落盘按内容嗅探扩展名(PNG头→.png 否则.jpg),原先硬编码 .png - 测试/文档同步;实测接口5 一张 59KB(JPG) vs 548KB(PNG)。pytest 44 全绿 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+3
-2
@@ -102,8 +102,9 @@ def rewrite_base64_to_url(
|
||||
if key.endswith("_base64") and isinstance(value, str):
|
||||
img_bytes = _decode_base64_value(value)
|
||||
if img_bytes is not None:
|
||||
# 生成文件名并落盘
|
||||
filename = f"{uuid.uuid4().hex}.png"
|
||||
# 按内容嗅探扩展名:PNG(接口1标注图,含透明) / JPEG(接口2/3/5 照片)
|
||||
ext = "png" if img_bytes[:8] == b"\x89PNG\r\n\x1a\n" else "jpg"
|
||||
filename = f"{uuid.uuid4().hex}.{ext}"
|
||||
filepath = Path(static_dir) / filename
|
||||
filepath.write_bytes(img_bytes)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user