@@ -7,6 +7,28 @@ import icongen from "icon-gen";
77const srcDir = path . resolve ( "images" ) ;
88const cacheDir = path . resolve ( ".cache/icons" ) ;
99const outDir = path . resolve ( "icons" ) ;
10+ const icoSizes = [ 16 , 24 , 32 , 48 , 64 , 128 , 256 ] ;
11+
12+ async function generatePngSet ( inputPath , outputDir ) {
13+ fs . mkdirSync ( outputDir , { recursive : true } ) ;
14+
15+ for ( const size of icoSizes ) {
16+ const outputPath = path . join ( outputDir , `${ size } .png` ) ;
17+
18+ if ( fs . existsSync ( outputPath ) ) continue ;
19+
20+ await sharp ( inputPath )
21+ . resize ( size , size , {
22+ fit : "contain" ,
23+ background : { r : 0 , g : 0 , b : 0 , alpha : 0 } ,
24+ } )
25+ . png ( {
26+ compressionLevel : 9 ,
27+ adaptiveFiltering : true ,
28+ } )
29+ . toFile ( outputPath ) ;
30+ }
31+ }
1032
1133function hashFile ( filePath ) {
1234 const data = fs . readFileSync ( filePath ) ;
@@ -15,10 +37,12 @@ function hashFile(filePath) {
1537
1638async function normalizeImage ( inputPath , outputPath ) {
1739 await sharp ( inputPath )
40+ . ensureAlpha ( )
1841 . resize ( 256 , 256 , {
1942 fit : "contain" ,
2043 background : { r : 0 , g : 0 , b : 0 , alpha : 0 } ,
2144 } )
45+ . toColorspace ( "srgb" )
2246 . png ( {
2347 compressionLevel : 9 ,
2448 adaptiveFiltering : true ,
@@ -58,7 +82,9 @@ async function main() {
5882 console . log ( `→ Cache hit ${ file } ` ) ;
5983 }
6084
61- await icongen ( cachedPng , outDir , {
85+ const pngSetDir = path . join ( cacheDir , `${ name } .${ hash } ` ) ;
86+ await generatePngSet ( cachedPng , pngSetDir ) ;
87+ await icongen ( pngSetDir , outDir , {
6288 report : false ,
6389 ico : {
6490 name,
0 commit comments