| Crates.io | bgone |
| lib.rs | bgone |
| version | 0.5.0 |
| created_at | 2025-09-21 14:28:12.638974+00 |
| updated_at | 2025-12-07 21:43:36.053279+00 |
| description | Ultra-fast CLI tool for removing solid background colors from images |
| homepage | https://github.com/benface/bgone |
| repository | https://github.com/benface/bgone |
| max_upload_size | |
| id | 1848856 |
| size | 2,580,963 |
Ultra-fast CLI tool for removing solid background colors from images using color unmixing.

auto keywordbrew tap benface/bgone
brew install bgone
cargo install bgone
In non-strict mode, bgone can use any color needed to perfectly reconstruct the image while making the background transparent.
# Fully automatic - detects the background and removes it
# Output defaults to input-bgone.png (or input-bgone-1.png if that exists, etc.)
bgone input.png
# Specify output path
bgone input.png output.png
# With background color - overrides automatic detection
bgone input.png --bg=#ffffff
# With foreground color - optimizes for high opacity when pixels match this color (within a threshold)
bgone input.png --fg=#ff0000
# Multiple foreground colors - output pixels can be any mix of these colors
bgone input.png --fg ff0000 00ff00 0000ff
# Foreground color deduction - uses a known amount of unknown colors
bgone input.png --fg auto
bgone input.png --fg auto auto --bg ffffff
# Mix known and unknown colors
bgone input.png --fg ff0000 auto
# Using shorthand notation
bgone input.png -f f00 -b fff
bgone input.png -f auto -s
bgone input.png -f f00 0f0 00f -b fff -t 0.1
Strict mode restricts unmixing to only the specified foreground colors, ensuring exact color matching.
# Strict mode requires --fg, but supports both known and unknown colors
bgone input.png --strict --fg=#ff0000
bgone input.png --strict --fg auto
bgone input.png --strict --fg ff0000 auto
# With specific background color
bgone input.png --strict --fg=#f00 --bg=#fff
Use --trim to automatically crop the output image to the bounding box of non-transparent pixels, removing any fully transparent padding:
# Remove background and trim
bgone input.png --trim
# Combine with other options
bgone input.png --bg=#ffffff --trim
bgone input.png --fg=#ff0000 --bg=#000000 --trim
# Multiple colors with # prefix still works, but requires quotes in shell
bgone input.png --fg "#f00" "#0f0" "#00f"
# Mix of shorthand and full notation
bgone input.png --fg ff0000 0f0 00f --bg fff
input - Path to the input image
output - (Optional) Path for the output image
-bgone suffix-f, --fg COLOR... - Foreground colors in hex format (e.g., f00, ff0000, #ff0000) or auto to deduce unknown colors
-b, --bg COLOR - Background color in hex format
-s, --strict - Enable strict mode (requires --fg and restricts to specified colors only)-t, --threshold FLOAT - Color similarity threshold (0.0-1.0, default: 0.05)
auto foreground colors: colors within this threshold are considered similar during deduction--fg in non-strict mode: pixels within this threshold of a (known or deduced) foreground color will use that color--trim - Trim the output image by cropping to the bounding box of non-transparent pixels
-h, --help - Print help information-v, --version - Print version informationbgone supports a wide range of image formats (PNG, JPEG, GIF, WebP, TIFF, BMP, ICO, TGA, DDS, HDR, OpenEXR, QOI, and more). Formats without alpha support (JPEG, BMP, etc.) are automatically converted to PNG.
The tool uses a color unmixing algorithm to determine how much of each foreground color and the background color contributed to each pixel. It then reconstructs the image with proper alpha transparency.
auto)When using the auto keyword, bgone:
bgone works best with:
bgone may struggle with:
bgone will struggle with:
bgone intelligently handles existing transparency in input images:
--bg for best accuracy--threshold for fine-tuning edge detectionauto only for foreground colors that aren't directly visible in the image but can recreate existing colors when blended with the backgroundauto with gradients or shades, pair it with white or black:
--fg fff auto for images with mostly light tones--fg 000 auto for images with mostly dark tonescargo build --release
You can test the tool without installing it using cargo run:
cargo run --release -- input.png --fg ff0000
The -- separates cargo's arguments from bgone's arguments.
The project includes a comprehensive testing framework that validates the color unmixing algorithm by:
# Run all tests
cargo test --release -- --nocapture
# Run specific test suites
cargo test --release --test strict_tests -- --nocapture
cargo test --release --test non_strict_tests -- --nocapture
cargo test --release --test color_deduction_tests -- --nocapture
cargo test --release --test square_gradient_stroke_tests -- --nocapture
cargo test --release --test translucent_recovery_tests -- --nocapture
cargo test --release --test trim_tests -- --nocapture
# Generate test inputs (only needed once)
cargo test --release --test generate_inputs -- --ignored
The algorithm achieves excellent results across different test scenarios:
PSNR values above 40 dB indicate excellent quality reconstruction.
This project was entirely ✨vibe coded✨ - built with Claude Code with very little care about the actual code output. As a result, the codebase may have quirks, bugs, or unconventional patterns.
Contributions are welcome! Feel free to:
Thank you!