title: how can convert a base64 svg image to base64 image png
body: <p>I have a code that converts a chart into svg. but I need the output format to be a PNG image. <code>svgString2Image</code> is the function that returns a codified base64 svg. How can I do it? thank you very much.</p>
  
  <pre><code>function svgString2Image( svgString, width, height, format, callback ) {
    //console.log("svgString",svgString)
      format ? format : 'png';
  
      var imgsrc = 'data:image/svg+xml;base64,'+ btoa( unescape( encodeURIComponent( svgString ) ) ); // Convert SVG string to data URL
      var canvas = document.createElement("canvas");
      var context = canvas.getContext("2d");
  
      canvas.width = width;
      canvas.height = height;
  
      var image = new Image();
      image.onload = function() {
          context.clearRect ( 0, 0, width, height );
          context.drawImage(image, 0, 0, width, height);
  
          canvas.toBlob( function(blob) {
              var filesize = Math.round( blob.length/1024 ) + ' KB';
              if ( callback ) callback( blob, filesize );
          });
  
      };
      ///****************************
    document.getElementById('my_image').src=imgsrc;
      return image.src = imgsrc;
  
  }
  </code></pre>
  
  <p><a href="http://plnkr.co/edit/lPhmuYywPCdjQrnwhQcH?p=preview" rel="nofollow noreferrer">http://plnkr.co/edit/lPhmuYywPCdjQrnwhQcH?p=preview</a></p>