DEV Community

Max/Wang
Max/Wang

Posted on

I Built My Own Free Background Remover

Recently, remove.bg started moving its background removal experience to Canva.

So I started looking around for alternatives.

There are quite a few good ones. Adobe has a pretty decent background remover, for example. The actual results are surprisingly good.

But then I hit the usual problems.

Limits.

Login requirements.

And sometimes you can process an image for free, but you need to sign in before you can actually download the result.

I also came across rembg, which is completely free and works really well. But I wanted something that could handle HEIC and HEIF images too, since a lot of photos these days come directly from iPhones.

So, naturally, I ended up coding my own.

A background remover that runs in the browser

I wanted to keep the whole thing simple:

  • Free
  • No account
  • No download limits
  • Supports JPG, PNG, WebP, HEIC and HEIF
  • Background removal happens locally in the browser

For the model, I went with BiRefNet-lite and converted it to ONNX so I could run inference with ONNX Runtime Web.

The interesting part is that this doesn't need a backend GPU.

It uses WebGPU when available, so the model can run directly on the user's machine.

I've tested it on a few different images and, honestly, the results are pretty good. Hair, people, products, objects, etc. are generally handled quite nicely.

It's not magic, of course. Background removal is one of those tasks where there will always be difficult images — messy hair, low contrast, objects blending into the background, and so on.

But for a lightweight browser tool, I'm pretty happy with it.

Why BiRefNet-lite?

I also looked at other models, including RMBG-1.4.

RMBG-1.4 can be very fast in my testing, and the output quality is in the same general range.

However, licensing matters when you're building a public commercial website, so I ended up using BiRefNet-lite for this project. The model is released under the MIT license, which makes things much simpler for this kind of use.

The trade-off is that inference isn't necessarily as fast as RMBG-1.4 on every setup.

That's something I'm still interested in optimizing.

One important limitation

There is one fairly big requirement:

Your browser needs WebGPU.

If your device or browser doesn't support WebGPU, this tool won't work.

That's the trade-off for running a relatively capable AI model directly on the user's machine instead of sending images to a server.

For newer laptops, desktops, and phones, WebGPU support is becoming much more common, though.

HEIC/HEIF was actually one of the reasons I built it

This was probably the biggest practical motivation.

If you're using an iPhone, there's a good chance you've encountered HEIC images.

I wanted to be able to drop one of those images into the tool, remove the background, and download the result without having to convert it somewhere else first.

So now it does exactly that.

Anyway, this started as one of those "why doesn't this simple thing work the way I want?" projects and turned into another little tool for SquishyFile.

You can try it here:

https://squishyfile.com/image/transparent-background-creator

Hopefully some of you find it useful. 🙂

Top comments (0)