37 lines
1.2 KiB
JavaScript
37 lines
1.2 KiB
JavaScript
import fs from 'fs';
|
|
import path from 'path';
|
|
import { fileURLToPath } from 'url';
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
const { Resvg } = await import('@resvg/resvg-js');
|
|
|
|
const svgDir = path.join(__dirname, 'svg');
|
|
const sizes = [24, 48, 96];
|
|
|
|
const files = fs.readdirSync(svgDir).filter((f) => f.endsWith('.svg'));
|
|
|
|
for (const file of files) {
|
|
const base = file.replace('.svg', '');
|
|
const svg = fs.readFileSync(path.join(svgDir, file), 'utf8');
|
|
|
|
for (const size of sizes) {
|
|
const outDir = path.join(__dirname, 'png', `${size}px`);
|
|
fs.mkdirSync(outDir, { recursive: true });
|
|
|
|
const grayPng = new Resvg(svg, {
|
|
fitTo: { mode: 'width', value: size },
|
|
}).render().asPng();
|
|
fs.writeFileSync(path.join(outDir, `${base}.png`), grayPng);
|
|
|
|
const whiteSvg = svg.replace(/#666666/gi, '#FFFFFF');
|
|
const whitePng = new Resvg(whiteSvg, {
|
|
fitTo: { mode: 'width', value: size },
|
|
}).render().asPng();
|
|
const whiteDir = path.join(__dirname, 'png-white', `${size}px`);
|
|
fs.mkdirSync(whiteDir, { recursive: true });
|
|
fs.writeFileSync(path.join(whiteDir, `${base}.png`), whitePng);
|
|
}
|
|
}
|
|
|
|
console.log('PNG export done:', files.length, 'icons x', sizes.length, 'sizes x 2 colors');
|