Files
ewoooc/scripts/archive/convert_assets.py
ogt 1b4f3a7bbe
Some checks failed
CD Pipeline / deploy (push) Failing after 59s
feat: EwoooC 初始化 — 完整專案推版至 Gitea
- 建立 Gitea Actions CD pipeline (.gitea/workflows/cd.yaml)
- 部署模式: rsync Python 檔案至 188 → docker restart (volume mount)
- Dockerfile/requirements 變動時自動重建 Docker image
- 部署通知: Telegram (開始/成功/失敗)
- 健康檢查: https://mo.wooo.work/health (最多 5 次重試)
- 同步最新 CLAUDE.md / ADR-008 / memory (2026-04-19)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-19 01:21:13 +08:00

52 lines
2.3 KiB
Python

import os
import subprocess
import base64
ASSETS = [
("/Users/ogt/momo_pro_system/web/static/images/logo.png", "WOOO_Main_Logo"),
("/Users/ogt/momo_pro_system/web/static/images/logo_v4_glass.png", "WOOO_Glass_Logo"),
("/Users/ogt/momo_pro_system/web/static/images/logo_v4_gradient.png", "WOOO_Gradient_Logo"),
]
OUTPUT_DIR = "/Users/ogt/momo_pro_system/export_assets"
os.makedirs(OUTPUT_DIR, exist_ok=True)
for input_path, base_name in ASSETS:
print(f"Processing {base_name}...")
try:
# TIFF (Keep transparency)
subprocess.run(["convert", input_path, "-background", "none", os.path.join(OUTPUT_DIR, f"{base_name}.tiff")], check=True)
# JPG (White background, flattened)
subprocess.run(["convert", input_path, "-background", "white", "-flatten", os.path.join(OUTPUT_DIR, f"{base_name}.jpg")], check=True)
# EPS (Raster embedded)
subprocess.run(["convert", input_path, "-background", "none", os.path.join(OUTPUT_DIR, f"{base_name}.eps")], check=True)
# AI (PDF renamed to AI for compatibility)
pdf_path = os.path.join(OUTPUT_DIR, f"{base_name}.pdf")
ai_path = os.path.join(OUTPUT_DIR, f"{base_name}.ai")
subprocess.run(["convert", input_path, "-background", "none", pdf_path], check=True)
subprocess.run(["cp", pdf_path, ai_path], check=True)
# SVG (Embed base64)
with open(input_path, "rb") as img_file:
b64_data = base64.b64encode(img_file.read()).decode("utf-8")
# Get dimensions using identify
dim_res = subprocess.check_output(["identify", "-format", "%w %h", input_path]).decode().strip().split()
if len(dim_res) >= 2:
w, h = dim_res[0], dim_res[1]
svg_content = f'''<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg width="{w}" height="{h}" viewBox="0 0 {w} {h}" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<image width="{w}" height="{h}" xlink:href="data:image/png;base64,{b64_data}"/>
</svg>'''
with open(os.path.join(OUTPUT_DIR, f"{base_name}.svg"), "w") as svg_file:
svg_file.write(svg_content)
print(f"Successfully converted {base_name}")
except Exception as e:
print(f"Error processing {base_name}: {e}")
print("All conversions completed.")