| 123456789101112131415161718192021222324 |
- const sharp = require('sharp');
- const fs = require('fs');
- const path = require('path');
- async function convertDir(dir, size) {
- const fullDir = path.join(__dirname, dir);
- if (!fs.existsSync(fullDir)) return;
- const files = fs.readdirSync(fullDir).filter(f => f.endsWith('.svg'));
- for (let file of files) {
- const fullPath = path.join(fullDir, file);
- const outPath = path.join(fullDir, file.replace('.svg', '.png'));
- await sharp(fullPath)
- .resize(size, size)
- .png()
- .toFile(outPath);
- console.log(`Converted ${file} to png`);
- }
- }
- async function main() {
- await convertDir('static/tabbar', 81);
- await convertDir('static/my', 96);
- }
- main().catch(console.error);
|