#!/usr/bin/env node /** * Audit image evidence: does each file actually contain a picture? * * node tools/web/inspect-image.mjs [...] [--json] [--allow-blank] * * node tools/web/inspect-image.mjs web/app/public/tutorial/render-basics/evidence * node tools/web/inspect-image.mjs /tmp/frames --json * * Prints width/height, alpha coverage, brightest channel and a verdict for each * PNG; JPEGs report dimensions only. Exits 2 when a blank frame is found, which * makes it usable as a gate in a capture pipeline. * * Why this exists: a render can report SUCCEEDED, write ~220 KB, and still be an * all-transparent frame. File size proves nothing; the pixels do. */ import {collectImages, imageStats} from "./lib/image-stats.mjs"; const argv = process.argv.slice(2); const json = argv.includes("--json"); const allowBlank = argv.includes("--allow-blank"); const inputs = argv.filter((item) => !item.startsWith("--")); if (!inputs.length) { console.error("usage: node tools/web/inspect-image.mjs [...] [--json] [--allow-blank]"); process.exit(1); } const results = collectImages(inputs).map((file) => { try { return imageStats(file); } catch (error) { return {path: file, verdict: "error", error: String(error?.message ?? error)}; } }); if (json) { console.log(JSON.stringify(results, null, 2)); } else { const rows = results.map((stats) => ({ file: stats.path.replace(`${process.cwd()}/`, ""), size: stats.width ? `${stats.width}×${stats.height}` : "—", bytes: stats.bytes ? `${Math.round(stats.bytes / 1024)} KiB` : "—", alpha: stats.maxAlpha === null || stats.maxAlpha === undefined ? "—" : String(stats.maxAlpha), opaque: stats.opaqueRatio === null || stats.opaqueRatio === undefined ? "—" : `${(stats.opaqueRatio * 100).toFixed(1)}%`, rgb: stats.maxRgb === null || stats.maxRgb === undefined ? "—" : String(stats.maxRgb), verdict: stats.verdict, })); const width = (key) => Math.max(4, ...rows.map((row) => String(row[key]).length)); const widths = {file: width("file"), size: width("size"), bytes: width("bytes"), alpha: width("alpha"), opaque: width("opaque"), rgb: width("rgb"), verdict: width("verdict")}; const line = (row, keys) => keys.map((key) => String(row[key]).padEnd(widths[key])).join(" "); const keys = ["file", "size", "bytes", "alpha", "opaque", "rgb", "verdict"]; console.log(line({file: "file", size: "size", bytes: "bytes", alpha: "alpha", opaque: "opaque", rgb: "maxRGB", verdict: "verdict"}, keys)); console.log(keys.map((key) => "-".repeat(widths[key])).join(" ")); for (const row of rows) console.log(line(row, keys)); } const blank = results.filter((stats) => stats.verdict === "transparent" || stats.verdict === "noise-only" || stats.verdict === "error"); if (blank.length) { console.error(`\n${blank.length} image(s) contain no picture: ${blank.map((stats) => stats.path).join(", ")}`); if (!allowBlank) process.exit(2); } else console.error(`\n${results.length} image(s) checked, all contain a picture.`);