Dev.to WebDev πŸ›  Dev πŸ‘ 0 πŸ“– 3 min read

Why I Built a Client-Side Image Compressor with Binary-Search Target Sizing and QR Transfer

Every developer runs into the same friction when optimizing images for web apps, GitHub READMEs, or strict upload forms: most online image compressors force you to upload your raw files to an unknown third-party server b

Every developer runs into the same friction when optimizing images for web apps, GitHub READMEs, or strict upload forms: most online image compressors force you to upload your raw files to an unknown third-party server before processing them.

Not only does uploading multi-megabyte screenshots waste bandwidth and add latency, it also raises privacy concerns when you are dealing with internal dashboards, staging builds, or personal documents.

To solve this for my own daily workflow, I built the Photo2URL Image Compressorβ€”a zero-upload, browser-native compression utility designed for speed, exact file size targets, and seamless cross-device transfers.

Here is a breakdown of the engineering choices behind it and how it works under the hood.

1. 100% Client-Side Processing (Zero Server Uploads)

Instead of streaming user files to a backend worker, the entire compression pipeline runs locally inside your browser tab using standard Web APIs (Canvas, createImageBitmap, and toBlob()).

  • Instant Feedback: Because there is no network round-trip for the raw file, compressing a 5 MB PNG into a lightweight WebP or JPEG takes milliseconds.
  • Privacy by Default: Your images never leave your device's memory during compression. You can even disconnect your Wi-Fi after loading the page and keep compressing files offline.
  • Visual Before/After Inspection: You can inspect compression artifacts side-by-side before downloading, ensuring text in UI screenshots stays crisp.

2. Automated Binary Search for Exact Target File Sizes

One of the most annoying parts of traditional compressors is guessing the quality slider:

"Set quality to 75% β†’ Still 2.4 MB β†’ Drag slider to 62% β†’ Now it's 1.7 MB β†’ Drag to 68%..."

Many platforms (like Discord, GitHub, CMS fields, or government portals) enforce hard file size capsβ€”such as under 500 KB or under 3 MB.

Instead of manual trial and error, this online image compressor lets you type in a Target Size (KB/MB). Under the hood, it runs a lightweight binary search across quality parameters, iteratively encoding and measuring blob byte lengths until it finds the highest visual quality that stays safely below your exact size ceiling.

3. Cross-Device QR Code Relay (Desktop to Phone)

A surprisingly common workflow bottleneck happens when you edit or compress an image on your desktop, but need it on your phone to post on mobile-first apps or messaging threads.

Normally, that means emailing the file to yourself or cluttering a chat app. To eliminate that friction, I added an optional QR Code Transfer feature:

  1. Compress your image locally in your desktop browser.
  2. Click to generate a temporary QR relay link if you need it on mobile.
  3. Scan the QR code with your phone's camera to download the optimized image immediately.

(Note: Local compression requires zero network transfers; the temporary cloud relay is strictly opt-in when you want to bridge desktop-to-mobile devices.)

Honest Limitations & Trade-Offs

In the spirit of transparent engineering, browser-native compression isn't a silver bullet for every edge case:

  • Browser Codec Constraints: Relying on native browser encoders means output efficiency can vary slightly between Chromium, Firefox, and Safariβ€”especially for advanced AVIF or progressive JPEG tuning compared to heavy server-side libvips or mozjpeg pipelines.
  • Memory Ceilings on Massive Files: Processing ultra-high-resolution RAW exports (e.g., 50+ megapixel images) inside a single browser tab is bound by client device RAM.
  • Best Fit: It is built for fast everyday developer assets, UI screenshots, blog visuals, and social media graphics rather than batch-processing thousands of studio photos at once.

Try It Out & Share Feedback

If you want a fast, privacy-first way to shrink assets without touching a terminal or waiting on server queues, give **[Photo2URL's free image compressor](

πŸ“° Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.