A cross-platform command-line interface for batch background removal using the rembg.js library.
- 🚀 Batch Processing: Process single images or entire directories
- 🌍 Cross-Platform: Works on Windows, macOS, and Linux
- 🎨 Multiple Formats: Supports JPG, JPEG, PNG, and WEBP
- 📊 Progress Tracking: Real-time progress indicators and detailed logging
- ⚡ Fast Processing: Optimized for speed and reliability
- 🔧 Flexible Configuration: Environment variables and CLI options
- Node.js v18.17.0 or higher
- A valid API key from RemBG.com
- Use the release binaries or Clone this repository
- Install dependencies:
npm install
- Set up your API key:
# Copy the example environment file cp env.example .env # Edit .env and add your API key X_API_KEY=your_actual_api_key_here
# Process a single image
rembg-cli -i image.jpg -o ./output
# Process all images in a directory
rembg-cli -i ./images -o ./output
# Specify output format
rembg-cli -i ./images -o ./output -f png| Option | Short | Description | Default |
|---|---|---|---|
--input |
-i |
Input file or directory | Required |
--output |
-o |
Output directory | ./output |
--format |
-f |
Output format (png, webp) | webp |
--verbose |
-v |
Enable verbose logging | false |
--api-key |
Override API key from environment | From env | |
--version |
Show version number | ||
--help |
Show help information |
# Process a single PNG image
rembg-cli -i photo.png -o ./processed
# Process all images in a folder with verbose output
rembg-cli -i ./photos -o ./processed -v
# Process images and save as JPG
rembg-cli -i ./photos -o ./processed -f jpg
# Use a different API key for this session
rembg-cli -i ./photos -o ./processed --api-key your_key_hereCreate a .env file in the project root:
X_API_KEY=your_api_key_here
DEFAULT_OUTPUT_FORMAT=webp
DEFAULT_OUTPUT_DIR=./outputBuild cross-platform executables using pkg:
# Build for Windows
npm run build:win
# Build for macOS
npm run build:mac
# Build for Linux
npm run build:linux
# Build for all platforms
npm run build:allThe built executables will be in the project root:
rembg-cli-win.exe(Windows)rembg-cli-mac(macOS)rembg-cli-linux(Linux)
- JPG/JPEG
- PNG
- WEBP
- WEBP (default)
- PNG
The CLI provides comprehensive error handling:
- ✅ Validation: Checks for required parameters and file existence
- 🔍 API Errors: Handles API failures gracefully
- 📁 File System: Manages directory creation and file operations
- 🚨 User Feedback: Clear error messages and suggestions
- Batch Processing: Process multiple images in a single command for better efficiency
- Output Format: Use PNG for best quality, WEBP for smaller file sizes and perfect for most users
- API Limits: The tool processes images sequentially to respect API rate limits
- Storage: Ensure sufficient disk space for output files
"X_API_KEY is not set"
- Set your API key in the
.envfile or use the--api-keyoption
"Input path does not exist"
- Check that the file or directory path is correct
- Use absolute paths if relative paths don't work
"No supported image files found"
- Ensure your files have supported extensions (.jpg, .jpeg, .png, .webp)
- Check that the files are not corrupted
"Failed to process image"
- Verify your API key is valid and has sufficient credits
- Check your internet connection
- Try processing the image individually to isolate the issue
- Use
rembg-cli --helpfor command options - Use
rembg-cli --versionto check the version - Enable verbose mode with
-vfor detailed logging
MIT License - see LICENSE file for details.
Contributions are welcome! Please feel free to submit issues and pull requests.
For API-related issues, visit RemBG Support page.