59 lines
1.4 KiB
JavaScript
59 lines
1.4 KiB
JavaScript
/**
|
||
* 图标转换脚本
|
||
* 将 SVG 图标转换为 PNG 格式
|
||
*
|
||
* 使用方法:
|
||
* 1. npm install sharp
|
||
* 2. node convert-icons.js
|
||
*/
|
||
|
||
const sharp = require('sharp');
|
||
const fs = require('fs');
|
||
const path = require('path');
|
||
|
||
const iconsDir = path.join(__dirname, 'static/icons');
|
||
const outputSize = 81;
|
||
|
||
const svgFiles = [
|
||
'home.svg',
|
||
'home-active.svg',
|
||
'cases.svg',
|
||
'cases-active.svg',
|
||
'service.svg',
|
||
'service-active.svg',
|
||
'user.svg',
|
||
'user-active.svg'
|
||
];
|
||
|
||
async function convertSvgToPng(svgFile) {
|
||
const inputPath = path.join(iconsDir, svgFile);
|
||
const outputPath = path.join(iconsDir, svgFile.replace('.svg', '.png'));
|
||
|
||
try {
|
||
await sharp(inputPath)
|
||
.resize(outputSize, outputSize)
|
||
.png()
|
||
.toFile(outputPath);
|
||
console.log(`✓ 转换成功: ${svgFile} -> ${svgFile.replace('.svg', '.png')}`);
|
||
} catch (error) {
|
||
console.error(`✗ 转换失败: ${svgFile}`, error.message);
|
||
}
|
||
}
|
||
|
||
async function main() {
|
||
console.log('开始转换图标...\n');
|
||
|
||
for (const file of svgFiles) {
|
||
const filePath = path.join(iconsDir, file);
|
||
if (fs.existsSync(filePath)) {
|
||
await convertSvgToPng(file);
|
||
} else {
|
||
console.log(`⚠ 文件不存在: ${file}`);
|
||
}
|
||
}
|
||
|
||
console.log('\n转换完成!');
|
||
}
|
||
|
||
main();
|