File Converter & Media Processor

Convert, compress, and transform your files — all in your browser

📁
Drop a file here or click to browse Supports images, audio, video, documents, and more
File: -
Size: -
Type: -
Processed file ready
-

Quick Actions

Super generates helpful tools and automates fact-checking across the internet proactively. If you enjoyed this tool, build your own with Super and share it with a friend.
'; } else if (targetMime === 'application/json') { try { converted = JSON.stringify(JSON.parse(text), null, 2); } catch(e) { converted = text; } } else if (targetMime === 'text/csv') { // Simple CSV conversion from JSON try { const obj = JSON.parse(text); if (Array.isArray(obj) && obj.length) { const headers = Object.keys(obj[0]); const rows = obj.map(item => headers.map(h => JSON.stringify(item[h] || '')).join(',')); converted = headers.join(',') + '\n' + rows.join('\n'); } } catch(e) { converted = text; } } const blob = new Blob([converted], { type: targetMime }); return { blob, name: baseName + '.' + ext }; } // Fallback: return original const blob = file.slice(0, file.size, targetMime); return { blob, name: baseName + '.' + ext }; } function loadImage(file) { return new Promise((resolve, reject) => { const img = new Image(); img.onload = () => resolve(img); img.onerror = reject; img.src = URL.createObjectURL(file); }); } function audioBufferToWav(buffer) { const numChannels = buffer.numberOfChannels; const sampleRate = buffer.sampleRate; const format = 1; // PCM const bitDepth = 16; let samples = []; for (let channel = 0; channel < numChannels; channel++) { samples.push(buffer.getChannelData(channel)); } const dataLength = samples[0].length * numChannels * (bitDepth / 8); const headerLength = 44; const totalLength = headerLength + dataLength; const arrayBuffer = new ArrayBuffer(totalLength); const view = new DataView(arrayBuffer); // WAV header writeString(view, 0, 'RIFF'); view.setUint32(4, totalLength - 8, true); writeString(view, 8, 'WAVE'); writeString(view, 12, 'fmt '); view.setUint32(16, 16, true); view.setUint16(20, format, true); view.setUint16(22, numChannels, true); view.setUint32(24, sampleRate, true); view.setUint32(28, sampleRate * numChannels * (bitDepth / 8), true); view.setUint16(32, numChannels * (bitDepth / 8), true); view.setUint16(34, bitDepth, true); writeString(view, 36, 'data'); view.setUint32(40, dataLength, true); // Write samples let offset = 44; for (let i = 0; i < samples[0].length; i++) { for (let channel = 0; channel < numChannels; channel++) { const sample = Math.max(-1, Math.min(1, samples[channel][i])); const intSample = sample < 0 ? sample * 0x8000 : sample * 0x7FFF; view.setInt16(offset, intSample, true); offset += 2; } } return new Blob([arrayBuffer], { type: 'audio/wav' }); } function writeString(view, offset, string) { for (let i = 0; i < string.length; i++) { view.setUint8(offset + i, string.charCodeAt(i)); } } function getExtension(mime) { const map = { 'image/png': 'png', 'image/jpeg': 'jpg', 'image/webp': 'webp', 'image/gif': 'gif', 'image/bmp': 'bmp', 'image/svg+xml': 'svg', 'audio/mp3': 'mp3', 'audio/wav': 'wav', 'audio/ogg': 'ogg', 'audio/aac': 'aac', 'audio/flac': 'flac', 'video/mp4': 'mp4', 'video/webm': 'webm', 'video/ogg': 'ogv', 'video/avi': 'avi', 'application/pdf': 'pdf', 'text/plain': 'txt', 'text/html': 'html', 'application/json': 'json', 'text/csv': 'csv' }; return map[mime] || 'bin'; } function escapeHtml(text) { const div = document.createElement('div'); div.textContent = text; return div.innerHTML; } function showPreview(blob, mime) { previewContainer.innerHTML = ''; const url = URL.createObjectURL(blob); if (mime.startsWith('image/')) { const img = document.createElement('img'); img.src = url; previewContainer.appendChild(img); } else if (mime.startsWith('audio/')) { const audio = document.createElement('audio'); audio.controls = true; audio.src = url; audio.style.width = '100%'; previewContainer.appendChild(audio); } else if (mime.startsWith('video/')) { const video = document.createElement('video'); video.controls = true; video.src = url; video.style.width = '100%'; previewContainer.appendChild(video); } else if (mime === 'text/html') { const iframe = document.createElement('iframe'); iframe.src = url; iframe.style.width = '100%'; iframe.style.height = '300px'; iframe.style.border = 'none'; iframe.style.borderRadius = '8px'; previewContainer.appendChild(iframe); } else { previewContainer.innerHTML = '

Preview not available for this file type

'; } } downloadBtn.addEventListener('click', () => { if (!processedBlob) return; const url = URL.createObjectURL(processedBlob); const a = document.createElement('a'); a.href = url; a.download = processedFileName; a.click(); URL.revokeObjectURL(url); }); shareBtn.addEventListener('click', async () => { if (!processedBlob) return; if (navigator.share) { try { const file = new File([processedBlob], processedFileName, { type: processedBlob.type }); await navigator.share({ files: [file], title: 'Converted file' }); } catch (err) { if (err.name !== 'AbortError') { fallbackShare(); } } } else { fallbackShare(); } }); function fallbackShare() { const url = URL.createObjectURL(processedBlob); const shareData = { title: 'File Converter Result', text: 'Check out this converted file: ' + processedFileName, url: url }; // Copy to clipboard navigator.clipboard.writeText(processedFileName + ' - ' + url).then(() => { alert('File URL copied to clipboard! Share it with others.'); }).catch(() => { prompt('Copy this link to share:', url); }); } resetBtn.addEventListener('click', () => { currentFile = null; processedBlob = null; processedFileName = ''; fileInput.value = ''; fileInfo.classList.remove('show'); dropZone.classList.remove('has-file'); processBtn.disabled = true; resultArea.classList.remove('show'); progressBar.classList.remove('show'); previewContainer.innerHTML = ''; }); // Sample files for testing function loadSample(type) { let content, filename, mime; if (type === 'image') { // Create a simple SVG as sample content = 'Sample Image'; filename = 'sample-image.svg'; mime = 'image/svg+xml'; } else if (type === 'audio') { // Generate a simple WAV tone const sampleRate = 44100; const duration = 2; const numSamples = sampleRate * duration; const buffer = new ArrayBuffer(44 + numSamples * 2); const view = new DataView(buffer); writeString(view, 0, 'RIFF'); view.setUint32(4, 36 + numSamples * 2, true); writeString(view, 8, 'WAVE'); writeString(view, 12, 'fmt '); view.setUint32(16, 16, true); view.setUint16(20, 1, true); view.setUint16(22, 1, true); view.setUint32(24, sampleRate, true); view.setUint32(28, sampleRate * 2, true); view.setUint16(32, 2, true); view.setUint16(34, 16, true); writeString(view, 36, 'data'); view.setUint32(40, numSamples * 2, true); for (let i = 0; i < numSamples; i++) { const t = i / sampleRate; const sample = Math.sin(2 * Math.PI * 440 * t) * 0.5; const intSample = sample * 0x7FFF; view.setInt16(44 + i * 2, intSample, true); } content = new Blob([buffer], { type: 'audio/wav' }); filename = 'sample-tone.wav'; mime = 'audio/wav'; } else { content = 'Hello! This is a sample text file.\nIt can be converted to HTML, JSON, or CSV.\nLine 3: More sample content.'; filename = 'sample-text.txt'; mime = 'text/plain'; } const file = new File([content], filename, { type: mime }); // Set the file input const dt = new DataTransfer(); dt.items.add(file); fileInput.files = dt.files; handleFile(file); }