12 lines
1.4 KiB
JavaScript
12 lines
1.4 KiB
JavaScript
// Deterministic delivery derivatives from the original, retained imagegen masters.
|
|
const sharp=require('../../PlotLine.Tests/Browser/node_modules/sharp'),fs=require('node:fs'),path=require('node:path');
|
|
(async()=>{const inventory=[];for(const scene of ['home','tour','pricing']){const source=`Docs/PublicVisualIdentity/Masters/${scene}-desk-v1.png`,meta=await sharp(source).metadata();
|
|
for(const mode of ['wide','mobile'])for(const width of mode==='wide'?[768,1152,1536]:[480,704])for(const format of ['avif','webp']){
|
|
const height=mode==='wide'?Math.round(width*.54):Math.round(width*4/3);let pipeline=sharp(source);
|
|
if(mode==='mobile'){const cropWidth=Math.floor(meta.height*.75);pipeline=pipeline.extract({left:0,top:0,width:cropWidth,height:meta.height});}
|
|
pipeline=pipeline.resize(width,height,{fit:'cover',position:mode==='wide'?'centre':'northwest'});
|
|
const name=`${scene}-${mode}-${width}.${format}`,destination=path.join('PlotLine/wwwroot/images/public/scenes',name);
|
|
await pipeline[format](format==='avif'?{quality:84,effort:5,chromaSubsampling:'4:4:4'}:{quality:90,effort:5}).toFile(destination);
|
|
inventory.push({scene,mode,width,height,format,bytes:fs.statSync(destination).size,url:'/images/public/scenes/'+name});}
|
|
}fs.writeFileSync('Docs/PublicVisualIdentity/AssetManifest.json',JSON.stringify(inventory,null,2)+'\n');console.log('Generated',inventory.length,'derivatives');})().catch(e=>{console.error(e);process.exit(1)});
|