HTMLify
ir.html
Views: 556 | Author: djdj
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Image Resizer</title> <style> body { font-family: Arial, sans-serif; text-align: center; margin: 20px; padding:10px; height:91vh; } #uploadedImage { max-width: 100%; height: auto; margin-top: 20px; } label { display: block; margin-top: 10px; } </style> </head> <body> <input type="file" id="imageInput" accept="image/*"> <label for="currentSize">Current Size:</label> <span id="currentSize"></span> <img id="uploadedImage" alt="Uploaded Image"> <label for="newWidth">New Width:</label> <input type="number" id="newWidth" placeholder="Enter new width"> <label for="newHeight">New Height:</label> <input type="number" id="newHeight" placeholder="Enter new height"> <button onclick="resizeImage()">Resize Image</button><br><br> <button onclick="downloadImage()">Download</button> <br><br><br> <script> document.getElementById('imageInput').addEventListener('change', handleImageUpload); function handleImageUpload() { const input = document.getElementById('imageInput'); const image = document.getElementById('uploadedImage'); const sizeLabel = document.getElementById('currentSize'); const file = input.files[0]; const reader = new FileReader(); reader.onload = function (e) { image.src = e.target.result; sizeLabel.textContent = `Width: ${image.width}px, Height: ${image.height}px`; }; reader.readAsDataURL(file); } function resizeImage() { const image = document.getElementById('uploadedImage'); const newWidth = document.getElementById('newWidth').value; const newHeight = document.getElementById('newHeight').value; if (newWidth && newHeight) { image.style.width = `${newWidth}px`; image.style.height = `${newHeight}px`; } } function downloadImage() { const image = document.getElementById('uploadedImage'); const link = document.createElement('a'); link.href = image.src; link.download = 'resized_image.png'; document.body.appendChild(link); link.click(); document.body.removeChild(link); } </script> </body> </html> |