Initial MANGABOM website
This commit is contained in:
9
scripts/calculate-image-spec.cjs
Normal file
9
scripts/calculate-image-spec.cjs
Normal file
@@ -0,0 +1,9 @@
|
||||
const fs=require('node:fs'),path=require('node:path');const root=path.resolve(__dirname,'..');
|
||||
const measurements=JSON.parse(fs.readFileSync(path.join(root,'docs/image-spec/slot-measurements.json'),'utf8'));
|
||||
const W=2400,H=1600;
|
||||
function crop(slot,z=1.045){const fit=Math.max(slot.width/W,slot.height/H);const [px,py]=slot.objectPosition.split(' ').map(v=>parseFloat(v)/100);const dx=(slot.width-W*fit)*px,dy=(slot.height-H*fit)*py;return {left:(slot.width/2*(1-1/z)-dx)/fit/W*100,right:(slot.width/2*(1+1/z)-dx)/fit/W*100,top:(slot.height/2*(1-1/z)-dy)/fit/H*100,bottom:(slot.height/2*(1+1/z)-dy)/fit/H*100};}
|
||||
const slots=measurements.flatMap(m=>m.slots.filter(s=>s.type!=='home').map(s=>({case:m.case,...s,crop:crop(s)})));
|
||||
const intersection={left:Math.max(...slots.map(s=>s.crop.left)),right:Math.min(...slots.map(s=>s.crop.right)),top:Math.max(...slots.map(s=>s.crop.top)),bottom:Math.min(...slots.map(s=>s.crop.bottom))};
|
||||
const output={master:{width:W,height:H},intersection,crops:slots};
|
||||
fs.mkdirSync(path.join(root,'docs/image-spec'),{recursive:true});fs.writeFileSync(path.join(root,'docs/image-spec/crop-measurements.json'),JSON.stringify(output,null,2));
|
||||
console.log(JSON.stringify({intersection,crops:slots.map(s=>({case:s.case,type:s.type,width:s.width,height:s.height,crop:s.crop}))},null,2));
|
||||
Reference in New Issue
Block a user