HTMLify
diq.html
Views: 524 | 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 | <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Imager Quality Decreaser</title> <style> .main{ border:2px solid; margin:5px; padding: 10px; } #output-image{ width:100%; height:100%; } </style> </head> <body> <div class="main"> <input type="file" id="inputImage" accept="image/*" onchange="displayImage()"><br> <div id="image-container"> <br><img id="output-image" alt="Original Image"><br> </div> <div id="options-container"> <br><label>Value: <input type="number" id="widthInput" value="300"> </label> <button onclick="quality()">Submit</button><br><br> <button onclick="downloadImage()">Download</button> </div> </div> <script> function displayImage() { const inputImage = document.getElementById('inputImage'); const outputImage = document.getElementById('output-image'); outputImage.src = URL.createObjectURL(inputImage.files[0]); } function quality() { const inputImage = document.getElementById('inputImage'); const outputImage = document.getElementById('output-image'); const widthInput = document.getElementById('widthInput'); const width = parseInt(widthInput.value); const canvas = document.createElement('canvas'); const ctx = canvas.getContext('2d'); const img = new Image(); img.src = URL.createObjectURL(inputImage.files[0]); img.onload = function() { canvas.width = width; canvas.height = (width / img.width) * img.height; ctx.drawImage(img, 0, 0, width, canvas.height); // Convert canvas to data URL const quality = canvas.toDataURL('image/jpeg'); // Display the resized image outputImage.src = quality; }; } function downloadImage() { const image = document.getElementById('output-image'); 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> |