svgToPng(svg,(imgData)=>{ //svg XML code
    const pngImage = document.createElement('img');
    document.body.appendChild(pngImage);
    pngImage.src=imgData;
});

function svgToPng(svg, callback) {
    const url = URL.createObjectURL(new Blob([svg], { type: 'image/svg+xml' }));
    svgUrlToPng(url, (imgData) => {
        callback(imgData);
        URL.revokeObjectURL(url);
    });
}

function svgUrlToPng(svgUrl, callback) {
    const svgImage = document.createElement('img');
    // imgPreview.style.position = 'absolute';
    // imgPreview.style.top = '-9999px';
    document.body.appendChild(svgImage);
    svgImage.onload = function () {
        const canvas = document.createElement('canvas');
        canvas.width = svgImage.clientWidth;
        canvas.height = svgImage.clientHeight;
        const canvasCtx = canvas.getContext('2d');
        canvasCtx.drawImage(svgImage, 0, 0);
        const imgData = canvas.toDataURL('image/png');
        callback(imgData);
        // document.body.removeChild(imgPreview);
    };
    svgImage.src = svgUrl;
}



function on_zoom_svg(id, amount) {
	var div = document.getElementById(id);
	var svg = div.firstChild;

	var width = parseInt(svg.getAttribute("width"));
	var height = parseInt(svg.getAttribute("height"));
	var vb = svg.getAttribute("viewBox");
	if (vb == null) {
		mcdHeightOverWidth = svg.getAttribute("height") / svg.getAttribute("width");
		vb = "0 0 " + width + " " + height;
		svg.setAttribute("viewBox", vb);
	}
	var vbWidth = parseInt(vb.split(" ")[2]);
	var vbHeight = parseInt(vb.split(" ")[3]);
	width += amount * 10;
	height = Math.round(width * mcdHeightOverWidth);
	var x = 0;
	var y = Math.round((vbHeight - height) / 10);
	console.log("TRUE", x, y);
	svg.setAttribute("width", width);
	svg.setAttribute("height", height);
	svg.setAttribute("viewBox", x + " " + y + " " + vbWidth + " " + vbHeight);
}

function on_zoom_text(id, amount) {
	let element = document.getElementById(id);
	let fontSize = window.getComputedStyle(element).getPropertyValue("font-size");
	let size = parseInt(fontSize);
	let unit = fontSize.substring(size.toString().length);
	size += amount;
	element.style.fontSize = size.toString() + unit;
}
