Most web workflows that touch images end up bouncing between three fragile steps: editing a flat graphic you lost the source file for, fixing a typo baked into a poster or screenshot, and squeezing the final PNG/WebP under an upload or Core Web Vitals budget.

When we added a client-side compression tool to Free AI Image Editor, we noticed three recurring bugs in typical "free online image compressors":

  1. Silent server uploads — many tools upload client assets, invoices, or unreleased UI mockups to remote servers just to run basic canvas encoding.
  2. Broken PNG transparency — some compressors quietly convert transparent PNGs into opaque JPEGs or fail to shrink alpha graphics at all.
  3. File size inflation — re-encoding an already optimized PNG or JPEG at a default quality slider often produces a larger file than the original.

Here is how we structured a 100% browser-local compression pipeline—and where local pixel processing ends and layered PSD decomposition begins.

Before and after browser-local image compression comparison

1. Keeping Transparent PNGs Actually Transparent (and Smaller)

Browser <canvas>.toBlob("image/png") only writes full 32-bit lossless PNGs. If you drop a 1.2 MB transparent UI screenshot or logo into a naive canvas compressor, the output is frequently 1.2 MB–1.8 MB—zero savings or even bigger.

To genuinely shrink PNGs locally without stripping transparency:

  • Use true indexed-color quantization (such as UPNG.js) that preserves the full alpha channel instead of flattening onto a white background.
  • Keep a strict "Original kept" guard: compare outputBlob.size against originalFile.size before accepting the result. If the original is already tighter at the chosen format and dimensions, return the original untouched rather than shipping a bloated re-encode.
  • Check byte signatures carefully for modern formats: iPhone HEIC files and AVIF files share ISO BMFF containers (ftyp brands like mif1). Always check AVIF vs. HEIC container brands in the right order before handing off to a local WASM/JS HEIC decoder so AVIF inputs aren't misrouted.

2. Hitting an Exact Max File Size (KB) Without Guessing Sliders

Real-world forms (job portals, app stores, marketplaces, CMS upload caps) rarely ask for "75% quality"—they ask for "under 100 KB" or "under 500 KB".

A naive binary search over quality 1..100 works smoothly for JPEG and WebP, where output size rises monotonically with quality. Lossless/quantized PNGs break that assumption at the top edge (q = 100), so a reliable client-side target-size loop needs three details:

  1. Probe q = 100 first: if the max-quality output already fits inside the KB cap, return immediately—no unnecessary quality loss.
  2. Binary search [1, 99]: find the highest quality that still fits under the byte limit.
  3. Optional dimension fallback ("Shrink dimensions if needed"): if even q = 1 at full resolution (say, a 4000 × 3000 photo targeting 100 KB) exceeds the cap, step down max dimensions cleanly (e.g., up to 4 passes down to a safe floor like 256 px) and re-run the quality search. If the cap is physically unreachable, surface the closest achieved size transparently instead of failing silently.

3. Preventing Browser Tab Crashes on Batch Runs

Mobile Safari and low-RAM laptops crash fast if a user drops 20 high-res photos and the app decodes all 20 bitmaps concurrently.

Two simple rules keep batch compression rock-solid:

  • Cap concurrency to 2 active jobs across batches via a shared coordinator queue, invalidating stale jobs immediately when a user drags a slider.
  • Revoke blob: object URLs deterministically after React/DOM commits, and package batch downloads locally with fflate into a single ZIP without ever touching a backend server.

Honest Limits of Browser-Local Compression

Local browser execution isn't magic—it comes with clear boundaries worth knowing upfront:

  • Browser decode ceilings: Canvas implementations cap total pixels (typically around 100 MP or 30,000 px on one edge).
  • EXIF stripping on re-encode: Canvas re-encoding strips camera EXIF metadata (which is actually good for privacy, though photographers who need embedded EXIF should keep originals).
  • No semantic edits: Local encoders can resize and quantize pixels, but they cannot change printed copy or separate foreground objects from a flat background.

You can test the full zero-upload pipeline (including interactive 1x/2x/4x split-screen comparison and batch ZIP export) directly in your browser on Free AI Image Compressor.

4. When You Need to Edit Before You Compress

In practice, compression is the last mile of an asset workflow. When someone hands you a flat PNG or JPG poster that needs changes before shipping to web, we split the upstream work by how much structural change is needed:

Flat graphic split into 3D editable Photoshop layers

  • Quick typo or price/date update on flat graphics: Start with Edit Text in Image—client-side OCR locates printed text so you can edit copy, font style, and sampled ink colors locally for free, with an optional AI Style Match pass when lighting or warped perspectives need seamless blending.
  • Moving objects, hiding elements, or handing off to Photoshop: Run the flat graphic through Image to PSD to separate foreground objects, reconstruct the background, reorder layers via drag-and-drop, and export a layered .psd (or layer PNG ZIP) with native editable text layers.
  • Targeted object swaps or background cleanups: Use prompt-based local repainting and numbered region marks on the main Free AI Image Editor canvas (no sign-up or watermark for daily free standard edits).

Once the graphic itself is right, a 2-second pass through the local Image Compressor brings a 4 MB PNG down to a clean ~120 KB WebP or quantized transparent PNG—ready to deploy without leaking unpublished assets to a random upload server.