Adjust SVG size based on loaded image
This commit is contained in:
parent
6b3d75fdc6
commit
5513e91773
1 changed files with 16 additions and 6 deletions
|
|
@ -27,13 +27,23 @@ function loadImage(base64Image) {
|
||||||
let svgDataUrl;
|
let svgDataUrl;
|
||||||
|
|
||||||
sourceImage.onload = function () {
|
sourceImage.onload = function () {
|
||||||
|
let svgWidth = this.width;
|
||||||
|
let svgHeight = this.height;
|
||||||
|
|
||||||
|
if (this.width > 1000) {
|
||||||
|
svgWidth = 1000;
|
||||||
|
svgHeight = 1000 * this.height / this.width;
|
||||||
|
}
|
||||||
|
|
||||||
|
svg.setAttribute("height", svgHeight);
|
||||||
|
svg.setAttribute("width", svgWidth);
|
||||||
|
|
||||||
|
let svgString = (new XMLSerializer).serializeToString(svg);
|
||||||
|
svgDataUrl = 'data:image/svg+xml,' + encodeURIComponent(svgString);
|
||||||
|
|
||||||
filterImage(svgDataUrl, this.width, this.height);
|
filterImage(svgDataUrl, this.width, this.height);
|
||||||
};
|
};
|
||||||
sourceImage.src = svgImage.href.baseVal = sourcePreview.src = base64Image;
|
sourceImage.src = svgImage.href.baseVal = sourcePreview.src = base64Image;
|
||||||
|
|
||||||
|
|
||||||
let svgString = (new XMLSerializer).serializeToString(svg);
|
|
||||||
svgDataUrl = 'data:image/svg+xml,' + encodeURIComponent(svgString);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -54,7 +64,7 @@ function handleFileSelect(e) {
|
||||||
|
|
||||||
document.querySelector('#file_input').addEventListener('change', handleFileSelect, false);
|
document.querySelector('#file_input').addEventListener('change', handleFileSelect, false);
|
||||||
|
|
||||||
function downloadURI(uri, name) {
|
function downloadURI(_uri, _name) {
|
||||||
let link = document.createElement("a");
|
let link = document.createElement("a");
|
||||||
link.download = 'distortedImageEH22.png';
|
link.download = 'distortedImageEH22.png';
|
||||||
link.href = result;
|
link.href = result;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue