title: Simplest image format: PPM to dataURI
body: <p>I try to generate PPM image dataURI using this format <a href="http://netpbm.sourceforge.net/doc/ppm.html" rel="nofollow noreferrer">description</a> (which is theoretically very simple) in JS but my code doesn't work. My attempt is below - how can I fix it?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>let ppmH="P6 3 2 255 "  // PPM header: 3x2 pixel picture (total 6 pixels)  
  let ppmD=[ 255,0,0,    0,255,0,    0,0,255,     // 3 pixels
             0,255,255,  255,0,255,  255,255,0];  // 3 pixels
  
  var base64 = btoa( ppmH +String.fromCharCode.apply(null, new Uint8Array(ppmD)));
  
  let uri= "data:image/x-portable-pixmap;base64,"+base64;
  
  pic.src=uri;
  console.log(uri);</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;img id="pic"&gt;</code></pre>
  </div>
  </div>
  </p>