convert.js 752 B

123456789101112131415161718192021222324
  1. const sharp = require('sharp');
  2. const fs = require('fs');
  3. const path = require('path');
  4. async function convertDir(dir, size) {
  5. const fullDir = path.join(__dirname, dir);
  6. if (!fs.existsSync(fullDir)) return;
  7. const files = fs.readdirSync(fullDir).filter(f => f.endsWith('.svg'));
  8. for (let file of files) {
  9. const fullPath = path.join(fullDir, file);
  10. const outPath = path.join(fullDir, file.replace('.svg', '.png'));
  11. await sharp(fullPath)
  12. .resize(size, size)
  13. .png()
  14. .toFile(outPath);
  15. console.log(`Converted ${file} to png`);
  16. }
  17. }
  18. async function main() {
  19. await convertDir('static/tabbar', 81);
  20. await convertDir('static/my', 96);
  21. }
  22. main().catch(console.error);