Files

22 lines
1.5 KiB
JavaScript

import puppeteer from 'puppeteer';
import sharp from 'sharp';
const b = await puppeteer.launch({ args:['--no-sandbox','--disable-setuid-sandbox','--use-gl=angle','--enable-unsafe-swiftshader','--ignore-gpu-blocklist'] });
const p = await b.newPage();
await p.setViewport({width:1100,height:1300});
await p.goto('http://10.200.201.3:4175/_lab/neu-card.html',{waitUntil:'load',timeout:60000});
await new Promise(r=>setTimeout(r,1500));
await p.evaluate(()=>document.querySelector('#sec-shader').scrollIntoView());
await new Promise(r=>setTimeout(r,900));
// координаты демо-карточки
const rect = await p.evaluate(()=>{ const r=document.querySelector('[data-shader-demo]').getBoundingClientRect(); return {x:r.x,y:r.y,w:r.width,h:r.height}; });
await p.screenshot({path:'/tmp/full.png'});
const img = sharp('/tmp/full.png');
const {data,info}=await img.raw().toBuffer({resolveWithObject:true});
// вырежем центр демо-карточки (по координатам вьюпорта)
const x0=Math.floor(rect.x+rect.w*0.2), y0=Math.floor(rect.y+rect.h*0.2);
const x1=Math.floor(rect.x+rect.w*0.8), y1=Math.floor(rect.y+rect.h*0.8);
let rs=0,gs=0,bs=0,n=0; const cols=new Set();
for(let y=y0;y<y1;y+=3){ for(let x=x0;x<x1;x+=3){ const i=(y*info.width+x)*3; rs+=data[i];gs+=data[i+1];bs+=data[i+2]; cols.add(`${data[i]>>5},${data[i+1]>>5},${data[i+2]>>5}`); n++; } }
console.log('demo card region avg:', [Math.round(rs/n),Math.round(gs/n),Math.round(bs/n)], 'distinct coarse colors:', cols.size);
await b.close();