Thursday, February 6, 2025

Image Converter Tool website


0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home

/* styles.css */ body { font-family: Arial, sans-serif; background-color: #f4f4f9; margin: 0; padding: 0; display: flex; justify-content: center; align-items: center; height: 100vh; } .container { background: white; padding: 2rem; border-radius: 10px; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); text-align: center; max-width: 400px; width: 100%; } h1 { font-size: 2rem; margin-bottom: 1rem; color: #333; } p { font-size: 1rem; color: #666; margin-bottom: 2rem; } input[type="file"] { display: block; margin: 0 auto 1rem; padding: 0.5rem; border: 1px solid #ccc; border-radius: 5px; } select { display: block; margin: 0 auto 1rem; padding: 0.5rem; border: 1px solid #ccc; border-radius: 5px; width: 100%; } button { background: #007bff; color: white; border: none; padding: 0.75rem 1.5rem; border-radius: 5px; cursor: pointer; font-size: 1rem; } button:hover { background: #0056b3; } #preview { margin-top: 1rem; } #preview-image { max-width: 100%; border-radius: 5px; } // script.js document.getElementById('image-input').addEventListener('change', function (event) { const file = event.target.files[0]; const reader = new FileReader(); reader.onload = function (e) { const previewImage = document.getElementById('preview-image'); previewImage.src = e.target.result; previewImage.style.display = 'block'; }; reader.readAsDataURL(file); }); document.getElementById('converter-form').addEventListener('submit', function (event) { event.preventDefault(); const fileInput = document.getElementById('image-input'); const format = document.getElementById('format-select').value; if (fileInput.files.length === 0) { alert('Please select an image file.'); return; } const file = fileInput.files[0]; const reader = new FileReader(); reader.onload = function (e) { const image = new Image(); image.src = e.target.result; image.onload = function () { const canvas = document.createElement('canvas'); canvas.width = image.width; canvas.height = image.height; const ctx = canvas.getContext('2d'); ctx.drawImage(image, 0, 0); canvas.toBlob(function (blob) { const link = document.createElement('a'); link.download = `converted-image.${format}`; link.href = URL.createObjectURL(blob); link.click(); }, `image/${format}`, 1); }; }; reader.readAsDataURL(file); });