JSFiddle - React, Tailwind, and code Playground
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<script>
window.onload = function() {
var input = document.getElementById('input');
input.addEventListener('change', handleFiles);
}
function handleFiles(e) {
var ctx = document.getElementById('canvas').getContext('2d');
var reader = new FileReader;
reader.onload = function(event) {
var img = new Image;
img.src = event.target.result;
img.onload = function() {
ctx.drawImage(img, 20,20);
alert('the image is drawn');
}
}
reader.readAsDataURL(e.target.files[0]);
}
</script>
</head>
<body>
<h1>Test</h1>
<input type="file" id="input"/>
<canvas width="400" height="300" id="canvas"/>
</body>
</html>