Files
ShaFaFanXin/前端/convert-icons.js
2026-01-27 18:06:04 +08:00

59 lines
1.4 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.

/**
* 图标转换脚本
* 将 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();