Olian04
5/22/2017 - 3:11 PM

From https://stackoverflow.com/questions/19183180/how-to-save-an-image-to-localstorage-and-display-it-on-the-next-page

const saveBannerImg = function() {
  let bannerImage = document.getElementById('bannerImg');
  let imgData = getBase64Image(bannerImage);
  localStorage.setItem("imgData", imgData);
}

const getBase64Image = function(img) {
  let canvas = document.createElement("canvas");
  canvas.width = img.width;
  canvas.height = img.height;

  let ctx = canvas.getContext("2d");
  ctx.drawImage(img, 0, 0);

  let dataURL = canvas.toDataURL("image/png");
    
  return dataURL.replace(/^data:image\/(png|jpg);base64,/, "");
}

const loadBannerImg = function() {
  let dataImage = localStorage.getItem('imgData');
  let bannerImg = document.getElementById('tableBanner');
  bannerImg.src = "data:image/png;base64," + dataImage;
}