Image Resizer

#image-resizer { max-width: 950px; margin: 20px auto; padding: 25px; background: #f5f7fb; border-radius: 15px; font-family: Arial, sans-serif; color: #222; box-sizing: border-box; } #image-resizer * { box-sizing: border-box; } #image-resizer .tool-title { text-align: center; font-size: 27px; font-weight: 700; margin-bottom: 10px; color: #172554; } #image-resizer .tool-desc { text-align: center; color: #64748b; margin-bottom: 22px; } #image-resizer .upload-area { border: 2px dashed #2563eb; border-radius: 12px; padding: 30px 15px; text-align: center; background: white; margin-bottom: 22px; } #image-resizer input[type=file] { max-width: 100%; margin-top: 12px; } #image-resizer .section-title { font-size: 19px; font-weight: bold; margin: 22px 0 12px; color: #172554; } #image-resizer .button-grid { display: grid; grid-template-columns: repeat(auto-fit,minmax(95px,1fr)); gap: 10px; } #image-resizer button { border: none; border-radius: 8px; padding: 13px 9px; background: #2563eb; color: white; font-size: 14px; font-weight: bold; cursor: pointer; transition: .2s; } #image-resizer button:hover { background: #1d4ed8; transform: translateY(-2px); } #image-resizer button:disabled { opacity: .5; cursor: not-allowed; transform: none; } #image-resizer .preset-btn { background: #0f766e; } #image-resizer .preset-btn:hover { background: #115e59; } #image-resizer .preview-box { background: white; border-radius: 12px; padding: 15px; margin-top: 22px; text-align: center; display: none; } #image-resizer .preview-box img { max-width: 100%; max-height: 350px; object-fit: contain; border-radius: 8px; margin: 10px auto; } #image-resizer .result-info { line-height: 1.8; color: #334155; overflow-wrap: anywhere; } #image-resizer .download-btn { display: inline-block; margin-top: 12px; padding: 13px 25px; background: #16a34a; color: white; text-decoration: none; border-radius: 8px; font-weight: bold; } #image-resizer .download-btn:hover { background: #15803d; } #image-resizer .status { text-align: center; margin: 15px 0; font-weight: bold; color: #2563eb; } #image-resizer .note { font-size: 13px; color: #64748b; margin-top: 18px; line-height: 1.6; } @media(max-width:500px) { #image-resizer { padding: 15px; } #image-resizer .tool-title { font-size: 22px; } }
Image Resizer Online
Resize and compress your images to your required size.
Upload Your Image

Select an image from your device

Resize Image by KB
Social Media Image Resizer

Resized Image Preview

Resized image preview
Download Image
Note: Images are processed in your browser. KB options represent maximum file sizes. JPEG format is used for compressed downloads. Transparent areas in uploaded images will have a white background.
(function () { const root = document.getElementById("image-resizer"); const fileInput = root.querySelector("#ir-file"); const status = root.querySelector("#ir-status"); const preview = root.querySelector("#ir-preview"); const resultImg = root.querySelector("#ir-result-img"); const info = root.querySelector("#ir-info"); const download = root.querySelector("#ir-download"); let originalImage = null; let originalName = "image"; function setBusy(busy, message) { root.querySelectorAll("button").forEach(btn => { btn.disabled = busy; }); status.textContent = message || ""; } fileInput.addEventListener("change", function () { const file = this.files[0]; if (!file) return; if (!file.type.startsWith("image/")) { status.textContent = "Please select a valid image."; return; } const reader = new FileReader(); reader.onload = function (event) { const img = new Image(); img.onload = function () { originalImage = img; originalName = file.name.replace(/\.[^.]+$/, "") || "image"; status.textContent = "Image uploaded successfully: " + img.width + " × " + img.height + " pixels"; preview.style.display = "none"; }; img.onerror = function () { status.textContent = "Unable to read this image."; }; img.src = event.target.result; }; reader.onerror = function () { status.textContent = "Unable to load the selected file."; }; reader.readAsDataURL(file); }); function makeCanvas(width, height) { const canvas = document.createElement("canvas"); canvas.width = Math.max(1, Math.round(width)); canvas.height = Math.max(1, Math.round(height)); const ctx = canvas.getContext("2d"); ctx.fillStyle = "#ffffff"; ctx.fillRect(0, 0, canvas.width, canvas.height); ctx.drawImage(originalImage, 0, 0, canvas.width, canvas.height); return canvas; } function toBlob(canvas, quality) { return new Promise(resolve => { canvas.toBlob(resolve, "image/jpeg", quality); }); } // Find the highest JPEG quality that stays under the target. async function compressToLimit(width, height, maxBytes) { for (let attempt = 0; attempt < 35; attempt++) { const canvas = makeCanvas(width, height); let low = 0.01; let high = 0.95; let bestBlob = null; for (let i = 0; i < 12; i++) { const quality = (low + high) / 2; const blob = await toBlob(canvas, quality); if (!blob) throw new Error("Image compression failed."); if (blob.size <= maxBytes) { bestBlob = blob; low = quality; } else { high = quality; } } if (bestBlob) return bestBlob; // If quality alone is insufficient, reduce dimensions. width *= 0.82; height *= 0.82; if (width < 1 || height targetRatio) { sw = originalImage.height * targetRatio; sx = (originalImage.width - sw) / 2; } else { sh = originalImage.width / targetRatio; sy = (originalImage.height - sh) / 2; } const canvas = document.createElement("canvas"); canvas.width = width; canvas.height = height; const ctx = canvas.getContext("2d"); ctx.drawImage( originalImage, sx, sy, sw, sh, 0, 0, width, height ); const blob = await toBlob(canvas, 0.90); if (!blob) throw new Error("Image processing failed."); showResult(blob, name + " (" + width + " × " + height + ")"); } catch (error) { status.textContent = error.message; } finally { setBusy(false, status.textContent); } } function showResult(blob, description) { const url = URL.createObjectURL(blob); if (resultImg.dataset.previousUrl) { URL.revokeObjectURL(resultImg.dataset.previousUrl); } resultImg.src = url; resultImg.dataset.previousUrl = url; const sizeKB = (blob.size / 1024).toFixed(2); info.innerHTML = "Operation: " + description + "
Final File Size: " + sizeKB + " KB" + "
Image Dimensions: " + resultImg.naturalWidth + " × " + resultImg.naturalHeight + "
Format: JPG"; download.href = url; download.download = originalName + "-resized.jpg"; preview.style.display = "block"; status.textContent = "Your image is ready to download."; } root.querySelectorAll("[data-kb]").forEach(button => { button.addEventListener("click", function () { resizeKB(Number(this.dataset.kb)); }); }); root.querySelector('[data-preset="youtube"]') .addEventListener("click", function () { resizePreset(1280, 720, "YouTube Thumbnail"); }); root.querySelector('[data-preset="instagram"]') .addEventListener("click", function () { resizePreset(1080, 1080, "Instagram Post"); }); })();
Scroll to Top