Spaces:
Running
Running
Surf commited on
Commit ·
2b6b660
1
Parent(s): 7dccd7a
接入:真人生成图应用到三种封面尺寸(推送 #30)
Browse files- README.md +2 -2
- assets/index-ip-0913f5b5af.js +0 -0
- index.html +1 -1
- pipeline/check-covers.mjs +2 -2
- src/film/core/covers.ts +25 -50
README.md
CHANGED
|
@@ -51,8 +51,8 @@ pinned: false
|
|
| 51 |
|
| 52 |
- [x] **#28 计划**:已写入本节,尚未生成和接入图片。
|
| 53 |
- [x] **#29 生成资产**:已生成 `odebiao-ip-generated.png`;以原片真人近景为参考,生成图保留黑色牛仔外套、正面半身、鲜明黄绿黑红几何背景;无中文文字、无水印、无第二人物。接入与尺寸回归在 #30/#31 执行。
|
| 54 |
-
- [
|
| 55 |
-
- [ ] **#31 构建质检**:
|
| 56 |
- [ ] **#32 最终同步**:待完成。
|
| 57 |
|
| 58 |
---
|
|
|
|
| 51 |
|
| 52 |
- [x] **#28 计划**:已写入本节,尚未生成和接入图片。
|
| 53 |
- [x] **#29 生成资产**:已生成 `odebiao-ip-generated.png`;以原片真人近景为参考,生成图保留黑色牛仔外套、正面半身、鲜明黄绿黑红几何背景;无中文文字、无水印、无第二人物。接入与尺寸回归在 #30/#31 执行。
|
| 54 |
+
- [x] **#30 接入封面**:封面引擎改为加载 `media/cover/odebiao-ip-generated.png`,不再从视频取帧;三比例共用同一生成图,Blob URL 缓存、失败提示、圆角裁切与描边已接入。
|
| 55 |
+
- [ ] **#31 构建质检**:387 张封面浏览器回归已完成,待提交新版静态 bundle 与最终远端校验。
|
| 56 |
- [ ] **#32 最终同步**:待完成。
|
| 57 |
|
| 58 |
---
|
assets/index-ip-0913f5b5af.js
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
index.html
CHANGED
|
@@ -12,7 +12,7 @@
|
|
| 12 |
document.documentElement.classList.add('dark');
|
| 13 |
</script>
|
| 14 |
<link rel="stylesheet" crossorigin href="./assets/index-Ce46jEpY.css">
|
| 15 |
-
<script type="module" crossorigin src="./assets/index-ip-
|
| 16 |
</head>
|
| 17 |
<body>
|
| 18 |
<div id="root"><!--ssr-outlet--></div>
|
|
|
|
| 12 |
document.documentElement.classList.add('dark');
|
| 13 |
</script>
|
| 14 |
<link rel="stylesheet" crossorigin href="./assets/index-Ce46jEpY.css">
|
| 15 |
+
<script type="module" crossorigin src="./assets/index-ip-0913f5b5af.js"></script>
|
| 16 |
</head>
|
| 17 |
<body>
|
| 18 |
<div id="root"><!--ssr-outlet--></div>
|
pipeline/check-covers.mjs
CHANGED
|
@@ -30,7 +30,7 @@ page.on('pageerror', e => errors.push(e.message))
|
|
| 30 |
await page.route('**/__cover-test.html', r => r.fulfill({ contentType: 'text/html', body: '<html><body style="margin:0;background:#141414"></body></html>' }))
|
| 31 |
await page.goto(`${origin}/__cover-test.html`)
|
| 32 |
const results = await page.evaluate(async () => {
|
| 33 |
-
const { renderCover, RATIOS, DESIGNS, coverLayout,
|
| 34 |
let count = 0; const violations = [], samples = []
|
| 35 |
for (let id = 1; id <= 43; id++) for (const r of RATIOS) for (const d of DESIGNS) {
|
| 36 |
const c = await renderCover(id, r.key, d.key)
|
|
@@ -40,7 +40,7 @@ const results = await page.evaluate(async () => {
|
|
| 40 |
if (box.x < 0 || box.y < 0 || box.x + box.w > r.w + 0.1 || box.y + box.h > r.h + 0.1) violations.push({ id, ratio: r.key, theme: d.key, box })
|
| 41 |
}
|
| 42 |
if (id === 1) samples.push({ ratio: r.key.replace(':', '-'), theme: d.key, png: c.toDataURL('image/png') })
|
| 43 |
-
if (
|
| 44 |
count++; c.width = c.height = 1
|
| 45 |
}
|
| 46 |
return { count, violations, samples }
|
|
|
|
| 30 |
await page.route('**/__cover-test.html', r => r.fulfill({ contentType: 'text/html', body: '<html><body style="margin:0;background:#141414"></body></html>' }))
|
| 31 |
await page.goto(`${origin}/__cover-test.html`)
|
| 32 |
const results = await page.evaluate(async () => {
|
| 33 |
+
const { renderCover, RATIOS, DESIGNS, coverLayout, PORTRAIT_ASSET } = await import('/src/film/core/covers.ts')
|
| 34 |
let count = 0; const violations = [], samples = []
|
| 35 |
for (let id = 1; id <= 43; id++) for (const r of RATIOS) for (const d of DESIGNS) {
|
| 36 |
const c = await renderCover(id, r.key, d.key)
|
|
|
|
| 40 |
if (box.x < 0 || box.y < 0 || box.x + box.w > r.w + 0.1 || box.y + box.h > r.h + 0.1) violations.push({ id, ratio: r.key, theme: d.key, box })
|
| 41 |
}
|
| 42 |
if (id === 1) samples.push({ ratio: r.key.replace(':', '-'), theme: d.key, png: c.toDataURL('image/png') })
|
| 43 |
+
if (c.dataset.portraitAsset !== PORTRAIT_ASSET) throw new Error('wrong generated asset')
|
| 44 |
count++; c.width = c.height = 1
|
| 45 |
}
|
| 46 |
return { count, violations, samples }
|
src/film/core/covers.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
-
// 真人 IP 封面
|
| 2 |
-
import { FONT, loadFonts } from './assets'
|
| 3 |
import { quoteById } from './film'
|
| 4 |
-
import { footageUrl } from './footage'
|
| 5 |
import { getCopy } from './copy'
|
| 6 |
import { pad2 } from './util'
|
| 7 |
|
|
@@ -18,57 +17,33 @@ export const DESIGNS: { key: Design; name: string; color: string }[] = [
|
|
| 18 |
{ key: 'quoteCard', name: '炭黑金 · 金句人物卡', color: '#171C19' },
|
| 19 |
]
|
| 20 |
const YELLOW = '#FFD21F', PAPER = '#FFF8E7', INK = '#101713', RED = '#D93D2B'
|
| 21 |
-
//
|
| 22 |
-
export const
|
| 23 |
let portraitPromise: Promise<HTMLCanvasElement> | null = null
|
| 24 |
|
| 25 |
function canvas(w: number, h: number) {
|
| 26 |
const c = document.createElement('canvas'); c.width = w; c.height = h; return c
|
| 27 |
}
|
| 28 |
|
| 29 |
-
/** 加载失败必须显式报错,禁止静默降级成风景封面
|
| 30 |
async function makePortrait() {
|
| 31 |
-
const
|
| 32 |
-
|
| 33 |
-
|
|
|
|
| 34 |
try {
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
const clean = () => { clearTimeout(timer); v.removeEventListener('loadeddata', ready); v.removeEventListener('error', fail) }
|
| 41 |
-
const ready = () => { clean(); resolve() }
|
| 42 |
-
const fail = () => { clean(); reject(new Error('原片人物素材加载失败,请检查网络后重试。')) }
|
| 43 |
-
const timer = setTimeout(fail, 30000)
|
| 44 |
-
v.addEventListener('loadeddata', ready, { once: true }); v.addEventListener('error', fail, { once: true })
|
| 45 |
-
v.src = objectUrl; v.load()
|
| 46 |
})
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
if (v.readyState >= 2 && Math.abs(v.currentTime - PORTRAIT_TIME) < 0.05) resolve()
|
| 51 |
-
else reject(new Error('未定位到指定真人近景,请重试。'))
|
| 52 |
-
}
|
| 53 |
-
const timer = setTimeout(() => { v.removeEventListener('seeked', finish); reject(new Error('真人近景取帧超时,请重试。')) }, 10000)
|
| 54 |
-
v.addEventListener('seeked', finish, { once: true }); v.currentTime = PORTRAIT_TIME
|
| 55 |
-
})
|
| 56 |
-
const raw = canvas(1920, 1080), g = raw.getContext('2d')!
|
| 57 |
-
g.drawImage(v, 0, 0, 1920, 1080)
|
| 58 |
-
// 只做曝光恢复,真实皮肤纹理不作生成式“美化”。
|
| 59 |
-
const pixels = g.getImageData(0, 0, 1920, 1080)
|
| 60 |
-
const lut = Array.from({ length: 256 }, (_, n) => Math.round(255 * Math.pow(n / 255, 0.70)))
|
| 61 |
-
for (let i = 0; i < pixels.data.length; i += 4) {
|
| 62 |
-
pixels.data[i] = lut[pixels.data[i]]; pixels.data[i + 1] = lut[pixels.data[i + 1]]; pixels.data[i + 2] = lut[pixels.data[i + 2]]
|
| 63 |
-
}
|
| 64 |
-
g.putImageData(pixels, 0, 0)
|
| 65 |
-
// 手工沿 960×540 参考帧的肩线/外套描摹轮廓,移除公路背景。
|
| 66 |
-
const path = new Path2D('M224 540 L230 480 L235 412 L247 320 L261 251 L264 235 Q278 189 310 175 L342 161 Q330 137 331 105 L329 77 Q325 35 355 0 L453 0 Q478 20 483 57 L484 71 Q494 68 492 91 L495 124 Q512 142 543 150 Q609 171 643 207 L669 244 Q702 299 716 356 Q729 403 725 451 L712 510 L706 540 Z M604 379 L625 426 L602 416 Z')
|
| 67 |
-
const out = canvas(1080, 1080), o = out.getContext('2d')!
|
| 68 |
-
o.scale(2, 2); o.translate(-205, 0); o.clip(path, 'evenodd'); o.drawImage(raw, 0, 0, 960, 540)
|
| 69 |
return out
|
| 70 |
} finally {
|
| 71 |
-
|
| 72 |
}
|
| 73 |
}
|
| 74 |
|
|
@@ -118,13 +93,13 @@ function pill(g: CanvasRenderingContext2D, value: string, x: number, y: number,
|
|
| 118 |
}
|
| 119 |
|
| 120 |
function drawPortrait(g: CanvasRenderingContext2D, source: HTMLCanvasElement, b: CoverBox, color: string, unit: number) {
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
g.
|
| 124 |
-
g.
|
| 125 |
-
// 薄描边使真人深色衣服与底色分离,不在脸上压字。
|
| 126 |
-
for (let i = 0; i < 12; i++) { const a = i / 12 * Math.PI * 2; g.drawImage(silhouette, b.x + Math.cos(a) * unit * 5, b.y + Math.sin(a) * unit * 5, b.w, b.h) }
|
| 127 |
g.drawImage(source, b.x, b.y, b.w, b.h)
|
|
|
|
|
|
|
| 128 |
}
|
| 129 |
|
| 130 |
export async function renderCover(id: number, ratio: Ratio, design: Design): Promise<HTMLCanvasElement> {
|
|
@@ -163,6 +138,6 @@ export async function renderCover(id: number, ratio: Ratio, design: Design): Pro
|
|
| 163 |
g.font = `400 ${s * 0.018}px ${FONT.mono}`; g.textAlign = 'right'; g.fillStyle = fg; g.fillText('ON THE ROAD.', w - m, L.footer.y)
|
| 164 |
// 内部测试读取具体边界;正常下载 PNG 不包含任何测试标记。
|
| 165 |
c.dataset.layout = JSON.stringify([titleBox, hookBox, L.footer])
|
| 166 |
-
c.dataset.
|
| 167 |
return c
|
| 168 |
}
|
|
|
|
| 1 |
+
// 真人 IP 封面:所有尺寸共用同一张生成视觉资产,避免每个比例的人脸不一致。
|
| 2 |
+
import { BASE, FONT, loadFonts } from './assets'
|
| 3 |
import { quoteById } from './film'
|
|
|
|
| 4 |
import { getCopy } from './copy'
|
| 5 |
import { pad2 } from './util'
|
| 6 |
|
|
|
|
| 17 |
{ key: 'quoteCard', name: '炭黑金 · 金句人物卡', color: '#171C19' },
|
| 18 |
]
|
| 19 |
const YELLOW = '#FFD21F', PAPER = '#FFF8E7', INK = '#101713', RED = '#D93D2B'
|
| 20 |
+
// 生成资产以原片真人为参考,中文标题仍由 Canvas 绘制,避免图片模型生成乱码。
|
| 21 |
+
export const PORTRAIT_ASSET = 'media/cover/odebiao-ip-generated.png'
|
| 22 |
let portraitPromise: Promise<HTMLCanvasElement> | null = null
|
| 23 |
|
| 24 |
function canvas(w: number, h: number) {
|
| 25 |
const c = document.createElement('canvas'); c.width = w; c.height = h; return c
|
| 26 |
}
|
| 27 |
|
| 28 |
+
/** 加载失败必须显式报错,禁止静默降级成旧封面或风景封面。 */
|
| 29 |
async function makePortrait() {
|
| 30 |
+
const response = await fetch(`${BASE}${PORTRAIT_ASSET}`, { signal: AbortSignal.timeout(30000) })
|
| 31 |
+
if (!response.ok) throw new Error('真人 IP 生成图加载失败,请刷新后重试。')
|
| 32 |
+
const blob = await response.blob()
|
| 33 |
+
const objectUrl = URL.createObjectURL(blob)
|
| 34 |
try {
|
| 35 |
+
const image = await new Promise<HTMLImageElement>((resolve, reject) => {
|
| 36 |
+
const el = new Image()
|
| 37 |
+
el.onload = () => resolve(el)
|
| 38 |
+
el.onerror = () => reject(new Error('真人 IP 生成图解码失败,请重试。'))
|
| 39 |
+
el.src = objectUrl
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
})
|
| 41 |
+
if (!image.naturalWidth || !image.naturalHeight) throw new Error('真人 IP 生成图尺寸无效。')
|
| 42 |
+
const out = canvas(image.naturalWidth, image.naturalHeight)
|
| 43 |
+
out.getContext('2d')!.drawImage(image, 0, 0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
return out
|
| 45 |
} finally {
|
| 46 |
+
URL.revokeObjectURL(objectUrl)
|
| 47 |
}
|
| 48 |
}
|
| 49 |
|
|
|
|
| 93 |
}
|
| 94 |
|
| 95 |
function drawPortrait(g: CanvasRenderingContext2D, source: HTMLCanvasElement, b: CoverBox, color: string, unit: number) {
|
| 96 |
+
// 生成图本身已经包含个人 IP 的鲜明背景;这里统一做圆角裁切、投影和描边。
|
| 97 |
+
g.save()
|
| 98 |
+
g.shadowColor = '#00170e66'; g.shadowBlur = unit * 24; g.shadowOffsetX = unit * 7; g.shadowOffsetY = unit * 10
|
| 99 |
+
g.beginPath(); g.roundRect(b.x, b.y, b.w, b.h, unit * 12); g.clip()
|
|
|
|
|
|
|
| 100 |
g.drawImage(source, b.x, b.y, b.w, b.h)
|
| 101 |
+
g.restore()
|
| 102 |
+
g.save(); g.strokeStyle = color; g.lineWidth = Math.max(2, unit * 5); g.beginPath(); g.roundRect(b.x, b.y, b.w, b.h, unit * 12); g.stroke(); g.restore()
|
| 103 |
}
|
| 104 |
|
| 105 |
export async function renderCover(id: number, ratio: Ratio, design: Design): Promise<HTMLCanvasElement> {
|
|
|
|
| 138 |
g.font = `400 ${s * 0.018}px ${FONT.mono}`; g.textAlign = 'right'; g.fillStyle = fg; g.fillText('ON THE ROAD.', w - m, L.footer.y)
|
| 139 |
// 内部测试读取具体边界;正常下载 PNG 不包含任何测试标记。
|
| 140 |
c.dataset.layout = JSON.stringify([titleBox, hookBox, L.footer])
|
| 141 |
+
c.dataset.portraitAsset = PORTRAIT_ASSET
|
| 142 |
return c
|
| 143 |
}
|