better svgs

This commit is contained in:
Kyle
2020-10-22 21:09:50 -07:00
parent 4435580473
commit 5c74232df0
2 changed files with 20 additions and 1 deletions

View File

@@ -175,7 +175,7 @@
<div class="autoGrid"> <div class="autoGrid">
<input type="file" accept="image/*" onchange="uploadImage(event, watermark)" placeholder="Via File Upload"> <input type="file" accept="image/*" onchange="uploadImage(event, watermark)" placeholder="Via File Upload">
<input type="text" placeholder="Via URL" onchange="watermark.src = 'https://cors-anywhere.herokuapp.com/' + this.value"> <input type="text" placeholder="Via URL" onchange="watermark.src = 'https://cors-anywhere.herokuapp.com/' + this.value">
<input type="text" placeholder="Via Set Code" onchange="watermark.src = 'https://cors-anywhere.herokuapp.com/http://gatherer.wizards.com/Handlers/Image.ashx?type=symbol&set=' + this.value + '&size=large'"> <input type="text" placeholder="Via Set Code" onchange="cropSVG(this.value, watermark)">
<select id="inputWatermarkPrimary" onchange="watermarkUpdated()"> <select id="inputWatermarkPrimary" onchange="watermarkUpdated()">
<option value="none">None</option> <option value="none">None</option>
<option value="default">Default</option> <option value="default">Default</option>

View File

@@ -1103,6 +1103,25 @@ function artistNameUpdated(artistName) {
bottomInfoUpdated() bottomInfoUpdated()
} }
//svg cropper
function cropSVG(set, targetImage) {
xhttp = new XMLHttpRequest()
xhttp.open('GET', 'https://raw.githubusercontent.com/andrewgioia/keyrune/4073ac89bb943978c29be504275e6f3160a07255/svg/' + set + '.svg', true)
xhttp.overrideMimeType('image/svg+xml')
xhttp.onload = function(event) {
if (this.readyState == 4 && this.status == 200) {
var svg = document.body.appendChild(xhttp.responseXML.documentElement)
var box = svg.getBBox(svg)
svg.setAttribute('viewBox', [box.x, box.y, box.width, box.height].join(' '))
svg.setAttribute('width', box.width)
svg.setAttribute('height', box.height)
targetImage.src = 'data:image/svg+xml,'+encodeURIComponent(svg.outerHTML)
svg.remove()
}
}
xhttp.send()
}
//Must run last: //Must run last:
initialize() initialize()