LazyTools Header
Image Compressor — Target File Size, | LazyTools
Image Tool

Image Compressor — Target File Size & Side-by-Side Preview

Compress JPG, PNG and WebP images directly in your browser — nothing is uploaded to any server. Furthermore, a unique target file size input lets you specify a maximum output size in kilobytes — the tool auto-adjusts quality to hit the target. Choose between quality slider mode and target size mode, then preview before and after side by side.

Target file size mode (unique)Before/after side-by-sideJPG / PNG / WebP100% browser — no server uploadQuality 1–100 slider
🗜️
Drop image here or click to upload
JPG, PNG, WebP — processed in your browser

How to use the Image Compressor

1

Drop or click to upload your image

Drag your JPG, PNG or WebP image onto the drop zone or click to open a file picker. Furthermore, the image loads directly into your browser — no file is sent to any server. The original image dimensions and file size appear in the stats strip.

2

Choose quality slider or target file size

In Quality mode, drag the slider to set compression quality from 1 to 100. Furthermore, in Target File Size mode, enter the maximum kilobyte size you need — for example 200 KB for a web hero image — and click Auto-compress to target. The tool uses binary search to find the quality level that hits the target.

3

Preview side by side and download

The before and after canvases show the original and compressed images simultaneously. Furthermore, the stats strip shows original size, compressed size and percentage reduction. Click Download to save the compressed file.

Quality slider versus target file size mode

Quality slider mode gives direct control over the compression level. Furthermore, it suits users who understand the quality-size trade-off and want predictable, repeatable settings for a workflow. Target file size mode suits a different use case — when the output must meet a specific limit regardless of the visual quality result. Moreover, a web hosting platform with a 300 KB image limit or an email service with a 500 KB attachment limit both require target file size control rather than manual quality adjustment.

ModeInputBest forOutput quality
Quality slider1–100 quality %Creative control, workflow consistencyPredictable by input
Target file sizeMaximum KBUpload limits, email size, web specsAuto-adjusted to fit

Output format comparison

JPG compresses photographs efficiently but discards detail using lossy compression. Furthermore, PNG uses lossless compression — file sizes are larger but no detail is lost. WebP offers better compression than JPG at equivalent quality in most cases. Moreover, WebP is supported by all modern browsers and produces 25–35% smaller files than JPG at the same perceived quality.

How target file size compression works

The target size algorithm uses binary search to find the quality level that produces output closest to the target. Furthermore, it tries a mid-point quality, checks the result size and narrows the search range until the output is within 2% of the target.

lo=0.05; hi=1.0; q=(lo+hi)/2; repeat 16 iterations
if output > target: hi = q (quality too high → reduce)
if output < target: lo = q (quality too low → increase)
Convergence: within ±2% of target in 12–16 iterations
Size estimate: base64 data URL length × 0.75 ≈ byte count

Worked example: compressing a hero image to 200 KB

A web developer has a 1.8 MB photograph to use as a website hero image. Their hosting platform limits images to 200 KB for performance. Using target file size mode:

SettingValue
ModeTarget file size
Target200 KB
FormatWebP
The tool converges on a quality setting of 67% after 14 iterations, producing a 197 KB WebP — within 2% of the 200 KB target. Furthermore, the before/after side-by-side shows no visible quality difference at the target size. Moreover, the 89% file size reduction from 1.8 MB to 197 KB dramatically improves page load speed without requiring manual quality guessing.

What is image compression?

Image compression reduces the file size of an image by removing or encoding redundant data. Furthermore, lossy compression — used by JPG and WebP — permanently discards some image data to achieve smaller sizes. The human eye tolerates moderate quality reduction without noticing a difference. Moreover, lossless compression — used by PNG — encodes the data more efficiently without discarding any information. The choice depends on whether preserving every pixel detail matters for the specific use case.

Web performance guidelines recommend keeping page images under specific size thresholds. Furthermore, Google's Core Web Vitals metrics — Largest Contentful Paint in particular — are directly affected by image file sizes. A 2 MB hero image delays the LCP score significantly. Moreover, image compression is the single highest-impact optimisation for most web pages. Studies show that images account for over 60% of average page weight across the web.

Lossy versus lossless compression

Lossy compression removes visual data that the human visual system is least sensitive to — typically high-frequency detail in smooth areas. Furthermore, the compression artefacts from lossy compression are most visible in areas of sharp colour transitions and text overlaid on images. Lossless compression uses techniques like run-length encoding and Huffman coding to represent the same pixel data in fewer bytes. Moreover, photographs compress best with lossy methods, while screenshots and diagrams with sharp edges often compress better with lossless PNG.

Why browser-based compression protects privacy

Server-based image tools upload your image to an external service for processing. Furthermore, this creates privacy concerns for images containing personal content — family photos, ID documents and internal business materials. Browser-based compression processes images entirely within your browser — the file never leaves your device. Moreover, this approach removes the latency of uploading a large file to a server and waiting for a response. The compression result is instantaneous regardless of internet connection speed.

Core Web Vitals and image optimisation

Google's Core Web Vitals scoring penalises pages with large image payloads. Furthermore, the Largest Contentful Paint element — usually the hero image — should load within 2.5 seconds for a "Good" score. A 2 MB uncompressed hero image on a typical mobile connection takes 4–6 seconds to load. Moreover, compressing the same image to under 200 KB reduces load time to under 1 second — moving the page from "Poor" to "Good" on the LCP metric without any code changes.

Frequently asked questions

No — the entire compression process runs inside your browser using the HTML5 Canvas API. Furthermore, your image data never leaves your device. No file is transmitted to any server at any point. Moreover, this means the tool works without an internet connection after the page has loaded, and there are no privacy concerns about image content being stored or processed externally.
A quality setting of 75–85% produces visually lossless results for most photographs at significantly reduced file sizes. Furthermore, quality settings below 60% introduce visible compression artefacts in areas of fine detail and sharp colour edges. For purely decorative background images, 60–70% quality is often acceptable. Moreover, the before/after preview in this tool makes it easy to find the lowest quality setting that still looks acceptable for the specific image.
PNG uses lossless compression — it cannot reduce file size by discarding data. Furthermore, the Canvas API's PNG output may sometimes be slightly larger than an optimised PNG created with dedicated tools like pngquant. For photographs, always use JPG or WebP instead of PNG — the file size difference is dramatic. Moreover, PNG is most appropriate for images with transparency, sharp edges or text overlays where lossy compression would produce visible artefacts.
The tool handles any image size that fits in browser memory. Furthermore, most modern devices can process images up to 25–50 megapixels without issues. Very large images — panoramas or high-resolution camera raw exports — may cause slow processing on lower-memory devices. Moreover, the Canvas API approach is limited by the available device memory rather than any artificial tool limit.
Target file size mode uses binary search to find the quality level that produces output closest to the specified kilobyte target. Furthermore, it starts at the midpoint between minimum and maximum quality, tests the output size and repeatedly narrows the range until the result is within 2% of the target. The algorithm converges in 12–16 iterations in under one second. Moreover, the quality slider shows the final quality value after convergence — so you can fine-tune manually if needed.

Related tools

Image Resizer & Cropper

Resize to exact pixels or percentage. Furthermore, social media preset sizes are built in.

Image Format Converter

Convert between JPG, PNG, WebP and AVIF. Furthermore, all conversion is browser-native.

Metadata Remover

Strip EXIF data before compressing. Furthermore, shows exactly what metadata was removed.

Image Filters

Apply 10 filters with intensity sliders. Furthermore, before/after split view shows changes live.

Image to PDF

Convert compressed images to PDF. Furthermore, multiple images combine into one PDF file.

Favicon Generator

Generate favicons from any image. Furthermore, multi-size ICO output is included.

Rate this tool

4.6
out of 5
379 ratings
5 ★
70%
4 ★
24%
3 ★
4%
2 ★
2%
1 ★
1%
How useful was this tool?