feat: 增加水印

This commit is contained in:
R524809
2026-08-24 17:15:08 +08:00
parent 95cb93a160
commit 024777ed8a
13 changed files with 272 additions and 7 deletions
+5
View File
@@ -18,6 +18,7 @@ from config import get_settings
from services import storage
from services.prompts import build_prompt, build_context, type_name
from services.tasks import Task, TaskImage, TASK_FAILED, TASK_RUNNING, TASK_DONE, TASK_PARTIAL, IMG_FAILED, IMG_OK
from services.watermark import apply_watermark
log = logging.getLogger("suite.generator")
@@ -435,6 +436,10 @@ async def run_suite(task: Task) -> None:
)
refs = _refs_for_job(list(task.ref_images or []), job)
data = await generator(prompt, refs, size=size, model=model)
# 水印:AI 出图返回后、落盘前的后处理(失败不阻断,内部返回原图)
wm = task.watermark or {}
if wm.get("enabled"):
data = apply_watermark(data, wm)
# 部分中转不遵守 output_format(要 jpeg 回 PNG),按魔数定扩展名
ext = ".png" if data[:8] == b"\x89PNG\r\n\x1a\n" else ".jpg"
key = storage.write_bytes(data, key_prefix=f"suites/{task.id}", ext=ext)