Skip to main content

resizebox-background-remover

AI background removal for Python by ResizeBox.com: https://resizebox.com/remove-background

Built by ResizeBox.com, a privacy-focused image toolkit. Images are processed locally in your Python process.

Install

pip install resizebox-background-remover

Remove a background

from resizebox_background_remover import remove_background

result = remove_background(
    "input.jpg",
    "output.png",
)

print(result.width, result.height)

The first run downloads the quantized onnx-community/ormbg-ONNX model from Hugging Face and caches it locally. The model is then executed locally with ONNX Runtime. Your image is not uploaded to ResizeBox or Hugging Face.

Work with bytes

from resizebox_background_remover import remove_background

with open("input.webp", "rb") as file:
    source = file.read()

result = remove_background(source)

with open("result.png", "wb") as file:
    file.write(result.data)

bytes, bytearray, binary file-like objects, str paths, and pathlib.Path are supported as inputs.

Solid background color

Transparent PNG is the default output. A six-digit hex color can be used instead:

result = remove_background(
    "input.png",
    "white-background.png",
    background="#FFFFFF",
)

Preload the model

Download and initialize the model before processing the first image:

from resizebox_background_remover import preload_model

model_path = preload_model()
print(model_path)

You can provide a custom Hugging Face cache directory:

preload_model(cache_dir="./model-cache")

ONNX Runtime providers

By default, ONNX Runtime chooses the providers available in the current Python environment. You can explicitly select providers when needed:

result = remove_background(
    "input.jpg",
    providers=["CPUExecutionProvider"],
)

Result

Every call returns a BackgroundRemovalResult:

result.data        # PNG bytes
result.width
result.height
result.mime_type   # "image/png"
result.filename
result.output_path

Errors

Validation, model download, model initialization, inference, and encoding failures raise BackgroundRemoverError with a machine-readable code.

from resizebox_background_remover import BackgroundRemoverError, remove_background

try:
    remove_background("input.jpg")
except BackgroundRemoverError as error:
    print(error.code)

Input and output

Supported input formats:

  • JPEG
  • PNG
  • WebP

Output format:

  • PNG with transparency by default
  • PNG composited onto a custom solid background when requested

The package validates decoded image format, file size, image dimensions, and model output before returning a result.

Model

The model is not bundled into the PyPI package. On first use, the package downloads:

onnx-community/ormbg-ONNX/onnx/model_quantized.onnx

The model repository is licensed separately under Apache-2.0. The Python package code is licensed under MIT.

Privacy

Image processing runs locally in your Python process. Image content is not uploaded to ResizeBox or Hugging Face. Hugging Face is contacted only to download the AI model file.

Website: https://resizebox.com/remove-background

Privacy Policy: https://resizebox.com/privacy-policy

License

MIT

Metadata

Release files for resizebox-background-remover 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for resizebox-background-remover 1.0.0
File Size Uploaded Provenance
resizebox_background_remover-1.0.0.tar.gz 10.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for resizebox-background-remover 1.0.0
File Interpreter ABI Platform
resizebox_background_remover-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 19.7 kB

Release files / resizebox_background_remover-1.0.0.tar.gz

Download URL resizebox_background_remover-1.0.0.tar.gz
Size 10.1 kB
Tags Source
SHA-256 checksum
How to use checksums
eb3ba93dae5f1403297128288db85066dcb6dae6612c801ac9ca7b19ac86776e
BLAKE2b-256 checksum
How to use checksums
7130966c74db9c5d1acf11cc6278b52e671001dac5d385f42f7ef599df67b1e4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Release files / resizebox_background_remover-1.0.0-py3-none-any.whl

Download URL resizebox_background_remover-1.0.0-py3-none-any.whl
Size 9.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
be1daaef6351c39613154dd0885852fdeb9375447409e51a9dce847063abef46
BLAKE2b-256 checksum
How to use checksums
5c239a87c8825bb15e569ecc9876b61441902d06a5687d10bef6dfde4a05c46e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Security for resizebox-background-remover 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page