title: Cannot read property 'toDataURL' of undefined -- Save Canvas as images
body: <p>Canvas2Image.js</p>
  
  <pre><code>return {
  
      saveAsPNG : function(oCanvas, bReturnImg, iWidth, iHeight) {
          if (!bHasDataURL) {
              return false;
          }
          var oScaledCanvas = scaleCanvas(oCanvas, iWidth, iHeight);
          var strData = oScaledCanvas.toDataURL("image/png");
          if (bReturnImg) {
              return makeImageObject(strData);
          } else {
              saveFile(strData.replace("image/png", strDownloadMime));
          }
          return true;
      },
  
      saveAsJPEG : function(oCanvas, bReturnImg, iWidth, iHeight) {
          if (!bHasDataURL) {
              return false;
          }
  
          var oScaledCanvas = scaleCanvas(oCanvas, iWidth, iHeight);
          var strMime = "image/jpeg";
          var strData = oScaledCanvas.toDataURL(strMime);
  
          // check if browser actually supports jpeg by looking for the mime type in the data uri.
          // if not, return false
          if (strData.indexOf(strMime) != 5) {
              return false;
          }
  
          if (bReturnImg) {
              return makeImageObject(strData);
          } else {
              saveFile(strData.replace(strMime, strDownloadMime));
          }
          return true;
      },
  </code></pre>
  
  <p>Call using this:</p>
  
  <pre><code>function exportAndSaveCanvas()  {
  
      // Get the canvas screenshot as PNG
      var screenshot = Canvas2Image.saveAsPNG(canvas, true);
  
      // This is a little trick to get the SRC attribute from the generated &lt;img&gt; screenshot
      canvas.parentNode.appendChild(screenshot);
      screenshot.id = "canvasimage";      
      data = $('#canvasimage').attr('src');
      canvas.parentNode.removeChild(screenshot);
  
  
      // Send the screenshot to PHP to save it on the server
      var url = 'upload/export.php';
      $.ajax({ 
          type: "POST", 
          url: url,
          dataType: 'text',
          data: {
              base64data : data
          }
      });
  </code></pre>
  
  <p>Wanting to covert the convert it to images and save but get this error : Uncaught TypeError: Cannot read property 'toDataURL' of undefined. Any idea how can i solve it?</p>
  
  <p>** i copy these codes from other source and other people using seem to be working fine with these codes. Did i miss out something?</p>
  
  <p>**** Both oScaledCanvas and oCanvas are undefined. Why?</p>