Files
membank/.codebuddy/skills/image-tools/scripts/render-main-image.js
12600k-rog-d4 5981a34e9c 优化亚克力机箱-单产品SKU配置和主图设计
- 删除N2840的2G-32G、4G-64G、4G-128G配置
- 删除AMD-A4的4G-128G配置
- 更新产品价格汇总表(32款→28款)
- 完善主图和详情页设计
- 添加来电自启功能说明
- 清理冗余图片文件
2026-04-08 01:06:45 +08:00

58 lines
1.8 KiB
JavaScript

const puppeteer = require('puppeteer');
const path = require('path');
const fs = require('fs');
async function convertMainImageToPng() {
console.log('🎨 启动主图渲染工具...\n');
const browser = await puppeteer.launch({
headless: 'new',
args: ['--no-sandbox', '--disable-setuid-sandbox']
});
const page = await browser.newPage();
await page.setViewport({ width: 1000, height: 1000 });
const mainImageDir = 'G:\\stonelan-workspace\\membank\\产品\\飞牛 NAS\\fyd-亚克力机箱 - 单\\主图';
const htmlFiles = fs.readdirSync(mainImageDir)
.filter(file => file.endsWith('.html'));
console.log(`📁 找到 ${htmlFiles.length} 个主图HTML文件需要渲染\n`);
for (const htmlFile of htmlFiles) {
try {
const htmlPath = path.join(mainImageDir, htmlFile);
const pngFile = htmlFile.replace('.html', '.png');
const pngPath = path.join(mainImageDir, pngFile);
console.log(`📄 正在渲染: ${htmlFile}`);
const fileUrl = `file:///${htmlPath.replace(/\\/g, '/')}`;
await page.goto(fileUrl, {
waitUntil: 'networkidle0',
timeout: 10000
});
await page.screenshot({
path: pngPath,
fullPage: true,
type: 'png'
});
console.log(`✅ 已生成: ${pngFile}\n`);
} catch (error) {
console.error(`❌ 渲染失败 ${htmlFile}: ${error.message}\n`);
}
}
await browser.close();
console.log('✨ 所有主图渲染完成!');
}
convertMainImageToPng().catch(error => {
console.error('💥 渲染过程出错:', error);
process.exit(1);
});