From 67c320a2dee6c7ac54dfd6a703d02e6cbd177536 Mon Sep 17 00:00:00 2001 From: jinghui Date: Fri, 13 Nov 2026 19:35:03 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9EAI=E6=8D=A2=E8=84=B8?= =?UTF-8?q?=E4=B8=8EAI=E6=B5=B7=E6=8A=A5=E7=94=9F=E6=88=90=E4=B8=A4?= =?UTF-8?q?=E4=B8=AA=E6=8E=88=E6=9D=83=E5=BA=94=E7=94=A8=E2=80=94=E2=80=94?= =?UTF-8?q?=E6=8D=A2=E8=84=B8(insightface=20buffalo=5Fl+inswapper=5F128?= =?UTF-8?q?=E6=9C=AC=E6=9C=BACPU=E6=8E=A8=E7=90=86,=20POST=20/ai/face-swap?= =?UTF-8?q?,=20consent=E5=BF=85=E5=A1=AB,=20=E5=A4=9A=E8=84=B8=E5=8F=96?= =?UTF-8?q?=E6=9C=80=E5=A4=A7);=20=E6=B5=B7=E6=8A=A5(25=E5=A5=97=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF9=E5=88=86=E7=B1=BB,=20=E6=94=B9=E6=96=87=E5=AD=97/?= =?UTF-8?q?=E6=8D=A2=E5=9B=BE=E7=89=87/AI=E7=94=9F=E6=88=90=E9=85=8D?= =?UTF-8?q?=E5=9B=BE=E4=B8=8E=E8=83=8C=E6=99=AF/=E5=9B=BE=E5=B1=82?= =?UTF-8?q?=E5=A2=9E=E5=88=A0=E6=8E=92=E5=BA=8F/=E8=83=8C=E6=99=AF?= =?UTF-8?q?=E9=A2=84=E8=AE=BE,=20=E6=8C=89=E5=AE=BD=E9=AB=98=E6=AF=94?= =?UTF-8?q?=E5=8C=B9=E9=85=8D=E4=B8=8A=E6=B8=B8=E5=B0=BA=E5=AF=B8=E6=A1=A3?= =?UTF-8?q?=E4=BD=8D,=20=E5=AF=BC=E5=87=BA1080x1440=20PNG);=20license.ts?= =?UTF-8?q?=E4=B8=8Erelay=20PROTECTED=5FTOOLS=E5=8F=8C=E7=AB=AF=E6=B3=A8?= =?UTF-8?q?=E5=86=8C=E4=BD=BFpricing/buy=E8=87=AA=E5=8A=A8+2;=20relay?= =?UTF-8?q?=E5=89=AF=E6=9C=AC=E5=90=8C=E6=AD=A5(Dockerfile=E8=A3=85insight?= =?UTF-8?q?face+COPY=20face-models=E4=B8=8D=E5=85=A5=E5=BA=93)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 + README.md | 13 + components.d.ts | 2 + docker/it-tools-relay/.gitignore | 11 + docker/it-tools-relay/Dockerfile | 3 + docker/it-tools-relay/server.py | 211 +++++++++- src/pages/Home.page.vue | 2 + src/tools/face-swap/face-swap.vue | 348 ++++++++++++++++ src/tools/face-swap/index.ts | 11 + src/tools/index.ts | 4 +- src/tools/license/license.ts | 2 + src/tools/poster/index.ts | 11 + src/tools/poster/poster.vue | 631 ++++++++++++++++++++++++++++++ src/tools/poster/templates.ts | 308 +++++++++++++++ 14 files changed, 1552 insertions(+), 8 deletions(-) create mode 100644 docker/it-tools-relay/.gitignore create mode 100644 src/tools/face-swap/face-swap.vue create mode 100644 src/tools/face-swap/index.ts create mode 100644 src/tools/poster/index.ts create mode 100644 src/tools/poster/poster.vue create mode 100644 src/tools/poster/templates.ts diff --git a/.gitignore b/.gitignore index afcd571..9d0f8b3 100644 --- a/.gitignore +++ b/.gitignore @@ -28,6 +28,9 @@ coverage *.sw? .env + +# 本地 AI 换脸模型(宿主预置, 不入库: buffalo_l ~289MB + inswapper_128 ~554MB) +docker/it-tools-relay/face-models/ /test-results/ /playwright-report/ /playwright/.cache/ diff --git a/README.md b/README.md index b09b97e..f1818f6 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,19 @@ - **界面文案**(按所选模型联动):未授权 `免费10次·剩N · CF池剩X/173张` / `… · Pollinations按Key余额`;已授权 `已授权 · CF池剩X/173张`;CF 池尽红色 `CF免费池已用完 · 08:00重置`。 - 额度查询端点 `POST /relay/ai/quota`(带 `model` 返回 `authorized/limit/used/remaining` + `upstream/upstream_daily/upstream_used/upstream_remaining/upstream_note/cf_daily`;`remaining=-1` 表示机器维度不限,仍受共享池约束)。次数用完点「或使用自己的提供商 / API KEY」用自己的 KEY 继续生成,403 提示文案同步引导。 +### AI 换脸(2026.11 新增) + +- 上传源人脸照片 + 目标照片,本机 CPU 一键换脸(insightface buffalo_l 人脸检测,多脸自动取最大 + inswapper_128 换脸模型,模型 855MB 预置于镜像内)。 +- 接口 `POST /relay/ai/face-swap`(multipart:`source`/`target`/`consent`),需勾选授权承诺,结果走站内 `/relay/ai/img` 图链路,支持下载。 +- 授权应用:未授权用户每天可免费试用 3 次,卡密激活后不限次。 + +### AI 海报生成(2026.11 新增) + +- 25 套热门海报模板、9 大分类(促销/节日/活动/美食/教育/健身/招聘/生日/封面),模板画布 1080×1440。 +- 选中模板后可:**修改文字**(内容/字号/颜色/粗细/对齐/行高/斜体,预览与导出换行一致)、**替换图片**(本地上传 或 AI 生成,圆角可调)、拖动移动图层、图层排序/删除、添加文字与图片框、一键切换背景渐变、AI 生成整屏背景。 +- AI 配图复用 `/relay/ai/gen-image` 与每日免费生图额度,按图框宽高比自动匹配上游尺寸档位。 +- 完成后一键导出 1080×1440 PNG。授权应用,支持每日免费试用。 + ## 优势 - **一次激活,全站通用**:输入一次卡密,全部授权功能解锁,无需逐个购买 diff --git a/components.d.ts b/components.d.ts index e83d5ea..5dcd98a 100644 --- a/components.d.ts +++ b/components.d.ts @@ -91,6 +91,7 @@ declare module '@vue/runtime-core' { EmojiPicker: typeof import('./src/tools/emoji-picker/emoji-picker.vue')['default'] Encryption: typeof import('./src/tools/encryption/encryption.vue')['default'] EtaCalculator: typeof import('./src/tools/eta-calculator/eta-calculator.vue')['default'] + FaceSwap: typeof import('./src/tools/face-swap/face-swap.vue')['default'] FavoriteButton: typeof import('./src/components/FavoriteButton.vue')['default'] FeedbackModal: typeof import('./src/components/FeedbackModal.vue')['default'] FormatTransformer: typeof import('./src/components/FormatTransformer.vue')['default'] @@ -217,6 +218,7 @@ declare module '@vue/runtime-core' { PercentageCalculator: typeof import('./src/tools/percentage-calculator/percentage-calculator.vue')['default'] PhoneParserAndFormatter: typeof import('./src/tools/phone-parser-and-formatter/phone-parser-and-formatter.vue')['default'] PinyinConverter: typeof import('./src/tools/pinyin-converter/pinyin-converter.vue')['default'] + Poster: typeof import('./src/tools/poster/poster.vue')['default'] 'Pricing.page': typeof import('./src/pages/Pricing.page.vue')['default'] PsEditor: typeof import('./src/tools/image-tools/PsEditor.vue')['default'] QrCodeGenerator: typeof import('./src/tools/qr-code-generator/qr-code-generator.vue')['default'] diff --git a/docker/it-tools-relay/.gitignore b/docker/it-tools-relay/.gitignore new file mode 100644 index 0000000..ad537d3 --- /dev/null +++ b/docker/it-tools-relay/.gitignore @@ -0,0 +1,11 @@ +.env +data/ +__pycache__/ +*.pyc +hf-cache/ +piper-models/ +ai-models/ +waifu2x/ +face-models/ +*.log +.venv-hf/ diff --git a/docker/it-tools-relay/Dockerfile b/docker/it-tools-relay/Dockerfile index 2c854de..2e8e83c 100644 --- a/docker/it-tools-relay/Dockerfile +++ b/docker/it-tools-relay/Dockerfile @@ -7,7 +7,10 @@ RUN apt-get update \ # models are pre-downloaded on the host (build env has no internet) RUN pip install --no-cache-dir piper-tts faster-whisper RUN pip install --no-cache-dir -i https://pypi.tuna.tsinghua.edu.cn/simple "rembg[cpu]" +# AI 换脸: insightface(纯Python wheel 免编译) + buffalo_l人脸检测 + inswapper_128换脸模型(宿主已预置) +RUN pip install --no-cache-dir -i https://pypi.tuna.tsinghua.edu.cn/simple insightface COPY hf-cache /root/.cache/huggingface +COPY face-models /app/face-models COPY piper-models /app/piper-models # AI 图片: u2net 抠图模型(预下载) + waifu2x-ncnn-vulkan 无损放大(CPU) COPY ai-models/u2net.onnx /root/.u2net/u2net.onnx diff --git a/docker/it-tools-relay/server.py b/docker/it-tools-relay/server.py index 61f447a..68fcd90 100644 --- a/docker/it-tools-relay/server.py +++ b/docker/it-tools-relay/server.py @@ -68,7 +68,7 @@ CF_DAILY_LIMIT = int(os.environ.get("CF_DAILY_LIMIT", "173")) CF_DAILY_FILE = os.environ.get("CF_DAILY_FILE", "/app/data/daily_gen_cf.json") DAY_MS = 24 * 60 * 60 * 1000 TZ_OFFSET_MS = 8 * 60 * 60 * 1000 # 北京时间 UTC+8 —— 重置对齐自然日 0 点 -PROTECTED_TOOLS = {"translator", "image-ocr", "pdf-ocr", "ai-retouch", "doc-convert", "image-tools", "pdf-tools", "video-tools", "audio-tools", "text-to-image", "ai-image-tools", "copywriting", "screenshot-qa", "video-subtitle", "ai-gen", "ai-text-edit"} +PROTECTED_TOOLS = {"translator", "image-ocr", "pdf-ocr", "ai-retouch", "doc-convert", "image-tools", "pdf-tools", "video-tools", "audio-tools", "text-to-image", "ai-image-tools", "copywriting", "screenshot-qa", "video-subtitle", "ai-gen", "ai-text-edit", "face-swap", "poster-maker"} MACHINE_RE = re.compile(r"^\d{10,16}$") # verify() messages that unconditionally block activation @@ -711,6 +711,51 @@ def check(machine: str, tool: str) -> int: return 200 if trial_allowed(machine, tool) else 403 +# ---- AI 换脸引擎:insightface buffalo_l 人脸检测 + inswapper_128 换脸(本机 CPU 推理) ---- +_FACE_LOCK = threading.Lock() +_FACE_APP = None +_FACE_SWAP = None +_FACE_MODELS_DIR = os.environ.get("FACE_MODELS_DIR", "/app/face-models") + + +def _face_engine(): + """懒加载换脸引擎(线程安全;首次调用约 1~2s,之后常驻内存复用)。""" + global _FACE_APP, _FACE_SWAP + if _FACE_APP is None: + from insightface.app import FaceAnalysis + from insightface import model_zoo + app = FaceAnalysis(name="buffalo_l", root=_FACE_MODELS_DIR, providers=["CPUExecutionProvider"]) + app.prepare(ctx_id=0, det_size=(640, 640)) + swap = model_zoo.get_model(os.path.join(_FACE_MODELS_DIR, "inswapper_128.onnx"), + providers=["CPUExecutionProvider"]) + _FACE_APP, _FACE_SWAP = app, swap + return _FACE_APP, _FACE_SWAP + + +def _largest_face(faces): + """多张脸时取面积最大的一张(换脸默认作用于最显眼的人脸)。""" + return max(faces, key=lambda f: float((f.bbox[2] - f.bbox[0]) * (f.bbox[3] - f.bbox[1]))) + + +def _face_swap_run(src_img, dst_img): + """源人脸 -> 目标照片。返回 (jpg字节|None, 错误信息, 耗时ms)。加锁串行避免并发吃满 CPU。""" + import cv2 as _cv2 + t0 = time.time() + with _FACE_LOCK: + app, swap = _face_engine() + src_faces = app.get(src_img) + dst_faces = app.get(dst_img) + if not src_faces: + return None, "源图中未检测到人脸,请换一张清晰的正脸照片", 0 + if not dst_faces: + return None, "目标图中未检测到人脸,请换一张含人物的照片", 0 + out = swap.get(dst_img, _largest_face(dst_faces), _largest_face(src_faces), paste_back=True) + ok, buf = _cv2.imencode(".jpg", out, [int(_cv2.IMWRITE_JPEG_QUALITY), 92]) + if not ok: + return None, "结果编码失败", 0 + return buf.tobytes(), None, int((time.time() - t0) * 1000) + + def _account_license_ok(machine: str) -> bool: """True when this device logged into an authorized account. @@ -3124,6 +3169,9 @@ class Handler(BaseHTTPRequestHandler): if parsed.path == "/ai/edit-image": self._handle_edit_image() return + if parsed.path == "/ai/face-swap": + self._handle_face_swap() + return if parsed.path == "/ai/seamless-edit": self._handle_seamless_edit() return @@ -3204,6 +3252,51 @@ class Handler(BaseHTTPRequestHandler): self._reply(404, b"not found") + # ---------- 中文提示词自动转英文(Flux/SDXL 系对英文理解最好) ---------- + _ZH_RE = re.compile(r"[\u4e00-\u9fff]") + _trans_cache: dict = {} + + def _translate_prompt(self, prompt: str): + """含中文才翻;成功 (英文, True);失败/未配置回退 (原文, False),绝不阻断生图。""" + if not prompt or not self._ZH_RE.search(prompt): + return prompt, False + cached = self._trans_cache.get(prompt) + if cached: + return cached, True + key = os.environ.get("NEWAPI_KEY", "") + if not key: + return prompt, False + try: + body = json.dumps({ + "model": os.environ.get("IMG_PROMPT_MODEL", "mimo-v2.6-flash"), + "messages": [ + {"role": "system", "content": ( + "You are an expert prompt engineer for text-to-image models (Flux / SDXL / DALL-E). " + "Translate the user's Chinese image prompt into ONE high-quality English image-generation prompt. " + "Preserve every style, composition, aspect-ratio, lighting and detail keyword; you may expand " + "slightly for natural flow. Output ONLY the English prompt itself - no quotes, no explanations, " + "no Chinese characters, no markdown.")}, + {"role": "user", "content": prompt}, + ], + "temperature": 0.3, "max_tokens": 500, + }).encode() + req = request.Request( + os.environ.get("NEWAPI_URL", "http://192.168.68.19:3099/v1/chat/completions"), + data=body, headers={"Content-Type": "application/json", "Authorization": "Bearer " + key}) + data = json.loads(request.urlopen(req, timeout=30).read()) + en = str(data.get("choices", [{}])[0].get("message", {}).get("content") or "").strip() + en = en.strip("`\"'\u201c\u201d ").strip() + if not en or self._ZH_RE.search(en[:120]): + return prompt, False + if len(self._trans_cache) >= 300: + self._trans_cache.clear() + self._trans_cache[prompt] = en + print(f"[img] prompt translated: {prompt[:40]} -> {en[:70]}", flush=True) + return en, True + except Exception as e: # noqa: BLE001 + print(f"[img] translate failed, use original: {e}", flush=True) + return prompt, False + # ---------- AI 生图 (NEWAPI) ---------- def _nm_base(self): return os.environ.get("NEWAPI_URL", "http://192.168.68.19:3099/v1/chat/completions").replace("/chat/completions", "") @@ -3256,7 +3349,7 @@ class Handler(BaseHTTPRequestHandler): b64 = item.get("b64_json") or "" if not url and not b64: raise RuntimeError("上游未返回图片") - self._reply(200, json.dumps({"code": 200, "message": "ok", "data": {"url": url, "b64": b64, "img_url": (d.get("img_url") or "") if isinstance(d, dict) else ""}}, ensure_ascii=False).encode("utf-8"), "application/json") + self._reply(200, json.dumps({"code": 200, "message": "ok", "data": {"url": url, "b64": b64, "img_url": (d.get("img_url") or "") if isinstance(d, dict) else "", "prompt_en": (d.get("prompt_en") or "") if isinstance(d, dict) else ""}}, ensure_ascii=False).encode("utf-8"), "application/json") def _handle_image_models(self): try: @@ -3302,7 +3395,7 @@ class Handler(BaseHTTPRequestHandler): msg = str(err or d.get("message") or "") raise RuntimeError(msg[:300] or "上游未返回图片") - def _persist_gen_image(self, machine, d, model, prompt, w, h): + def _persist_gen_image(self, machine, d, model, prompt, w, h, kind="gen"): """把生成结果落盘并写入该机器的历史索引;返回站内图片 URL(任何失败返回空串)。""" try: if not self._gen_machine_ok(machine): @@ -3321,6 +3414,14 @@ class Handler(BaseHTTPRequestHandler): raw = rr.read() if not raw or len(raw) < 200: return "" + if not (w and h): + try: + from PIL import Image as _PIL + import io as _io + _im = _PIL.open(_io.BytesIO(raw)) + w, h = _im.size + except Exception: + w, h = 0, 0 if raw[:8] == b"\x89PNG\r\n\x1a\n": ext = ".png" elif raw[:2] == b"\xff\xd8": @@ -3349,6 +3450,7 @@ class Handler(BaseHTTPRequestHandler): idx = [] idx.insert(0, {"id": iid, "file": fname, "at": int(time.time()), "model": str(model)[:60], "prompt": str(prompt)[:500], + "kind": str(kind or "gen")[:20], "w": w, "h": h}) while len(idx) > 100: old = idx.pop() or {} @@ -3525,20 +3627,24 @@ class Handler(BaseHTTPRequestHandler): w, h = 1024, 1024 w = max(16, min(2048, w)) h = max(16, min(2048, h)) + # 中文提示词自动转英文再发上游(Flux/SDXL 英文效果最好;翻译失败回退原文) + gen_prompt, translated = self._translate_prompt(prompt) try: if own_provider: - d = self._provider_images_gen(provider, model, prompt, f"{w}x{h}") + d = self._provider_images_gen(provider, model, gen_prompt, f"{w}x{h}") else: - d = self._nm_images_gen(model, prompt, f"{w}x{h}") + d = self._nm_images_gen(model, gen_prompt, f"{w}x{h}") daily_consume(machine, model) # 内置渠道成功才扣次(机器计数 + CF 共享池) except Exception as e: # noqa: BLE001 print(f"[img] gen failed: {e}", flush=True) self._reply(502, json.dumps({"code": 502, "message": f"生图失败:{e}"}, ensure_ascii=False).encode("utf-8"), "application/json") return # 落盘保存到该机器的历史(失败不阻断响应) - img_url = self._persist_gen_image(machine, d, model, prompt, w, h) + img_url = self._persist_gen_image(machine, d, model, prompt, w, h) # 历史存用户原文 if isinstance(d, dict) and img_url: d["img_url"] = img_url + if translated and isinstance(d, dict): + d["prompt_en"] = gen_prompt # 实际发给上游的英文提示词(供前端提示) self._img_reply_ok(d) def _handle_edit_image(self): @@ -3565,8 +3671,11 @@ class Handler(BaseHTTPRequestHandler): return try: img = up.file.read() - d = self._nm_images_edit(model, prompt, img, up.filename) + gen_prompt, translated = self._translate_prompt(prompt) + d = self._nm_images_edit(model, gen_prompt, img, up.filename) daily_consume(machine, model) # 内置渠道成功才扣次(机器计数 + CF 共享池) + if translated and isinstance(d, dict): + d["prompt_en"] = gen_prompt self._img_reply_ok(d) except Exception as e: # noqa: BLE001 print(f"[img] edit failed: {e}", flush=True) @@ -3820,6 +3929,94 @@ class Handler(BaseHTTPRequestHandler): canvas.paste(im2, ((tw - im2.width) // 2, (th - im2.height) // 2)) return canvas + def _handle_face_swap(self): + """AI换脸(授权功能):源人脸照片 -> 目标照片,本机 CPU 推理,结果走 /ai/img 站内图链路。""" + machine = self.headers.get("X-Machine-Id", "") + code = check(machine, "face-swap") + if code != 200: + self._reply(403, json.dumps({"code": 403, "message": "AI换脸是授权功能:试用期内可免费体验,正式使用请先激活卡密"}, + ensure_ascii=False).encode("utf-8"), "application/json") + return + log_usage(machine, "face-swap") + ctype = self.headers.get("Content-Type") or "" + if "multipart/form-data" not in ctype: + self._reply(400, json.dumps({"code": 400, "message": "需要 multipart/form-data"}, ensure_ascii=False).encode("utf-8"), "application/json") + return + try: + form = cgi.FieldStorage(fp=self.rfile, headers=self.headers, + environ={"REQUEST_METHOD": "POST", "CONTENT_TYPE": ctype}) + except Exception as e: # noqa: BLE001 + self._reply(400, json.dumps({"code": 400, "message": f"表单解析失败: {e}"}, ensure_ascii=False).encode("utf-8"), "application/json") + return + if str(form.getvalue("consent") or "") != "1": + self._reply(400, json.dumps({"code": 400, "message": "请先勾选「我承诺仅使用已获本人授权的照片进行换脸」"}, + ensure_ascii=False).encode("utf-8"), "application/json") + return + try: + src_raw = form["source"].file.read() if "source" in form else b"" + dst_raw = form["target"].file.read() if "target" in form else b"" + except Exception: + src_raw, dst_raw = b"", b"" + if not src_raw or not dst_raw: + self._reply(400, json.dumps({"code": 400, "message": "请同时上传源人脸照片与目标照片"}, ensure_ascii=False).encode("utf-8"), "application/json") + return + if len(src_raw) > 15 * 1024 * 1024 or len(dst_raw) > 15 * 1024 * 1024: + self._reply(400, json.dumps({"code": 400, "message": "单张图片不能超过 15MB"}, ensure_ascii=False).encode("utf-8"), "application/json") + return + import cv2 as _cv2 + import numpy as _np + src_img = _cv2.imdecode(_np.frombuffer(src_raw, _np.uint8), _cv2.IMREAD_COLOR) + dst_img = _cv2.imdecode(_np.frombuffer(dst_raw, _np.uint8), _cv2.IMREAD_COLOR) + if src_img is None or dst_img is None: + self._reply(400, json.dumps({"code": 400, "message": "图片解码失败,请上传 JPG/PNG 等常见格式"}, ensure_ascii=False).encode("utf-8"), "application/json") + return + try: + out_jpg, msg, ms = _face_swap_run(src_img, dst_img) + except Exception as e: # noqa: BLE001 + print(f"[face-swap] failed: {e}", flush=True) + self._reply(500, json.dumps({"code": 500, "message": f"换脸失败: {e}"}, ensure_ascii=False).encode("utf-8"), "application/json") + return + if out_jpg is None: + self._reply(400, json.dumps({"code": 400, "message": msg}, ensure_ascii=False).encode("utf-8"), "application/json") + return + try: + gen_dir = os.path.join(DATA_DIR, "gen_images", machine) + os.makedirs(gen_dir, exist_ok=True) + iid = f"{int(time.time())}_{uuid.uuid4().hex[:8]}" + with open(os.path.join(gen_dir, iid + ".jpg"), "wb") as f: + f.write(out_jpg) + idx_path = os.path.join(gen_dir, "index.json") + with GEN_IMG_LOCK: + idx = [] + if os.path.exists(idx_path): + try: + idx = json.load(open(idx_path, encoding="utf-8")) + if not isinstance(idx, list): + idx = [] + except Exception: + idx = [] + idx.insert(0, {"id": iid, "file": iid + ".jpg", "at": int(time.time()), + "model": "AI换脸", "prompt": "face-swap", + "w": int(dst_img.shape[1]), "h": int(dst_img.shape[0])}) + while len(idx) > 100: + old = idx.pop() or {} + fn = str(old.get("file") or "") + if fn and "/" not in fn and "\\" not in fn: + try: + os.remove(os.path.join(gen_dir, fn)) + except Exception: + pass + with open(idx_path, "w", encoding="utf-8") as f: + json.dump(idx, f, ensure_ascii=False) + except Exception as e: # noqa: BLE001 + print(f"[face-swap] persist failed: {e}", flush=True) + self._reply(500, json.dumps({"code": 500, "message": "结果保存失败"}, ensure_ascii=False).encode("utf-8"), "application/json") + return + body = json.dumps({"code": 200, "message": "ok", + "data": {"url": f"/relay/ai/img/{machine}/{iid}", "elapsed_ms": ms}}, + ensure_ascii=False).encode("utf-8") + self._reply(200, body, "application/json") + def _handle_seamless_edit(self): machine = self.headers.get("X-Machine-Id", "") if check(machine, "ai-text-edit") != 200: diff --git a/src/pages/Home.page.vue b/src/pages/Home.page.vue index c5872e3..828cb57 100644 --- a/src/pages/Home.page.vue +++ b/src/pages/Home.page.vue @@ -11,6 +11,8 @@ import { useRecentTools } from '@/composable/recent-tools'; // 近期新功能亮点(手动维护,新工具上线时加一条) // ★铁规则:每完成一批新功能/新工具,必须在这里最前面加条目(新→旧),否则首页看不到 const NEW_FEATURES = [ + { path: '/face-swap', icon: '🎭', name: 'AI 换脸', desc: '上传源人脸与目标照片,本地 AI 一键换脸(insightface 人脸检测+inswapper),授权功能支持免费试用' }, + { path: '/poster-maker', icon: '🖼️', name: 'AI 海报生成', desc: '热门海报模板任选:改文字、换图片、AI 生成配图与背景,一键导出 PNG' }, { path: '/ai-gen', icon: '🎨', name: 'AI 生图', desc: '10款内置模型一键出图,四组86个现成提示词(通用/自媒体/电商/软件类),中文自动转英文发送' }, { path: '/mcp-connect', icon: '🔌', name: 'AI 接入 (MCP)', desc: '把本站能力接到任意 AI 客户端,13个工具、卡密令牌管理、调用记录后台可查' }, { path: '/admin', icon: '📊', name: '管理后台升级', desc: '使用统计含未登录访客、在线人数实时排行、留言反馈与公告推送、用户最后登录时间' }, diff --git a/src/tools/face-swap/face-swap.vue b/src/tools/face-swap/face-swap.vue new file mode 100644 index 0000000..fb9316f --- /dev/null +++ b/src/tools/face-swap/face-swap.vue @@ -0,0 +1,348 @@ + + + + + diff --git a/src/tools/face-swap/index.ts b/src/tools/face-swap/index.ts new file mode 100644 index 0000000..57c0366 --- /dev/null +++ b/src/tools/face-swap/index.ts @@ -0,0 +1,11 @@ +import { FaceId } from '@vicons/tabler'; +import { defineTool } from '../tool'; + +export const tool = defineTool({ + name: 'AI 换脸', + path: '/face-swap', + description: 'AI 换脸:上传源人脸与目标照片,本地 AI 一键换脸', + keywords: ['ai', '换脸', 'face', 'swap', '人脸', '人脸替换', 'ai换脸', '头像', '表情'], + component: () => import('./face-swap.vue'), + icon: FaceId, +}); diff --git a/src/tools/index.ts b/src/tools/index.ts index a19b644..c3a50c9 100644 --- a/src/tools/index.ts +++ b/src/tools/index.ts @@ -96,6 +96,8 @@ import { tool as copywriting } from './copywriting'; import { tool as mcpConnect } from './mcp-connect'; import { tool as docConvert } from './doc-convert'; import { tool as aiRetouch } from './ai-retouch'; +import { tool as faceSwap } from './face-swap'; +import { tool as posterMaker } from './poster'; import { tool as wifiQrCodeGenerator } from './wifi-qr-code-generator'; import { tool as randomPortGenerator } from './random-port-generator'; import { tool as romanNumeralConverter } from './roman-numeral-converter'; @@ -166,7 +168,7 @@ export const toolsByCategory: ToolCategory[] = [ }, { name: 'Images and videos', - components: [qrCodeGenerator, wifiQrCodeGenerator, batchBarcodeGenerator, codeReader, imageOcr, pdfOcr, pdfTools, imageTools, base64ImageConverter, videoTools, audioTools, sealMaker, signaturePad, textToImage, aiGen, docConvert, aiRetouch, labelDesigner, siteBookmarks, svgPlaceholderGenerator, cameraRecorder], + components: [qrCodeGenerator, wifiQrCodeGenerator, batchBarcodeGenerator, codeReader, imageOcr, pdfOcr, pdfTools, imageTools, base64ImageConverter, videoTools, audioTools, sealMaker, signaturePad, textToImage, aiGen, docConvert, aiRetouch, faceSwap, posterMaker, labelDesigner, siteBookmarks, svgPlaceholderGenerator, cameraRecorder], }, { name: 'Development', diff --git a/src/tools/license/license.ts b/src/tools/license/license.ts index 606f4ee..ac29085 100644 --- a/src/tools/license/license.ts +++ b/src/tools/license/license.ts @@ -19,6 +19,8 @@ export const PROTECTED_TOOLS: Record = { '/ai-image-lab': 'AI图片实验室', '/copywriting': '文案工具箱', '/ai-gen': 'AI 生图', + '/face-swap': 'AI换脸', + '/poster-maker': 'AI海报生成', }; export const TRIAL_MS = 30 * 60 * 1000; // 每个功能每天免费 30 分钟 diff --git a/src/tools/poster/index.ts b/src/tools/poster/index.ts new file mode 100644 index 0000000..03ad29c --- /dev/null +++ b/src/tools/poster/index.ts @@ -0,0 +1,11 @@ +import { Template } from '@vicons/tabler'; +import { defineTool } from '../tool'; + +export const tool = defineTool({ + name: 'AI 海报', + path: '/poster-maker', + description: 'AI 海报生成:热门海报模板任选,改文字、换图片、AI 配图,一键导出 PNG', + keywords: ['poster', '海报', '模板', '宣传图', '朋友圈', '小红书', '电商', '海报生成', 'ai海报'], + component: () => import('./poster.vue'), + icon: Template, +}); diff --git a/src/tools/poster/poster.vue b/src/tools/poster/poster.vue new file mode 100644 index 0000000..824ddd7 --- /dev/null +++ b/src/tools/poster/poster.vue @@ -0,0 +1,631 @@ + + + + + diff --git a/src/tools/poster/templates.ts b/src/tools/poster/templates.ts new file mode 100644 index 0000000..a6d9cd8 --- /dev/null +++ b/src/tools/poster/templates.ts @@ -0,0 +1,308 @@ +// AI 海报模板库 —— 设计尺寸 1080×1440(3:4 通用朋友圈/小红书/电商比例) +// 模板 = 背景(纯色/线性渐变) + 图层列表(文字/图片/色块),加载后进入画布编辑: +// 支持改文字(内容/字号/颜色/粗细/对齐)、换图片(上传/AI生成)、拖动移动、增删图层、导出 PNG。 + +export interface PosterTextShadow { color: string; blur: number; y: number } + +export interface PosterTextLayer { + type: 'text'; + text: string; + x: number; y: number; w: number; + size: number; + color: string; + weight?: number; + align?: 'left' | 'center' | 'right'; + lineHeight?: number; // 倍数,默认 1.25 + italic?: boolean; + shadow?: PosterTextShadow; +} + +export interface PosterImageLayer { + type: 'image'; + x: number; y: number; w: number; h: number; + radius?: number; + src?: string; // 当前图片(上传或 AI 生成后写入) + prompt?: string; // AI 生成默认提示词 +} + +export interface PosterShapeLayer { + type: 'shape'; + shape: 'rect' | 'ellipse'; + x: number; y: number; w: number; h: number; + fill: string; + radius?: number; + opacity?: number; +} + +export type PosterLayer = PosterTextLayer | PosterImageLayer | PosterShapeLayer; + +export interface PosterBg { + color?: string; + angle?: number; + stops?: { c: string; p: number }[]; +} + +export interface PosterTemplate { + id: string; + name: string; + category: string; + w: number; + h: number; + bg: PosterBg; + layers: PosterLayer[]; +} + +export const POSTER_W = 1080; +export const POSTER_H = 1440; + +export const POSTER_CATS = [ + { id: 'hot', name: '热门' }, + { id: 'promo', name: '促销' }, + { id: 'festival', name: '节日' }, + { id: 'event', name: '活动' }, + { id: 'food', name: '美食' }, + { id: 'edu', name: '教育' }, + { id: 'sport', name: '健身' }, + { id: 'recruit', name: '招聘' }, + { id: 'birthday', name: '生日' }, + { id: 'redbook', name: '封面' }, +]; + +const tx = (text: string, x: number, y: number, w: number, size: number, color: string, + o: Partial = {}): PosterTextLayer => + ({ type: 'text', text, x, y, w, size, color, weight: 700, align: 'center', lineHeight: 1.25, ...o }); + +const im = (x: number, y: number, w: number, h: number, prompt = '', o: Partial = {}): PosterImageLayer => + ({ type: 'image', x, y, w, h, radius: 24, prompt, ...o }); + +const sh = (shape: 'rect' | 'ellipse', x: number, y: number, w: number, h: number, fill: string, + o: Partial = {}): PosterShapeLayer => + ({ type: 'shape', shape, x, y, w, h, fill, ...o }); + +const solid = (color: string): PosterBg => ({ color }); +const grad = (angle: number, c1: string, c2: string): PosterBg => + ({ angle, stops: [{ c: c1, p: 0 }, { c: c2, p: 1 }] }); + +const mk = (id: string, name: string, category: string, bg: PosterBg, layers: PosterLayer[]): PosterTemplate => + ({ id, name, category, w: POSTER_W, h: POSTER_H, bg, layers }); + +export const POSTER_TEMPLATES: PosterTemplate[] = [ + // ---------------- 促销 ---------------- + mk('shuang11', '双11狂购节', 'promo', grad(135, '#ff2d55', '#ff9500'), [ + sh('ellipse', 640, 60, 420, 420, 'rgba(255,255,255,0.13)'), + sh('ellipse', -60, 240, 300, 300, 'rgba(255,255,255,0.10)'), + tx('双11狂购节', 50, 380, 980, 140, '#ffffff', { weight: 900 }), + tx('全场5折起 · 满300减50', 50, 570, 980, 56, '#ffe082'), + sh('rect', 340, 668, 400, 96, '#ffd60a', { radius: 48 }), + tx('限时抢购 手慢无', 340, 686, 400, 44, '#c62828'), + im(90, 830, 900, 430, '双11电商促销商品堆头,礼盒购物袋红色节日氛围,电商海报', { radius: 28 }), + tx('活动时间:11月1日 - 11月11日', 50, 1300, 980, 40, '#ffffff', { weight: 400 }), + ]), + mk('d618', '618年中大促', 'promo', grad(120, '#0052ff', '#00c6ff'), [ + tx('618年中大促', 50, 290, 980, 150, '#ffffff', { weight: 900 }), + tx('跨店每满300减50', 50, 490, 980, 60, '#ffd60a', { weight: 900 }), + im(140, 640, 800, 560, '618蓝色科技感电商商品展示,礼盒光效,促销banner', { radius: 32 }), + sh('rect', 340, 1258, 400, 92, '#ffd60a', { radius: 46 }), + tx('立即抢购', 340, 1274, 400, 44, '#0052ff'), + ]), + mk('qingcang', '清仓大甩卖', 'promo', solid('#ffd60a'), [ + tx('清仓大甩卖', 50, 230, 980, 170, '#d32f2f', { weight: 900 }), + tx('全场1折起', 50, 450, 980, 110, '#111111', { weight: 900 }), + tx('数量有限 售完即止', 50, 610, 980, 48, '#333333'), + im(120, 740, 840, 460, '工厂清仓甩卖商品堆头,衣服鞋帽纸箱,黄色促销海报', { radius: 24 }), + sh('ellipse', 380, 1250, 320, 170, '#d32f2f'), + tx('速抢', 380, 1298, 320, 56, '#ffffff', { weight: 900 }), + ]), + mk('kaixin', '新店开业', 'promo', grad(135, '#e53935', '#ff7043'), [ + sh('ellipse', -100, -80, 420, 420, 'rgba(255,255,255,0.12)'), + tx('新店开业', 50, 320, 980, 165, '#ffffff', { weight: 900 }), + tx('全场8折 · 进店有礼', 50, 540, 980, 60, '#ffe082'), + im(120, 700, 840, 480, '新店铺开业花篮与门头,喜庆红色氛围,开业典礼照片', { radius: 24 }), + tx('地址:XX路88号 · 电话:138-0000-0000', 50, 1270, 980, 42, '#ffffff', { weight: 400 }), + ]), + + // ---------------- 节日 ---------------- + mk('chunjie', '新春快乐', 'festival', grad(135, '#c62828', '#ff8f00'), [ + sh('ellipse', 390, 130, 300, 300, 'rgba(255,213,79,0.92)'), + tx('2026', 390, 226, 300, 72, '#c62828', { weight: 900 }), + tx('新春快乐', 50, 520, 980, 190, '#ffd54f', { weight: 900, shadow: { color: 'rgba(120,0,0,0.45)', blur: 24, y: 8 } }), + tx('万事如意 · 阖家幸福 · 财源广进', 50, 770, 980, 52, '#ffffff', { weight: 700 }), + im(140, 900, 800, 400, '中国春节红灯笼与梅花,喜庆新年氛围摄影', { radius: 24 }), + tx('恭祝全市人民 新年大吉', 50, 1350, 980, 46, '#ffe0b2', { weight: 400 }), + ]), + mk('zhongqiu', '中秋团圆', 'festival', grad(160, '#1a237e', '#6a1b9a'), [ + tx('中秋佳节', 50, 250, 980, 175, '#ffd54f', { weight: 900 }), + tx('月圆人团圆', 50, 455, 980, 70, '#ffffff'), + im(190, 620, 700, 700, '满月夜空,金色月亮特写,中秋节深蓝色氛围', { radius: 350 }), + tx('但愿人长久 千里共婵娟', 50, 1372, 980, 44, '#c5cae9', { weight: 400 }), + ]), + mk('shengdan', '圣诞快乐', 'festival', solid('#2e7d32'), [ + tx('圣诞快乐', 50, 230, 980, 175, '#ff5252', { weight: 900, shadow: { color: 'rgba(0,0,0,0.35)', blur: 18, y: 6 } }), + tx('Merry Christmas', 50, 440, 980, 54, '#ffffff', { weight: 400, italic: true }), + im(140, 570, 800, 550, '圣诞树彩灯装饰,温暖圣诞夜氛围', { radius: 24 }), + sh('rect', 330, 1185, 420, 100, '#ff5252', { radius: 50 }), + tx('圣诞好礼8折', 330, 1207, 420, 44, '#ffffff'), + tx('12月24日 - 12月26日', 50, 1340, 980, 40, '#c8e6c9', { weight: 400 }), + ]), + mk('yuandan', '元旦快乐', 'festival', grad(135, '#0d47a1', '#00acc1'), [ + tx('元旦快乐', 50, 300, 980, 165, '#ffffff', { weight: 900 }), + tx('2026 新年新气象', 50, 510, 980, 64, '#b3e5fc'), + im(120, 680, 840, 470, '跨年城市夜空烟花,蓝色新年氛围摄影', { radius: 24 }), + tx('愿所有美好如期而至', 50, 1240, 980, 54, '#ffffff', { weight: 700 }), + tx('Happy New Year', 50, 1345, 980, 40, '#b3e5fc', { weight: 400, italic: true }), + ]), + + // ---------------- 活动 ---------------- + mk('choujiang', '幸运大抽奖', 'event', grad(135, '#6a1b9a', '#e91e63'), [ + sh('ellipse', 340, 110, 400, 400, 'rgba(255,255,255,0.15)'), + tx('抽', 340, 205, 400, 200, '#ffd60a', { weight: 900 }), + tx('幸运大抽奖', 50, 580, 980, 150, '#ffffff', { weight: 900 }), + tx('100%中奖 · 最高赢免单', 50, 770, 980, 60, '#ffd60a'), + im(140, 900, 800, 380, '抽奖转盘与紫色礼盒,霓虹活动海报背景', { radius: 24 }), + sh('rect', 340, 1320, 400, 90, '#ffd60a', { radius: 45 }), + tx('立即参与', 340, 1338, 400, 44, '#6a1b9a'), + ]), + mk('fenxiang', '行业分享会', 'event', solid('#263238'), [ + sh('rect', 80, 110, 12, 130, '#00acc1'), + tx('行业干货分享会', 130, 118, 870, 72, '#80deea', { align: 'left', weight: 700 }), + tx('时间:11月20日 14:00\n地点:市图书馆 · 报告厅', 80, 320, 920, 44, '#b0bec5', { align: 'left', weight: 400, lineHeight: 1.6 }), + im(80, 560, 920, 540, '讲师舞台演讲分享会现场,PPT大屏,专业会议照片', { radius: 16 }), + sh('rect', 80, 1180, 920, 180, 'rgba(0,172,193,0.18)', { radius: 20 }), + tx('限额50名 · 报名免费', 120, 1244, 840, 46, '#80deea', { align: 'left', weight: 700 }), + ]), + mk('huiyuan', '会员日', 'event', solid('#ff6f00'), [ + tx('会员日', 50, 280, 980, 180, '#ffffff', { weight: 900 }), + tx('每月8日 双倍积分', 50, 510, 980, 66, '#ffe0b2'), + im(190, 660, 700, 560, '橙色暖调会员积分礼品展示,电商会员日配图', { radius: 28 }), + tx('更有会员专属价等你来抢', 50, 1280, 980, 48, '#ffffff', { weight: 700 }), + ]), + + // ---------------- 美食 ---------------- + mk('huoguo', '招牌火锅', 'food', solid('#b71c1c'), [ + tx('沸腾火锅', 50, 230, 980, 160, '#ffd54f', { weight: 900 }), + tx('麻辣鲜香 · 越煮越有味', 50, 430, 980, 56, '#ffffff'), + im(110, 580, 860, 560, '红油火锅翻滚特写,辣椒花椒热气腾腾,美食摄影', { radius: 24 }), + tx('进店消费满100送50', 50, 1220, 980, 52, '#ffd54f', { weight: 900 }), + tx('地址:美食街A12 · 11:00-次日02:00', 50, 1340, 980, 40, '#ffcdd2', { weight: 400 }), + ]), + mk('naicha', '新品奶茶', 'food', grad(135, '#fce4ec', '#f8bbd0'), [ + tx('新品上市', 50, 270, 980, 150, '#ad1457', { weight: 900 }), + tx('招牌奶茶 第二杯半价', 50, 470, 980, 64, '#880e4f'), + im(160, 640, 760, 560, '粉色系珍珠奶茶饮品摄影,清新甜品海报', { radius: 28 }), + sh('ellipse', 390, 1250, 300, 160, '#ad1457'), + tx('尝鲜去', 390, 1292, 300, 46, '#ffffff', { weight: 900 }), + ]), + mk('shaokao', '深夜烧烤', 'food', solid('#171717'), [ + tx('深夜烧烤', 50, 250, 980, 150, '#ff9100', { weight: 900 }), + tx('串串香 · 啤酒畅饮', 50, 450, 980, 58, '#ffffff'), + im(100, 600, 880, 540, '炭火烧烤羊肉串特写,火光油亮,夜市美食摄影', { radius: 20 }), + tx('营业至凌晨2点 · 到店送烤串5串', 50, 1220, 980, 46, '#ffab40', { weight: 700 }), + tx('XX路夜市3号摊', 50, 1330, 980, 38, '#9e9e9e', { weight: 400 }), + ]), + + // ---------------- 教育 ---------------- + mk('shuxi', '暑期班招生', 'edu', grad(135, '#00695c', '#26a69a'), [ + tx('暑期班招生', 50, 280, 980, 150, '#ffffff', { weight: 900 }), + tx('名额有限 · 报名立减500', 50, 480, 980, 60, '#b2dfdb'), + im(130, 640, 820, 470, '学生在明亮教室上课,教育培训宣传照', { radius: 24 }), + sh('rect', 290, 1200, 500, 100, '#ffd60a', { radius: 50 }), + tx('免费试听一节课', 290, 1222, 500, 44, '#00695c'), + tx('咨询电话:400-000-0000', 50, 1345, 980, 40, '#b2dfdb', { weight: 400 }), + ]), + mk('kaixue', '开学季特惠', 'edu', solid('#1565c0'), [ + tx('开学季', 50, 260, 980, 170, '#ffd60a', { weight: 900 }), + tx('学费立减500元', 50, 470, 980, 76, '#ffffff', { weight: 900 }), + tx('再送开学大礼包', 50, 610, 980, 50, '#bbdefb'), + im(150, 740, 780, 430, '书本文具开学用品摆拍,蓝色清爽背景', { radius: 24 }), + sh('rect', 340, 1260, 400, 96, '#ffd60a', { radius: 48 }), + tx('马上报名', 340, 1280, 400, 44, '#1565c0'), + ]), + mk('chongci', '考试冲刺营', 'edu', solid('#283593'), [ + tx('考试冲刺营', 50, 250, 980, 140, '#ffd54f', { weight: 900 }), + tx('30天高效提分计划', 50, 450, 980, 64, '#ffffff'), + im(120, 610, 840, 470, '学生夜晚书桌台灯下复习,学习氛围照片', { radius: 24 }), + tx('一对一辅导 · 名师划重点', 50, 1160, 980, 50, '#c5cae9'), + sh('rect', 300, 1270, 480, 96, '#ffd54f', { radius: 48 }), + tx('预约免费测评', 300, 1290, 480, 44, '#283593'), + ]), + + // ---------------- 健身 ---------------- + mk('jianshen', '健身年卡', 'sport', solid('#1b1b1b'), [ + tx('年卡特惠', 50, 250, 980, 160, '#c6ff00', { weight: 900 }), + tx('¥1999/年 限时开抢', 50, 460, 980, 72, '#ffffff', { weight: 900 }), + im(100, 620, 880, 500, '健身房力量训练场景,深色调硬核健身摄影', { radius: 24 }), + tx('私教体验课×3 免费送', 50, 1210, 980, 50, '#c6ff00', { weight: 700 }), + tx('24小时营业 · 全城连锁', 50, 1330, 980, 38, '#9e9e9e', { weight: 400 }), + ]), + mk('yujia', '瑜伽体验课', 'sport', grad(160, '#80cbc4', '#e0f2f1'), [ + tx('瑜伽体验课', 50, 280, 980, 140, '#00695c', { weight: 900 }), + tx('新客免费 · 零基础友好', 50, 470, 980, 58, '#004d40'), + im(140, 640, 800, 520, '瑜伽垫上的女性拉伸,明亮工作室清新氛围', { radius: 28 }), + tx('每周六上午 10:00', 50, 1240, 980, 48, '#00695c', { weight: 700 }), + tx('扫码预约 限前50名', 50, 1335, 980, 42, '#00897b', { weight: 400 }), + ]), + + // ---------------- 招聘 ---------------- + mk('gaoxin', '高薪招聘', 'recruit', solid('#0d1b2a'), [ + sh('rect', 0, 0, 1080, 12, '#00e5ff'), + tx('高薪招聘\n期待你加入', 80, 170, 920, 110, '#ffffff', { align: 'left', weight: 900, lineHeight: 1.35 }), + tx('前端工程师 / 产品经理 / 运营', 80, 510, 920, 48, '#4dd0e1', { align: 'left', weight: 700 }), + tx('13薪 · 五险一金 · 弹性工作 · 年度体检', 80, 630, 920, 44, '#90a4ae', { align: 'left', weight: 400 }), + im(80, 770, 920, 430, '现代互联网公司开放办公区,团队协作照片', { radius: 16 }), + sh('rect', 80, 1300, 460, 92, '#00e5ff', { radius: 46 }), + tx('投递简历', 80, 1319, 460, 40, '#0d1b2a'), + ]), + mk('mendi', '门店招聘', 'recruit', solid('#ffd60a'), [ + tx('门店招聘', 50, 270, 980, 160, '#111111', { weight: 900 }), + tx('店员 / 收银 / 导购', 50, 480, 980, 64, '#b71c1c', { weight: 900 }), + tx('月薪4500-8000 · 包吃住', 50, 610, 980, 52, '#111111'), + im(140, 740, 800, 420, '明亮便利店门店员工微笑服务照片', { radius: 24 }), + sh('rect', 300, 1250, 480, 100, '#b71c1c', { radius: 50 }), + tx('电话:138-0000-0000', 300, 1274, 480, 44, '#ffffff', { weight: 900 }), + ]), + + // ---------------- 生日 ---------------- + mk('shengri', '生日快乐', 'birthday', grad(135, '#f8bbd0', '#f48fb1'), [ + tx('生日快乐', 50, 260, 980, 170, '#ad1457', { weight: 900 }), + tx('愿你所求皆如愿', 50, 465, 980, 56, '#880e4f'), + im(170, 630, 740, 560, '粉色生日蛋糕蜡烛气球,生日派对摄影', { radius: 32 }), + sh('ellipse', 380, 1250, 320, 160, '#ad1457'), + tx('许愿时刻', 380, 1292, 320, 46, '#ffffff', { weight: 900 }), + ]), + mk('zhousui', '宝宝周岁', 'birthday', grad(135, '#fff9c4', '#ffe0b2'), [ + tx('周岁快乐', 50, 250, 980, 150, '#ef6c00', { weight: 900 }), + tx('宝宝成长纪念', 50, 450, 980, 56, '#e65100'), + im(160, 620, 760, 560, '抓周物品与宝宝生日布置,暖黄色温馨照片', { radius: 32 }), + tx('健康快乐 平安长大', 50, 1280, 980, 48, '#bf360c', { weight: 700 }), + ]), + + // ---------------- 封面/宣传 ---------------- + mk('ganhuo', '干货分享封面', 'redbook', solid('#f7f7f7'), [ + sh('rect', 70, 90, 340, 92, '#ff2442', { radius: 46 }), + tx('干货分享', 70, 111, 340, 42, '#ffffff', { weight: 900 }), + tx('5个让效率翻倍\n的办公神器', 70, 240, 940, 96, '#111111', { align: 'left', weight: 900, lineHeight: 1.4 }), + tx('收藏 = 用到', 70, 530, 940, 40, '#888888', { align: 'left', weight: 400 }), + im(70, 640, 940, 640, '干净留白的桌面办公好物平铺摄影,小红书封面风格', { radius: 24 }), + tx('关注我 持续分享实用工具', 70, 1350, 940, 36, '#999999', { align: 'left', weight: 400 }), + ]), + mk('qiye', '企业宣传', 'redbook', grad(135, '#004d40', '#00897b'), [ + tx('企业宣传', 50, 300, 980, 150, '#ffffff', { weight: 900 }), + tx('专业 · 高效 · 值得信赖', 50, 500, 980, 56, '#b2dfdb'), + im(110, 660, 860, 520, '现代企业办公大楼玻璃幕墙蓝天,商务摄影', { radius: 20 }), + tx('成立10年 · 服务客户10000+', 50, 1250, 980, 46, '#80cbc4', { weight: 700 }), + sh('rect', 340, 1345, 400, 76, 'rgba(255,255,255,0.92)', { radius: 38 }), + tx('了解更多', 340, 1363, 400, 36, '#004d40', { weight: 700 }), + ]), +]; + +// 背景快捷预设(画布"背景"区一键切换) +export const BG_PRESETS: { name: string; bg: PosterBg }[] = [ + { name: '中国红', bg: grad(135, '#c62828', '#ff8f00') }, + { name: '活力橙', bg: grad(135, '#ff6d00', '#ffb300') }, + { name: '科技蓝', bg: grad(120, '#0052ff', '#00c6ff') }, + { name: '魅紫', bg: grad(135, '#6a1b9a', '#e91e63') }, + { name: '森绿', bg: grad(135, '#00695c', '#26a69a') }, + { name: '樱花粉', bg: grad(135, '#f8bbd0', '#f48fb1') }, + { name: '暗夜黑', bg: solid('#171717') }, + { name: '奶油白', bg: solid('#f7f7f7') }, +];