feat: AI炫图接入gpt-image-2.5云端生图(结构化提示词工程+照片参考合成)

This commit is contained in:
HHY
2026-09-25 04:15:45 -07:00
parent 710b3521a2
commit 6726a9fa3a
12 changed files with 496 additions and 48 deletions
+72
View File
@@ -0,0 +1,72 @@
// 云端 AI 炫图(gpt-image)端到端验证: 注入测试照片 → 拖框 → AI 照片合成 → 截图
// 用法: node verify-aicloud.mjs <token>
import puppeteer from 'puppeteer-core'
const browser = await puppeteer.launch({
executablePath: 'C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe',
headless: 'new',
args: ['--window-size=1440,900', '--enable-unsafe-swiftshader'],
defaultViewport: { width: 1440, height: 900 },
})
const page = await browser.newPage()
page.on('pageerror', e => console.log(`[JS异常] ${String(e).slice(0, 200)}`))
const token = process.argv[2]
await page.goto(`http://localhost:8000/ai_render?token=${encodeURIComponent(token)}`, { waitUntil: 'networkidle2' })
await new Promise(r => setTimeout(r, 2000))
// 1) 选第一个样板
await page.click('.controls .el-select')
await new Promise(r => setTimeout(r, 800))
await (await page.$('.el-select-dropdown__item')).click()
await new Promise(r => setTimeout(r, 1000))
// 2) 注入程序化"旧客厅"照片(带深色旧窗洞)
await page.evaluate(() => {
const cv = document.createElement('canvas')
cv.width = 1200; cv.height = 800
const ctx = cv.getContext('2d')
const g = ctx.createLinearGradient(0, 0, 0, 800)
g.addColorStop(0, '#e8e0d2'); g.addColorStop(0.7, '#d8cdbb'); g.addColorStop(1, '#9c8b74')
ctx.fillStyle = g; ctx.fillRect(0, 0, 1200, 800)
ctx.fillStyle = 'rgba(120,100,80,0.25)'
ctx.fillRect(380, 260, 440, 340)
ctx.strokeStyle = 'rgba(90,70,50,0.5)'; ctx.lineWidth = 8
ctx.strokeRect(380, 260, 440, 340)
return new Promise(resolve => {
cv.toBlob(blob => {
const dt = new DataTransfer()
dt.items.add(new File([blob], 'room.png', { type: 'image/png' }))
const input = document.querySelector('.el-upload input[type=file]')
input.files = dt.files
input.dispatchEvent(new Event('change'))
resolve()
}, 'image/png')
})
})
await new Promise(r => setTimeout(r, 1200))
// 3) 框选窗洞
const stage = await page.$('.photo-cv')
const b = await stage.boundingBox()
await page.mouse.move(b.x + b.width * 0.3, b.y + b.height * 0.3)
await page.mouse.down()
await page.mouse.move(b.x + b.width * 0.7, b.y + b.height * 0.75, { steps: 8 })
await page.mouse.up()
await new Promise(r => setTimeout(r, 300))
// 4) 切到"室外渲染"场景更像安装效果: 保持默认渲图, 点击 AI 照片合成
const genBtn = await page.evaluateHandle(() => [...document.querySelectorAll('button')].find(x => x.textContent.includes('AI 照片合成')))
await genBtn.asElement().click()
console.log('已提交云端生成, 等待 AI 绘制(最长 150s)...')
// 轮询等 ai-img 出现
let ok = false
for (let i = 0; i < 75; i++) {
await new Promise(r => setTimeout(r, 2000))
ok = await page.evaluate(() => !!document.querySelector('.ai-img'))
if (ok) break
if (i % 5 === 4) console.log(` 等待中 ${(i + 1) * 2}s`)
}
if (!ok) { console.log('✗ 超时未返回'); await browser.close(); process.exit(1) }
const img = await page.$('.ai-result')
await img.screenshot({ path: 'D:/Code/huamenchuang/shots/verify-aicloud.png' })
console.log('✓ 云端 AI 照片合成验证完成')
await browser.close()