Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!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>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement