AI • Science • Technology • Future

Side Projects

Local File Conversion in Browser

Image from the original article
Featured image: original publisher image. Via original publisher.

A team at MetalDevs built a tool that converts image and PDF files directly in the browser, without sending data to any server. This project shows how modern web APIs—like Web Workers, OffscreenCanvas, and WebAssembly—can create powerful, privacy-first tools that run entirely on the user’s device. Source: dev.to.

What Happened

A few months ago, our team at MetalDevs needed to convert about thirty .heic photos from an iPhone to JPEGs and shrink a scanned PDF under 2 MB for an online form. Every tool on the first page of Google either capped us at three files, made us wait on a slow upload bar, or wanted an email signup.

It felt ridiculous. Modern laptops sit right in front of us with 16 GB of RAM and multi-core CPUs, yet we were uploading private documents to some random Linux container just to run basic image compression. So we decided to build the whole thing to run locally inside the browser tab. No S3 buckets, no backend queues, no file limits. Just Web Workers, OffscreenCanvas, and a couple of WebAssembly modules.

How It Works

Getting a basic proof-of-concept working took an afternoon. Making it not crash on real-world batches of 50+ high-res photos took way longer. Here is what actually worked and where things broke.

Moving pixels off the main thread (and why bitmap.close() saved us)

Our first version ran on the main thread. After five minutes, it froze when we added ten 4000×3000 photos. The UI stayed locked until the loop finished.

We moved the work into a Web Worker using OffscreenCanvas and createImageBitmap(). The file decodes directly in the worker, not through raw pixel arrays.

  1. Decode the file into a bitmap in the worker’s context.
  2. Calculate a scaling ratio based on target width or keep original aspect ratio.
  3. Render the resized image on an OffscreenCanvas with high-quality smoothing.
  4. Convert the canvas output to a blob with chosen format and quality.

Crucially, we call bitmap.close() right after drawing. That call seems small—but skipping it caused major issues. Chrome’s garbage collector doesn’t always free GPU memory fast enough during heavy batches. On older devices or phones, the tab would silently crash mid-process. Closing the bitmap immediately keeps memory use stable.

Hitting exact KB limits without guessing quality sliders

Most image tools offer a 1–100 quality slider. Users don’t want to guess. They don’t want to export at 75%, check Finder, see 240 KB, go back, adjust to 62%, and re-export just to meet a 200 KB limit.

File sizes don’t scale linearly with quality. A noisy photo of trees compresses very differently than a clean UI screenshot. No math formula can predict the right setting.

We built a binary search inside the worker. It tests convertToBlob() until it finds a size under the user’s limit.

Image from the original article
original publisher image. Via original publisher. · Source
  1. Start with quality between 0.05 and 0.95.
  2. Test the middle value and check the output size.
  3. If the size is too big, reduce the high end. If too small, reduce the low end.

One edge case: a 15 MB photo asked for 50 KB. Even at 0.05 quality, it wouldn’t shrink enough. When no valid result is found, the worker reduces canvas size by 10% and tries again. This repeats until the file fits. We now let users type 100 KB or 200 KB and get the exact file on the first click.

Dealing with HEIC and PDFs via WebAssembly

createImageBitmap() handles JPEG, PNG, WebP, and AVIF—covering 80% of use cases. Two formats break browser-only tools: Apple’s .heic photos and multi-page .pdf files.

We compiled C/C++ decoders—libheif for HEIC and a lightweight PDF parser—into WebAssembly. We never load the .wasm files upfront. No one wants to download a 2 MB binary just to resize a PNG. We only import the module when the file header matches ftypheic or %PDF-.

For PDFs, we don’t turn every page into an image. That would destroy selectable text and blow up file size. Instead, the parser walks the PDF object tree, pulls out embedded raster scans, downsamples them on an OffscreenCanvas, and rebuilds the file stream.

Testing and Verification

To test if data stays local, open PixConvert, open DevTools (F12 → Network tab), and drop a file in. Once the page loads, network traffic stays flat at zero bytes.

Three Small Things We’d Do Differently from Day One

  • Cap your worker pool: Early on, we created a new Worker for every file. On a 16-thread desktop, 30 files triggered 30 workers at once—choking the browser. Now we cap a reusable pool at Math.min(navigator.hardwareConcurrency || 4, 6), which speeds up batch processing.
  • Revoke Blob URLs: Every URL.createObjectURL() stays in RAM until the tab closes. We now call URL.revokeObjectURL() right after the download starts.
  • EXIF data is stripped: Drawing on a canvas removes GPS tags and camera metadata. For privacy tools, this is a benefit. But it caught us off guard when testing photo orientation flags (EXIF Orientation).

Anyone else building local-first tools with WebAssembly or OffscreenCanvas? How are you handling Safari’s quirks with worker canvas contexts? It’s been the trickiest browser to keep stable.

This project shows how browser-native APIs can combine to build strong, privacy-first tools—without any backend infrastructure. It sets a path for future tools that prioritize user control, data sovereignty, and minimal external dependencies.

For tools that never upload your data, see Zero-Server Tools That Never Send Your Data.

For a deeper dive into browser-based processing, see Linux History in Browser: Building a Time Machine for Early Linux Kernels.

Sources & further reading

Featured image: original publisher image. Via original publisher. Image source