100% Client-Side · No Upload · Private

Smart Image Compressor
& WebP Converter

Compress, convert, and compare images instantly in your browser. See the difference with live before/after comparison — your files never leave your device.

Advertisement · Top Banner (728x90 / Responsive)

Why Choose Our Compressor?

Built for performance, privacy, and premium results — all running natively in your browser.

100% Private

Your images are processed locally in your browser. Nothing is ever uploaded to a server — total privacy guaranteed.

Lightning Fast

Powered by the Canvas API and native browser optimization. Get results in milliseconds, even for large images.

Live Preview

Watch the compressed output update in real-time as you adjust quality. Compare side-by-side before downloading.

WebP Optimized

Convert to modern WebP format for up to 35% smaller files than JPEG/PNG with no visible quality loss.

All Devices

Fully responsive interface that works flawlessly on desktop, tablet, and mobile — no app install required.

Free Forever

No sign-up, no watermarks, no limits. Compress as many images as you want, completely free of charge.

Frequently Asked Questions

Everything you need to know about the image compressor.

Are my images uploaded to a server?
No. All image processing happens entirely in your browser using the HTML5 Canvas API. Your files never leave your device, ensuring complete privacy and security.
What is the best quality setting?
For most use cases, a quality setting between 70-85% provides an excellent balance between file size and visual quality. For WebP, you can often go as low as 65% with minimal quality loss.
Why should I convert to WebP?
WebP is a modern image format developed by Google that provides superior lossless and lossy compression. WebP files are typically 25-35% smaller than equivalent JPEGs while maintaining the same visual quality, making them ideal for faster websites.
What image formats are supported?
You can upload PNG, JPG/JPEG, WebP, and SVG images. Output formats supported are WebP, JPEG, and PNG. SVG files will be rasterized when converted to other formats.
Sticky Footer Ad (320x50 / 728x90)
// ============================================ // Utility Functions // ============================================ const formatBytes = (bytes) => { if (bytes === 0) return '0 B'; const k = 1024; const sizes = ['B', 'KB', 'MB', 'GB']; const i = Math.floor(Math.log(bytes) / Math.log(k)); return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]; }; const showToast = (message, type = 'info') => { const toast = document.createElement('div'); toast.className = `toast toast-${type}`; toast.textContent = message; el.toastContainer.appendChild(toast); requestAnimationFrame(() => toast.classList.add('show')); setTimeout(() => { toast.classList.remove('show'); setTimeout(() => toast.remove(), 300); }, 3500); }; const debounce = (fn, wait) => { let t; return (...args) => { clearTimeout(t); t = setTimeout(() => fn(...args), wait); }; }; const getExtension = (mime) => { const map = { 'image/webp': 'webp', 'image/jpeg': 'jpg', 'image/png': 'png' }; return map[mime] || 'img'; }; const getFormatLabel = (mime) => { const map = { 'image/webp': 'WEBP', 'image/jpeg': 'JPEG', 'image/png': 'PNG' }; return map[mime] || 'IMG'; }; // ============================================ // File Handling // ============================================ const handleFile = (file) => { if (!file) return; // Validate type if (!file.type.startsWith('image/')) { showToast('Please upload a valid image (PNG, JPG, WebP, or SVG)', 'error'); return; } // Validate size (warn over 20MB but allow) if (file.size > 20 * 1024 * 1024) { showToast('Large file detected — processing may take a moment', 'info'); } state.originalFile = file; state.originalSize = file.size; state.originalType = file.type; const reader = new FileReader(); reader.onload = (e) => { const img = new Image(); img.onload = () => { state.originalImage = img; showResults(); processImage(); }; img.onerror = () => showToast('Failed to load image. Try another file.', 'error'); img.src = e.target.result; }; reader.onerror = () => showToast('Failed to read file', 'error'); reader.readAsDataURL(file); }; const showResults = () => { el.uploadZone.classList.add('hidden'); el.toolResults.hidden = false; el.toolResults.classList.add('fade-in'); // Update file info el.fileName.textContent = state.originalFile.name; let formatName = state.originalType.split('/')[1].toUpperCase().replace('SVG+XML', 'SVG').replace('JPEG', 'JPG'); el.fileMeta.textContent = `${state.originalImage.naturalWidth} × ${state.originalImage.naturalHeight}px · ${formatName}`; el.originalSize.textContent = formatBytes(state.originalSize); // Set before image el.beforeImg.src = state.originalImage.src; // Scroll into view smoothly setTimeout(() => { el.toolResults.scrollIntoView({ behavior: 'smooth', block: 'start' }); }, 100); }; // ============================================ // Image Processing (Canvas-based) // ============================================ const processImage = () => { if (!state.originalImage) return; state.isProcessing = true; el.processingIndicator.classList.add('active'); // Use requestAnimationFrame to allow UI update requestAnimationFrame(() => { try { const canvas = document.createElement('canvas'); const img = state.originalImage; let width = img.naturalWidth || img.width; let height = img.naturalHeight || img.height; // Cap maximum dimensions for performance const maxDim = 4096; if (width > maxDim || height > maxDim) { const ratio = Math.min(maxDim / width, maxDim / height); width = Math.floor(width * ratio); height = Math.floor(height * ratio); } canvas.width = Math.max(1, width); canvas.height = Math.max(1, height); const ctx = canvas.getContext('2d'); // Fill white background for JPEG (no alpha channel support) if (state.outputFormat === 'image/jpeg') { ctx.fillStyle = '#ffffff'; ctx.fillRect(0, 0, canvas.width, canvas.height); } // Use high quality smoothing ctx.imageSmoothingEnabled = true; ctx.imageSmoothingQuality = 'high'; ctx.drawImage(img, 0, 0, canvas.width, canvas.height); canvas.toBlob((blob) => { if (!blob) { showToast('Compression failed. Try a different format.', 'error'); state.isProcessing = false; el.processingIndicator.classList.remove('active'); return; } // Revoke previous URL to prevent memory leaks if (state.compressedUrl) { URL.revokeObjectURL(state.compressedUrl); } state.compressedBlob = blob; state.compressedUrl = URL.createObjectURL(blob); // Update UI el.compressedSize.textContent = formatBytes(blob.size); // Re-append indicator if it was removed if (!el.compressedSize.querySelector('.processing-indicator')) { el.compressedSize.appendChild(el.processingIndicator); } const savingsPercent = ((state.originalSize - blob.size) / state.originalSize) * 100; if (savingsPercent >= 0) { el.savings.textContent = `−${savingsPercent.toFixed(1)}%`; el.savings.classList.remove('negative'); } else { el.savings.textContent = `+${Math.abs(savingsPercent).toFixed(1)}%`; el.savings.classList.add('negative'); } // Update after image el.afterImg.src = state.compressedUrl; // Update download info const ext = getExtension(state.outputFormat); const originalName = state.originalFile.name.replace(/\.[^/.]+$/, ''); el.downloadInfo.textContent = `${originalName}_compressed.${ext} · ${formatBytes(blob.size)}`; // Update format badge el.formatBadge.textContent = getFormatLabel(state.outputFormat); state.isProcessing = false; el.processingIndicator.classList.remove('active'); }, state.outputFormat, state.quality / 100); } catch (err) { console.error('Processing error:', err); showToast('An error occurred during processing', 'error'); state.isProcessing = false; el.processingIndicator.classList.remove('active'); } }); }; const debouncedProcess = debounce(processImage, 200); // ============================================ // Before/After Comparison Slider // ============================================ let isDragging = false; const updateSliderPosition = (clientX) => { const rect = el.comparison.getBoundingClientRect(); let x = clientX - rect.left; x = Math.max(0, Math.min(rect.width, x)); const percent = (x / rect.width) * 100; el.comparisonHandle.style.left = percent + '%'; el.afterWrap.style.clipPath = `inset(0 0 0 ${percent}%)`; }; // Mouse events (Desktop) el.comparison.addEventListener('mousedown', (e) => { isDragging = true; updateSliderPosition(e.clientX); e.preventDefault(); }); window.addEventListener('mousemove', (e) => { if (isDragging) updateSliderPosition(e.clientX); }); window.addEventListener('mouseup', () => { isDragging = false; }); // Touch events (Mobile) el.comparison.addEventListener('touchstart', (e) => { isDragging = true; updateSliderPosition(e.touches[0].clientX); }, { passive: true }); window.addEventListener('touchmove', (e) => { if (isDragging) { // We don't prevent default here because CSS 'touch-action: none' handles it updateSliderPosition(e.touches[0].clientX); } }, { passive: true }); window.addEventListener('touchend', () => { isDragging = false; }); // Initialize slider at 50% const initSlider = () => { const rect = el.comparison.getBoundingClientRect(); if (rect.width > 0) { updateSliderPosition(rect.left + rect.width / 2); } }; // ============================================ // Range Slider Visual Fill // ============================================ const updateRangeFill = () => { const value = el.qualitySlider.value; const percent = (value / 100) * 100; el.qualitySlider.style.backgroundSize = `${percent}% 100%`; }; // ============================================ // Download Functionality // ============================================ const downloadImage = () => { if (!state.compressedBlob) { showToast('Please wait for processing to complete', 'error'); return; } const ext = getExtension(state.outputFormat); const originalName = state.originalFile.name.replace(/\.[^/.]+$/, ''); const filename = `${originalName}_compressed.${ext}`; const url = URL.createObjectURL(state.compressedBlob); const a = document.createElement('a'); a.href = url; a.download = filename; document.body.appendChild(a); a.click(); document.body.removeChild(a); setTimeout(() => URL.revokeObjectURL(url), 1000); showToast(`Downloaded: ${filename}`, 'success'); }; // ============================================ // Reset Tool // ============================================ const resetTool = () => { if (state.compressedUrl) { URL.revokeObjectURL(state.compressedUrl); } state.originalImage = null; state.originalFile = null; state.compressedBlob = null; state.compressedUrl = null; state.originalSize = 0; el.toolResults.hidden = true; el.uploadZone.classList.remove('hidden'); el.fileInput.value = ''; el.beforeImg.src = ''; el.afterImg.src = ''; // Reset quality and format to defaults el.qualitySlider.value = 80; state.quality = 80; el.qualityValue.textContent = '80%'; el.formatSelect.value = 'image/webp'; state.outputFormat = 'image/webp'; updateRangeFill(); window.scrollTo({ top: 0, behavior: 'smooth' }); }; // ============================================ // Event Listeners // ============================================ // File input change (Works for both label click and direct interaction) el.fileInput.addEventListener('change', (e) => { if (e.target.files && e.target.files[0]) { handleFile(e.target.files[0]); } }); // Drag and drop (Desktop only, but harmless on mobile) ['dragenter', 'dragover'].forEach(evt => { el.uploadZone.addEventListener(evt, (e) => { e.preventDefault(); e.stopPropagation(); el.uploadZone.classList.add('drag-active'); }); }); ['dragleave', 'drop'].forEach(evt => { el.uploadZone.addEventListener(evt, (e) => { e.preventDefault(); e.stopPropagation(); if (evt === 'dragleave' && e.target !== el.uploadZone) return; el.uploadZone.classList.remove('drag-active'); }); }); el.uploadZone.addEventListener('drop', (e) => { e.preventDefault(); const file = e.dataTransfer.files[0]; if (file) handleFile(file); }); // Prevent default browser behavior on drop anywhere ['dragover', 'drop'].forEach(evt => { window.addEventListener(evt, (e) => e.preventDefault()); }); // Quality slider el.qualitySlider.addEventListener('input', (e) => { state.quality = parseInt(e.target.value, 10); el.qualityValue.textContent = state.quality + '%'; updateRangeFill(); debouncedProcess(); }); // Format select el.formatSelect.addEventListener('change', (e) => { state.outputFormat = e.target.value; debouncedProcess(); }); // Download button el.downloadBtn.addEventListener('click', downloadImage); // Reset button el.resetBtn.addEventListener('click', resetTool); // FAQ toggle document.querySelectorAll('.faq-question').forEach(q => { q.addEventListener('click', () => { const item = q.parentElement; const wasActive = item.classList.contains('active'); // Close all document.querySelectorAll('.faq-item').forEach(i => i.classList.remove('active')); // Open clicked if it was closed if (!wasActive) item.classList.add('active'); }); }); // Sticky ad logic let stickyAdShown = false; const showStickyAd = () => { if (stickyAdShown) return; stickyAdShown = true; setTimeout(() => el.stickyAd.classList.add('show'), 1500); }; el.stickyAdClose.addEventListener('click', () => { el.stickyAd.classList.remove('show'); }); // Show sticky ad after scroll let scrollListenerAdded = false; const initScrollListener = () => { if (scrollListenerAdded) return; scrollListenerAdded = true; window.addEventListener('scroll', () => { if (window.scrollY > 600) showStickyAd(); }, { passive: true }); }; // Smooth scroll for nav links document.querySelectorAll('a[href^="#"]').forEach(a => { a.addEventListener('click', (e) => { const target = document.querySelector(a.getAttribute('href')); if (target) { e.preventDefault(); target.scrollIntoView({ behavior: 'smooth' }); } }); }); // Recalculate slider position on resize window.addEventListener('resize', () => { if (!el.toolResults.hidden) { const rect = el.comparison.getBoundingClientRect(); const currentLeft = parseFloat(el.comparisonHandle.style.left) || 50; updateSliderPosition(rect.left + (rect.width * currentLeft / 100)); } }); // ============================================ // Initialize // ============================================ const init = () => { updateRangeFill(); initScrollListener(); // Initialize slider position once tool is visible (in case of pre-loaded state) setTimeout(() => { if (!el.toolResults.hidden) initSlider(); }, 200); }; // Run init when DOM is ready if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', init); } else { init(); } // Initialize slider after image loads const observer = new MutationObserver(() => { if (!el.toolResults.hidden && el.beforeImg.src) { initSlider(); } }); observer.observe(el.toolResults, { attributes: true, attributeFilter: ['hidden'] }); })();