Reuse existing image element on conversion.

This commit is contained in:
GoteGuru 2022-05-20 01:15:03 +02:00
parent 16f6557e69
commit d01e2faa75

View file

@ -1006,10 +1006,14 @@ function editHeightmap() {
this.value = ""; // reset input value to get triggered if the file is re-uploaded
const reader = new FileReader();
const img = new Image();
img.id = "imageToConvert";
const imgId = "imageToConvert";
let img = document.getElementById(imgId);
if (!img) {
img = new Image();
img.id = imgId;
img.style.display = "none";
document.body.appendChild(img);
}
img.onload = function () {
const ctx = document.getElementById("canvas").getContext("2d");