notes/HTML5 Load local file on to canvas-9QNRWTJ7.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>Load Image</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<input type='file' name='img' size='65' id='uploadimage' />
<br>
<canvas id="canvas" width="500" height="500"></canvas>
</body>
<script>
document.getElementById("uploadimage").addEventListener("change", draw, false);
function draw(ev) {
console.log(ev);
var ctx = document.getElementById('canvas').getContext('2d'),
img = new Image(),
f = document.getElementById("uploadimage").files[0],
url = window.URL || window.webkitURL,
src = url.createObjectURL(f);
img.src = src;
img.onload = function() {
ctx.drawImage(img, 0, 0);
url.revokeObjectURL(src);
}
}
</script>
</html>
syntax highlighted by Code2HTML, v. 0.9.1