function loadImage(url, crossOrigin, callback) {
    callback = callback || noop;
    var img = new Image();
    crossOrigin = crossOrigin !== undefined ? crossOrigin : defaults.crossOrigin;
    if (crossOrigin !== undefined) {
      img.crossOrigin = crossOrigin;
    }

    function clearEventHandlers() {
      img.removeEventListener('error', onError);  // eslint-disable-line
      img.removeEventListener('load', onLoad);  // eslint-disable-line
      img = null;
    }

    function onError() {
      var msg = "couldn't load image: " + url;
      utils.error(msg);
      callback(msg, img);
      clearEventHandlers();
    }

    function onLoad() {
      callback(null, img);
      clearEventHandlers();
    }

    img.addEventListener('error', onError);
    img.addEventListener('load', onLoad);
    img.src = url;
    return img;
  }
Loads an image
@param {string} url url to image
@param {function(err, img)} [callback] a callback that's passed an error and the image. The error will be non-null
    if there was an error
@return {HTMLImageElement} the image being loaded.