tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

create-pattern-data-url.js (580B)


      1 const patternSize = 4;
      2 
      3 export default function createPatternDataURL() {
      4  const ctx = document.createElement('canvas').getContext('2d');
      5  ctx.canvas.width = patternSize;
      6  ctx.canvas.height = patternSize;
      7 
      8  const b = [0, 0, 0, 255];
      9  const t = [0, 0, 0, 0];
     10  const r = [255, 0, 0, 255];
     11  const g = [0, 255, 0, 255];
     12 
     13  const imageData = new ImageData(patternSize, patternSize);
     14  imageData.data.set([
     15    b, t, t, r,
     16    t, b, g, t,
     17    t, r, b, t,
     18    g, t, t, b,
     19  ].flat());
     20  ctx.putImageData(imageData, 0, 0);
     21  return {patternSize, dataURL: ctx.canvas.toDataURL()};
     22 }