function toDataUrl(src, callback, outputFormat) {
    // Create an Image object
    var img = new Image();
    // Add CORS approval to prevent a tainted canvas
    img.crossOrigin = 'Anonymous';
    img.onload = function () {
      // Create an html canvas element
      var canvas = document.createElement('CANVAS');
      // Create a 2d context
      var ctx = canvas.getContext('2d');
      var dataURL;
      // Resize the canavas to the image dimensions
      canvas.height = this.height;
      canvas.width = this.width;
      // Draw the image to a canvas
      ctx.drawImage(this, 0, 0);
      // Convert the canvas to a data url
      dataURL = canvas.toDataURL(outputFormat);
      // Return the data url via callback
      callback(dataURL, canvas.width, canvas.height);
      // Mark the canavas to be ready for garbage
      // collection
      canvas = null;
    };
    // Load the image
    img.src = src;
    // make sure the load event fires for cached images too
    if (img.complete || img.complete === undefined) {
      // Flush cache
      img.src = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==';
      // Try again
      img.src = src;
    }
  }
// modified callback caller to return img size.
modified callback caller to return img size.
modified callback caller to return img size .
function toDataUrl(src, callback, outputFormat) {
    var img = new Image();
    img.crossOrigin = 'Anonymous';
    img.onload = function () {
      var canvas = document.createElement('CANVAS');
      var ctx = canvas.getContext('2d');
      var dataURL;
      canvas.height = this.height;
      canvas.width = this.width;
      ctx.drawImage(this, 0, 0);
      dataURL = canvas.toDataURL(outputFormat);
      callback(dataURL, canvas.width, canvas.height);
      canvas = null;
    };
    img.src = src;
    if (img.complete || img.complete === undefined) {
      img.src = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==';
      img.src = src;
    }
  }
function toDataUrl ( src , callback , outputFormat ) { var img = new Image ( ) ; img . crossOrigin = 'Anonymous' ; img . onload = function ( ) { var canvas = document . createElement ( 'CANVAS' ) ; var ctx = canvas . getContext ( '2d' ) ; var dataURL ; canvas . height = this . height ; canvas . width = this . width ; ctx . drawImage ( this , 0 , 0 ) ; dataURL = canvas . toDataURL ( outputFormat ) ; callback ( dataURL , canvas . width , canvas . height ) ; canvas = null ; } ; img . src = src ; if ( img . complete || img . complete === undefined ) { img . src = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==' ; img . src = src ; } }
modified callback caller to return img size.
modified callback caller to return img size .
// Create an Image object // Add CORS approval to prevent a tainted canvas // Create an html canvas element // Create a 2d context // Resize the canavas to the image dimensions // Draw the image to a canvas // Convert the canvas to a data url // Return the data url via callback // Mark the canavas to be ready for garbage // collection // Load the image // make sure the load event fires for cached images too // Flush cache // Try again