/**
 * Load an image by its url
 *
 * @param {String} url
 * @param {Function} init - an optional image initializer
 * @return {Promise}
 */
export function loadUrl(url, init) {
  var img = new Image();
  img.setAttribute('crossOrigin', 'anonymous');
  return new Promise(function (resolve) {
    img.onload = function () {
      resolve(img);
    };

    img.src = url;
  });
}
/**
 * Return a collection of images from an
 * array of File objects
 *
 * @param {File} file
 * @return {Promise}
 */

export function loadFile(file) {
  var reader = new FileReader();
  return new Promise(function (resolve) {
    var img = new Image();

    reader.onloadend = function () {
      return setAndResolve(img, reader.result, resolve);
    };

    reader.readAsDataURL(file);
  });
}