title: Can't convert base64Image to ImageData object
body: <p>I'm currently trying to convert a base64Encoded string (representation of an image) into an ImageData object in Javascript. However, this comes back with an  error:</p>
  <p>Uncaught InvalidStateError: Failed to construct 'ImageData': The input data length is not a multiple of 4.</p>
  <p>The encoded image is 940 x 740</p>
  <p>What am I missing? Any help appreciated</p>
  <p><a href="https://jsfiddle.net/w7u2ba3c/" rel="nofollow noreferrer">JSFiddle link with full code</a></p>
  <pre><code>   function _base64ToArrayBuffer(base64) {
          var binary_string = window.atob(base64);
          var len = binary_string.length;
          var bytes = new Uint8Array(len);
          for (var i = 0; i &lt; len; i++) {
              bytes[i] = binary_string.charCodeAt(i);
          }
          return bytes.buffer;
      }
  
  
  const base64String = &quot;&quot;; //truncated because stackoverflow question too long.
  const arrBuffer = _base64ToArrayBuffer (base64String );
  
  var array = new Uint8ClampedArray(arrBuffer);
  console.log(array);
  var image = new ImageData(array, 900, 740);
  console.log(image);
  </code></pre>