import fs from 'node:fs'; import { PNG } from 'pngjs'; for (const name of process.argv.slice(2)) { const png = PNG.sync.read(fs.readFileSync(name)); const { width: w, height: h, data } = png; let sum = 0, bright = 0, n = 0; // 分区域统计 const zones = { center: 0, left: 0, right: 0 }; for (let y = 0; y < h; y++) { for (let x = 0; x < w; x++) { const i = (y * w + x) * 4; const lum = 0.299 * data[i] + 0.587 * data[i + 1] + 0.114 * data[i + 2]; sum += lum; n++; if (lum > 40) bright++; if (lum > 40) { if (x < w / 3) zones.left++; else if (x > (2 * w) / 3) zones.right++; else zones.center++; } } } console.log(`${name}: ${w}x${h} avgLum=${(sum / n).toFixed(1)} brightPct=${((bright / n) * 100).toFixed(1)}% left/center/right=${zones.left}/${zones.center}/${zones.right}`); }