Lot M1 trait, étape A : le banc de mesure et de captures (horloge figée sous mouvement réduit, toits, ombres, poids, i/s, comparaison au pixel)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
c946484a79
commit
907282c0ea
@@ -0,0 +1,17 @@
|
||||
// node diff.mjs a.png b.png [a2.png b2.png ...] : pixels différents
|
||||
import { createRequire } from 'node:module'; import { readFileSync } from 'node:fs';
|
||||
const require = createRequire(process.env.PW_CORE || '/home/julesneny8/.npm/_npx/9833c18b2d85bc59/node_modules/');
|
||||
const { chromium } = require('playwright-core');
|
||||
const b = await chromium.launch({ executablePath: process.env.CHROMIUM || '/home/julesneny8/.cache/ms-playwright/chromium-1254/chrome-linux64/chrome' });
|
||||
const p = await b.newPage(); const f = process.argv.slice(2);
|
||||
for (let i = 0; i < f.length; i += 2) {
|
||||
const r = await p.evaluate(async ([a, c]) => {
|
||||
const ld = (s) => new Promise((ok) => { const i = new Image(); i.onload = () => ok(i); i.src = 'data:image/png;base64,' + s; });
|
||||
const [A, B] = await Promise.all([ld(a), ld(c)]); if (A.width !== B.width || A.height !== B.height) return 'tailles différentes';
|
||||
const d = (I) => { const k = document.createElement('canvas'); k.width = I.width; k.height = I.height; const x = k.getContext('2d'); x.drawImage(I, 0, 0); return x.getImageData(0, 0, I.width, I.height).data; };
|
||||
const da = d(A), db = d(B); let n = 0, x0 = 1e9, x1 = -1, y0 = 1e9, y1 = -1; for (let j = 0; j < da.length; j += 4) if (da[j] !== db[j] || da[j + 1] !== db[j + 1] || da[j + 2] !== db[j + 2]) { n++; const q = j / 4, X = q % A.width, Y = (q / A.width) | 0; x0 = Math.min(x0, X); x1 = Math.max(x1, X); y0 = Math.min(y0, Y); y1 = Math.max(y1, Y); }
|
||||
return `${n} px sur ${A.width * A.height}` + (n ? ` boîte ${x0},${y0}-${x1},${y1}` : "");
|
||||
}, [readFileSync(f[i]).toString('base64'), readFileSync(f[i + 1]).toString('base64')]);
|
||||
console.log(f[i].split('/').pop(), '|', f[i + 1].split('/').pop(), ':', r);
|
||||
}
|
||||
await b.close();
|
||||
Reference in New Issue
Block a user