/** * 生成 81×81 TabBar PNG 图标(透明底,适合微信小程序) * 用法:node scripts/gen-tabbar-icons.mjs */ import fs from 'node:fs' import path from 'node:path' import { fileURLToPath } from 'node:url' import sharp from 'sharp' const __dirname = path.dirname(fileURLToPath(import.meta.url)) const outDir = path.resolve(__dirname, '../src/static/tabbar') const GRAY = '#8C7B6A' const ORANGE = '#FF6B35' function svgIcon(type, color) { if (type === 'home') { return ` ` } if (type === 'scan') { return ` ` } if (type === 'coupon') { return ` ` } return ` ` } async function writeIcon(name, type, color) { const svg = svgIcon(type, color) const buf = await sharp(Buffer.from(svg)).png().toBuffer() fs.writeFileSync(path.join(outDir, name), buf) } async function main() { fs.mkdirSync(outDir, { recursive: true }) const items = [ ['home.png', 'home', GRAY], ['home-active.png', 'home', ORANGE], ['scan.png', 'scan', GRAY], ['scan-active.png', 'scan', ORANGE], ['coupon.png', 'coupon', GRAY], ['coupon-active.png', 'coupon', ORANGE], ['profile.png', 'profile', GRAY], ['profile-active.png', 'profile', ORANGE] ] for (const [file, type, color] of items) { await writeIcon(file, type, color) console.log('wrote', file) } } main().catch(err => { console.error(err) process.exit(1) })