)
}
}
)
(
}
{
)
)
(
)
(
(
{
}
)
(
)
}
)
)
{
(
(
)
)
}
)
(
}

Upload Image

  1. const uploadInput = document.body.appendChild(
  2.   Object.assign(document.createElement('input'), {
  3.     type: 'file',
  4.     accept: 'image/png, image/jpeg'
  5.   })
  6. );
  7.  
  8. const imageEl = document.body.appendChild(
  9.   Object.assign(document.createElement('img'), {
  10.     style: `
  11.             display:block;
  12.             width: 100%;
  13.           `
  14.   })
  15. );
  16.  
  17. const reader = new FileReader();
  18.  
  19. reader.addEventListener('load', () => {
  20.   imageEl.src = reader.result;
  21. });
  22.  
  23. uploadInput.addEventListener('change', e => {
  24.   const file = e.target.files[0];
  25.   if (file != null) {
  26.     reader.readAsDataURL(file);
  27.   }
  28. });

Load an image into memory…

// images // javascript // ui
snippet.zone ~ 2021-22 /// {s/z}