dapaijizhang3/create-icons.js

86 lines
3.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const fs = require('fs');
const path = require('path');
// 创建SVG图标的函数
function createSVGIcon(type, color) {
let svgContent = '';
switch(type) {
case 'home':
svgContent = `<?xml version="1.0" encoding="UTF-8"?>
<svg width="81" height="81" viewBox="0 0 81 81" xmlns="http://www.w3.org/2000/svg">
<path d="M40.5 15 L20 35 L25 35 L25 65 L35 65 L35 50 L46 50 L46 65 L56 65 L56 35 L61 35 Z"
fill="${color}" />
</svg>`;
break;
case 'stats':
svgContent = `<?xml version="1.0" encoding="UTF-8"?>
<svg width="81" height="81" viewBox="0 0 81 81" xmlns="http://www.w3.org/2000/svg">
<rect x="15" y="45" width="15" height="20" fill="${color}"/>
<rect x="33" y="35" width="15" height="30" fill="${color}"/>
<rect x="51" y="25" width="15" height="40" fill="${color}"/>
</svg>`;
break;
case 'profile':
svgContent = `<?xml version="1.0" encoding="UTF-8"?>
<svg width="81" height="81" viewBox="0 0 81 81" xmlns="http://www.w3.org/2000/svg">
<circle cx="40.5" cy="25" r="12" fill="${color}"/>
<ellipse cx="40.5" cy="55" rx="20" ry="15" fill="${color}"/>
</svg>`;
break;
}
return svgContent;
}
// 创建简单的PNG占位文件使用最小的PNG数据
function createMinimalPNG() {
// 最小的1x1 PNG图片的Base64数据
const base64 = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==';
return Buffer.from(base64, 'base64');
}
// 图标配置
const icons = [
{ name: 'home.png', type: 'home', color: '#999999' },
{ name: 'home-active.png', type: 'home', color: '#07c160' },
{ name: 'stats.png', type: 'stats', color: '#999999' },
{ name: 'stats-active.png', type: 'stats', color: '#07c160' },
{ name: 'profile.png', type: 'profile', color: '#999999' },
{ name: 'profile-active.png', type: 'profile', color: '#07c160' },
{ name: 'default-avatar.png', type: 'profile', color: '#cccccc' },
{ name: 'empty.png', type: 'home', color: '#dddddd' }
];
// 创建images目录如果不存在
const imagesDir = path.join(__dirname, 'images');
if (!fs.existsSync(imagesDir)) {
fs.mkdirSync(imagesDir, { recursive: true });
}
// 创建所有图标文件PNG占位符
icons.forEach(icon => {
const filePath = path.join(imagesDir, icon.name);
const pngData = createMinimalPNG();
fs.writeFileSync(filePath, pngData);
console.log(`创建图标: ${icon.name}`);
});
// 同时创建SVG版本供参考
icons.forEach(icon => {
const svgFilePath = path.join(imagesDir, icon.name.replace('.png', '.svg'));
const svgContent = createSVGIcon(icon.type, icon.color);
if (svgContent) {
fs.writeFileSync(svgFilePath, svgContent);
console.log(`创建SVG: ${icon.name.replace('.png', '.svg')}`);
}
});
console.log('\n图标创建完成');
console.log('提示:');
console.log('1. PNG文件是占位符可以在微信开发者工具中正常运行');
console.log('2. SVG文件显示了实际图标样式');
console.log('3. 您可以使用在线工具将SVG转换为PNG');
console.log('4. 或者打开generate-icons.html在浏览器中生成真实PNG图标');