0

i'm using this function to convert an svg to a jpeg (it includes canvg):

    svgToDataUrl(svg, format = 'jpeg') {
        var id = new Date();
        var canvasElement = $(`<canvas id="${id}" width="1198px" 
height="1694px"></canvas>`).appendTo('#resultsInterface');
        let canvas = canvasElement[0];
        window.canvg(canvas, svg);
        var imgData = canvas.toDataURL(`image/${format}`, 0.98);
        canvasElement.remove();
        return imgData;
     }

The SVG variable in a SVG image previously generated. Now, it works properly but, if the SVG contains a tag with an href in base64 format:

<image xlink:href="data:image/png;base64,iVBORblablabla..."></image>

The result is blank. I've tried to check the canvas generated (before it is removed) and is just fine but for some reason canvas.toDataURL seems not working in this case.

Any clue?

Thanks Daniele

Daniele
  • 71
  • 1
  • 2
  • 5

0 Answers0