Saturday, October 28, 2023

Creating a complete responsive Image Resizer tool with a download button, user-customizable width and height, and colorful styling in HTML, CSS, and JavaScript is a multifaceted task. To keep this article concise, I will provide an overview of the steps and code snippets required to build this tool. Title: Building a Responsive Image Resizer Tool with HTML, CSS, and JavaScript

html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport"content="width=device-width, initial-scale=1.0"> <link rel="stylesheet"href="styles.css"> <title>Image Resizer Tool</title> </head> <body> <divclass="container"> <h1>Image Resizer</h1> <input type="file" id="imageInput"accept="image/*"> <div class="controls"> <input type="number" id="widthInput"placeholder="Width"> <input type="number" id="heightInput" placeholder="Height"> <buttonid="resizeButton">Resize</button> </div> <img id="resizedImage" alt="Resized Image"> <aid="downloadButton" download="resized_image.png">Download</a> </div> <scriptsrc="script.js"></script> </body> </html>

CSS (styles.css)

css
body { font-family: Arial, sans-serif; background-color#f0f0f0text-align: center; }.container { background-color#fffmax-width400pxmargin0 auto; padding20px;border-radius8pxbox-shadow0 0 5px rgba(0000.2); } h1 { color#333; } inputbutton { margin10pxpadding5pxborder1px solid #cccborder-radius4px; }#resizeButton { background-color#4CAF50color: white; cursor: pointer; }#resizeButton:hover { background-color#45a049; } #resizedImage { max-width100%;height: auto; display: none; } #downloadButton { display: none; text-decoration: none;background-color#4CAF50color: white; padding10pxborder-radius4pxmargin10px; }

JavaScript (script.js)

javascript
document.getElementById("imageInput").addEventListener("change"function (e) { constfile = e.target.files[0]; if (file) { const image = new Image(); image.src = URL.createObjectURL(file); image.onload = function () {document.getElementById("resizedImage").src = image.src;document.getElementById("downloadButton").style.display = "block"; }; } });document.getElementById("resizeButton").addEventListener("click"function () { constwidth = document.getElementById("widthInput").valueconst height = document.getElementById("heightInput").valueconst resizedImage = document.getElementById("resizedImage"); resizedImage.style.width = width + "px"; resizedImage.style.height = height + "px"const downloadButton = document.getElementById("downloadButton"); downloadButton.href = resizedImage.src; });

This code will create a responsive image resizer tool with a download button and customizable width and height fields. Users can select an image, set the dimensions, and download the resized image. Styling is provided to make the tool visually appealing. Make sure to place these code snippets in separate files (HTML, CSS, and JavaScript) and adjust the file paths accordingly.