download (name, options = {}) {
    // Setup default options
    options.format = options.format || 'image/jpeg';

    // Convert it to a data URI
    this._toDataURI(options, (uri) => {
      // We have our data URI

      // Create an image
      const image = new window.Image();
      image.src = uri;

      // Confiugre the image onload callback
      image.onload = function () {
        // Create a canvas element sized to fit the image
        const canvas = document.createElement('canvas');
        canvas.width = image.width;
        canvas.height = image.height;

        // Get the canvas context and draw the image onto it
        const context = canvas.getContext('2d');
        context.drawImage(image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height);

        // Create a link to dynamically click and trigger the download
        const a = document.createElement('a');
        a.download = name;
        a.href = canvas.toDataURL(options.format || 'image/jpeg');
        document.body.appendChild(a);

        // I'm aware that `a.click()` below may not work reliably on all browsers. This is something to explore at a later date.

        // Click and download
        a.click();
      }
    });
  }
/**
   * Downloads the SVG as an image
   *
   * @param {string} name - The name to download the image with
   * @param {object} options - The configurable options
   */
Downloads the SVG as an image
@param {string} name - The name to download the image with
@param {object} options - The configurable options
Downloads the SVG as an image @param { string } name - The name to download the image with @param { object } options - The configurable options
download (name, options = {}) {
    options.format = options.format || 'image/jpeg';
    this._toDataURI(options, (uri) => {
      const image = new window.Image();
      image.src = uri;
      image.onload = function () {
        const canvas = document.createElement('canvas');
        canvas.width = image.width;
        canvas.height = image.height;
        const context = canvas.getContext('2d');
        context.drawImage(image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height);
        const a = document.createElement('a');
        a.download = name;
        a.href = canvas.toDataURL(options.format || 'image/jpeg');
        document.body.appendChild(a);
        a.click();
      }
    });
  }
download ( name , options = { } ) { options . format = options . format || 'image/jpeg' ; this . _toDataURI ( options , ( uri ) => { const image = new window . Image ( ) ; image . src = uri ; image . onload = function ( ) { const canvas = document . createElement ( 'canvas' ) ; canvas . width = image . width ; canvas . height = image . height ; const context = canvas . getContext ( '2d' ) ; context . drawImage ( image , 0 , 0 , image . width , image . height , 0 , 0 , canvas . width , canvas . height ) ; const a = document . createElement ( 'a' ) ; a . download = name ; a . href = canvas . toDataURL ( options . format || 'image/jpeg' ) ; document . body . appendChild ( a ) ; a . click ( ) ; } } ) ; }
Downloads the SVG as an image
 @param {string} name - The name to download the image with
 @param {object} options - The configurable options
Downloads the SVG as an image @param { string } name - The name to download the image with @param { object } options - The configurable options
// Setup default options // Convert it to a data URI // We have our data URI // Create an image // Confiugre the image onload callback // Create a canvas element sized to fit the image // Get the canvas context and draw the image onto it // Create a link to dynamically click and trigger the download // I'm aware that `a.click()` below may not work reliably on all browsers. This is something to explore at a later date. // Click and download