i'm having some issues converting a thumbnail image generation function to a promise.
I need to have it so it runs the Promise.all once the thumbnail has been generated, currently the thumb is undefined (which makes sense as it needs to generate first).
I don't understand the first img.onload part, my work around was to set it on $scope, which i know is a terrible way to pass data around.
    var img = new Image;
    img.onload = resizeImage;
    img.src = $scope.imageData;
    function resizeImage() {
      var newDataUri = imageToDataUri(this, 100, 100);
      $scope.imageDataThumb = newDataUri;
      $scope.$apply();
    }
    function imageToDataUri(img, width, height) {
      // create an off-screen canvas
      var canvas = document.createElement('canvas'),
      ctx = canvas.getContext('2d');
      canvas.width = width;
      canvas.height = height;
      ctx.drawImage(img, 0, 0, width, height);
      var quality = 1.0;
      return canvas.toDataURL('image/jpeg', quality).split(",")[1];  // quality = [0.0, 1.0]
    }
    var imgGuid = factory.guid();
    //Save the image to storage
    console.log($scope.imageDataThumb);
    Promise.all([fireBaseService.postImageToStorage(imageData, "images", imgGuid), fireBaseService.postImageToStorage($scope.imageDataThumb, "images", "thumb_" + imgGuid)])
      .then(function (results) {
      //do stuff with results
      });
