HTMLify

ir.html
Views: 211 | Author: djdj
<!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>

Comments