title: How to save canvas on phone and get the location of the image with phonegap?
body: <p>What is the way to save a canvas to your phone album (camera roll, etc.) using Phonegap?</p>
  
  <p>And when saved, how do I get the image URL using Cordova? Which plugins should I consider for this?</p>
  
  <hr>
  
  <p><strong>Method 1: Canvas2Image Plugin</strong></p>
  
  <p>With <a href="https://github.com/devgeeks/Canvas2ImagePlugin" rel="nofollow">this plugin</a>, you can save a canvas to your phone library using:</p>
  
  <pre><code>&lt;canvas id="myCanvas" width="165px" height="145px"&gt;&lt;/canvas&gt;
  
  function onDeviceReady()
  {
      window.canvas2ImagePlugin.saveImageDataToLibrary(
          function(msg){
              console.log(msg);
          },
          function(err){
              console.log(err);
          },
          document.getElementById('myCanvas')
      );
  }
  </code></pre>
  
  <p>However, it is not clear how the imageURI is passed or returned after saving?</p>
  
  <p>UPDATE 23/02. I tried the following, but it never reaches my successcallback:</p>
  
  <p>$scope.done = function() {</p>
  
  <pre><code>    // todo: iterate over cloaks
      $ionicLoading.show({
              template: 'Saving images...'
      });
  
  
      // #issue: callback is not called
      saveCanvasToPhone().then(successCallback, errorCallback);
  
      var successCallback = function(output) {
          $ionicLoading.hide();
  
          window.alert("success call back: " + output) // never reached
  
          $scope.addNewImage(output);
          $state.go('tab.dash', {}, {reload: true}); // does not work
          $state.go('tab.dash') // does not work
  
          $scope.refreshLocalstorage();
  
      }
  
      // #issue4-nl: not working
      var errorCallback = function(error) {
          $ionicLoading.hide();
          console.log("error cb: "+ error)
          window.alert("error cb: " + error)
      }
  
      function saveCanvasToPhone() {
  
  
  
          var defer = $q.defer();
  
          try {
              window.canvas2ImagePlugin.saveImageDataToLibrary(
              function(output){
  
                  $scope.addNewImage(output); // does not work to save imagepath on localstorage
  
                  $scope.debugEntryOther = output // works fine
                  defer.resolve(output)
                  $ionicLoading.hide()
              },
              function(error){
                  defer.reject(error)
                  $ionicLoading.hide()
                  window.alert(error)
              },
              document.getElementById('canvas')
          );
          } catch(error) {
                  defer.reject(error)
                  $ionicLoading.hide()
                  console.log("saveCanvasToPhone: trycatch: error: " + error)
          }
          return defer.promise;
      } // save canvas to phone
  } // done
  </code></pre>