This repository has been archived by the owner on Oct 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 291
SVG Support #93
Comments
This is what I'm using svtToPng.html <div id="fileBox"></div>
<input placeholder="scale" id="sizeInput" value="128" />
<div id="output" />
<script>
var el = null;
window.onload = () => {
createFileElem();
document.getElementById("sizeInput").onchange = renderStuff;
};
function createFileElem(){
el = document.createElement("input");
el.type = "file";
el.onchange = renderStuff;
let fileBox = document.getElementById("fileBox");
fileBox.innerHTML = "";
fileBox.appendChild(el);
}
function renderStuff(){
if(el.files.length > 0){
let reader = new FileReader();
reader.onload = (e) => {
let size = document.getElementById("sizeInput").value;
if(size == "") size = 128;
makePng(e.target.result, +size);
}
reader.readAsText(el.files[0]);
}
}
function makePng(svgData,size){
var img = new Image();
var svg = new Blob([svgData], {type: 'image/svg+xml;charset=utf-8'});
var DOMURL = window.URL || window.webkitURL || window;
var url = DOMURL.createObjectURL(svg);
img.onload = function(){
var canvas = document.createElement('canvas');
canvas.width = size;
canvas.height = size;
var ctx = canvas.getContext('2d');
ctx.drawImage(img,0,0,size,size);
DOMURL.revokeObjectURL(url);
document.getElementById("output").innerHTML = '<img src="'+canvas.toDataURL()+'" style="background: black;" />';
}
img.src = url;
}
</script> drag the file to your browser, and it renders it exactly as a browser would do :) |
What?? |
You can use it to convert svg to png, it's not as good as having it convert while building the application but it did the job for me. |
@jespertheend Wtf, dude :) The feature request is about to support SVG for app icons and splash screens, not how to convert SVG to PNG. |
I understand that, and I wanted something like that as well, but I'm using this in the meantime as a workaround. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Feature request for SVG Support.
The text was updated successfully, but these errors were encountered: