Check transparent canvas

Benchmark created on


Preparation HTML

<canvas id='editor' style='border:solid'></canvas>

<canvas id='blank' style='display:none'></canvas>

Setup

canvas = document.getElementById('editor');
    blank = document.getElementById('blank');
    ctx = canvas.getContext("2d");
    w = canvas.offsetWidth;
    h = canvas.offsetHeight;
    
    f1 = function() {
      var data = ctx.getImageData(0, 0, w, h).data;
      for(var i = 0, l = data.length; i < l; i += 4) {
        if(data[i + 3] !== 0) {
          return false;
        }
      }
      return true;
    };
    
    f2 = function() {
      return canvas.toDataURL() === blank.toDataURL();
    };

Test runner

Ready to run.

Testing in
TestOps/sec
Pixels
f1();
ready
Data URL
f2();
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.