1

I am in need of converting a base64 encoded svg to a png and then returning it to the client to be rendered.

The idea is that I am drawing an svg on the client using d3.js and I need to convert it to png.

I tried taking the javascript root and writing the svg on the canvas and then converting it toDataUrl but IE has problems with this on all versions so this is not a viable option.

I have searched online a bit and all I could find is Inkscape.

This is not a viable solution for me because of limited access on the server and frankly I don't think it's a good idea to install an entire application for a simple functionality.

Is there any other solution that can take a base 64 encoded svg and return a png that can be displayed in an image?

Kalle
  • 2,282
  • 1
  • 24
  • 30
aleczandru
  • 5,319
  • 15
  • 62
  • 112
  • Is [link](https://stackoverflow.com/questions/58910/converting-svg-to-png-using-c-sharp) this of any help? – Hintham Mar 26 '15 at 13:14

2 Answers2

0

I am facing the same issue, however I been able to render the SVG into an image so your users could right click to download the image or right click on the canvas. There is also Canvg which has a library that appears to work with IE, however it is not accurate for complex SVG and so does not meet my needs. Perhaps it will help you.

I have code in my question that will work in IE, just use the IMG or Canvas object, you do not need to call toDataURI.

Checkout Canvg, it might be of help.

Good luck! If you find a better solution, please let me know. :-)

Nicholas
  • 572
  • 6
  • 17
0

I found that since I have to support IE 11 I instead went with canvas to blob to PNG using "canvas-toBlob.js" and "FileSaver.js"

$("#save-btn").click(function() 
{
    $("#myChart").get(0).toBlob(function(blob) 
    {
        saveAs(blob, "chart_1.png");
    });
});

https://jsfiddle.net/mfvmoy64/155

C Sharp Conner
  • 378
  • 2
  • 11