A command-line tool for removing backgrounds and foregrounds from images using AI. Works with both Node.js and Bun.
Install globally using npm:
npm install -g background-removal-js-node-cliThen use the CLI commands anywhere:
background-removal-cli rmbg -i input.jpg -o output.png
# or use the shorter alias
rmbg-cli rmbg -i input.jpg -o output.pngClone the repository and install dependencies:
git clone https://github.com/shpaw415/background-removal-js-node-cli.git
cd background-removal-js-node-cli
npm installBuild the CLI:
npm run buildInstall locally for development:
npm link# Remove background
background-removal-cli rmbg -i input.jpg -o output.png
# Or use the shorter command
rmbg-cli rmbg -i input.jpg -o output.png
# Remove foreground
background-removal-cli rmfg -i input.jpg -o output.png# With Node.js
node dist/index.js rmbg -i input.jpg -o output.png
# With Bun (from TypeScript source)
bun run index.ts rmbg -i input.jpg -o output.png
# With Bun (from compiled JS)
bun run dist/index.js rmbg -i input.jpg -o output.pngbackground-removal-cli rmbg [options]
Options:
-i, --input <path> Input image path (required)
-o, --output <path> Output image path (required)
-m, --model <model> Model size: small, medium, large (default: medium)
-f, --format <format> Output format: png, jpeg, x-alpha8, x-rgba8, webp (default: png)
-q, --quality <quality> Quality for jpeg/webp: 0-100 (default: 80)
-d, --debug Enable debug mode
-h, --help Show helpbackground-removal-cli rmfg [options]
# Same options as rmbg# Basic background removal
background-removal-cli rmbg -i photo.jpg -o photo-no-bg.png
# High quality with large model
background-removal-cli rmbg -i photo.jpg -o output.png -m large -q 95
# Output as JPEG
background-removal-cli rmbg -i photo.jpg -o output.jpg -f jpeg -q 90
# Remove foreground instead
background-removal-cli rmfg -i photo.jpg -o background-only.png# Run in development mode with Bun
bun run dev
# Build for production
npm run build
# Start compiled version
npm startTo publish this package to npm:
-
Login to npm (first time only):
npm login
-
Update version (choose one):
npm version patch # 1.0.0 -> 1.0.1 npm version minor # 1.0.0 -> 1.1.0 npm version major # 1.0.0 -> 2.0.0
-
Publish the package:
npm publish
The prepublishOnly script will automatically build the project before publishing.
- Node.js >= 18.0.0
- npm or Bun
- @imgly/background-removal-node - AI-powered background removal
- commander - Command-line interface framework
- log-update - Progress indicator
- sharp - Image processing
MIT © shpaw415
This project was created using bun init and supports both Bun and Node.js runtimes.