Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <script>
- function uploadImage(input) {
- var reader = new FileReader();
- reader.onload = function (event) {
- var image = new Image();
- image.onload = function () {
- var width = parseInt(prompt("Informe a largura desejada:", "1280"));
- var height = parseInt(prompt("Informe a altura desejada:", "720"));
- var canvas = document.createElement("canvas");
- canvas.width = width;
- canvas.height = height;
- var ctx = canvas.getContext("2d");
- ctx.drawImage(image, 0, 0, width, height);
- document.getElementById("image").src = canvas.toDataURL();
- document.getElementById("downloadButton").style.display = "block";
- document.getElementById("image").style.display = "block";
- };
- image.src = event.target.result;
- };
- reader.readAsDataURL(input.files[0]);
- }
- function downloadImage() {
- var d = new Date();
- var dateString = d.getDate() + "-" + (d.getMonth() + 1) + "-" + d.getFullYear();
- var timeString = d.getHours() + "-" + d.getMinutes() + "-" + d.getSeconds();
- var image = document.getElementById("image");
- var link = document.createElement("a");
- link.download = dateString + "-" + timeString + "-resized-image.png";
- link.href = image.src;
- link.click();
- }
- </script>
- </head>
- <body>
- <input type="file" onchange="uploadImage(this)">
- <br><br>
- <img id="image" src="" style="display: none">
- <br><br>
- <button id="downloadButton" onclick="downloadImage()" style="display: none">Baixar imagem</button>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement