|
| 1 | +# RemBG CLI |
| 2 | + |
| 3 | +A cross-platform command-line interface for batch background removal using the [rembg.js](https://github.com/Remove-Background-ai/rembg.js) library. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- 🚀 **Batch Processing**: Process single images or entire directories |
| 8 | +- 🌍 **Cross-Platform**: Works on Windows, macOS, and Linux |
| 9 | +- 🎨 **Multiple Formats**: Supports JPG, JPEG, PNG, and WEBP |
| 10 | +- 📊 **Progress Tracking**: Real-time progress indicators and detailed logging |
| 11 | +- ⚡ **Fast Processing**: Optimized for speed and reliability |
| 12 | +- 🔧 **Flexible Configuration**: Environment variables and CLI options |
| 13 | + |
| 14 | +## Installation |
| 15 | + |
| 16 | +### Prerequisites |
| 17 | + |
| 18 | +- Node.js v18.17.0 or higher |
| 19 | +- A valid API key from [RemBG.com](https://www.rembg.com/en) |
| 20 | + |
| 21 | +### Setup |
| 22 | + |
| 23 | +1. Use the release binaries or Clone this repository |
| 24 | +2. Install dependencies: |
| 25 | + ```bash |
| 26 | + npm install |
| 27 | + ``` |
| 28 | +3. Set up your API key: |
| 29 | + ```bash |
| 30 | + # Copy the example environment file |
| 31 | + cp env.example .env |
| 32 | + |
| 33 | + # Edit .env and add your API key |
| 34 | + X_API_KEY=your_actual_api_key_here |
| 35 | + ``` |
| 36 | + |
| 37 | +## Usage |
| 38 | + |
| 39 | +### Basic Usage |
| 40 | + |
| 41 | +```bash |
| 42 | +# Process a single image |
| 43 | +rembg-cli -i image.jpg -o ./output |
| 44 | + |
| 45 | +# Process all images in a directory |
| 46 | +rembg-cli -i ./images -o ./output |
| 47 | + |
| 48 | +# Specify output format |
| 49 | +rembg-cli -i ./images -o ./output -f png |
| 50 | +``` |
| 51 | + |
| 52 | +### Command Options |
| 53 | + |
| 54 | +| Option | Short | Description | Default | |
| 55 | +|--------|-------|-------------|---------| |
| 56 | +| `--input` | `-i` | Input file or directory | Required | |
| 57 | +| `--output` | `-o` | Output directory | `./output` | |
| 58 | +| `--format` | `-f` | Output format (png, webp) | `webp` | |
| 59 | +| `--verbose` | `-v` | Enable verbose logging | `false` | |
| 60 | +| `--api-key` | | Override API key from environment | From env | |
| 61 | +| `--version` | | Show version number | | |
| 62 | +| `--help` | | Show help information | | |
| 63 | + |
| 64 | +### Examples |
| 65 | + |
| 66 | +```bash |
| 67 | +# Process a single PNG image |
| 68 | +rembg-cli -i photo.png -o ./processed |
| 69 | + |
| 70 | +# Process all images in a folder with verbose output |
| 71 | +rembg-cli -i ./photos -o ./processed -v |
| 72 | + |
| 73 | +# Process images and save as JPG |
| 74 | +rembg-cli -i ./photos -o ./processed -f jpg |
| 75 | + |
| 76 | +# Use a different API key for this session |
| 77 | +rembg-cli -i ./photos -o ./processed --api-key your_key_here |
| 78 | +``` |
| 79 | + |
| 80 | +## Environment Variables |
| 81 | + |
| 82 | +Create a `.env` file in the project root: |
| 83 | + |
| 84 | +```env |
| 85 | +X_API_KEY=your_api_key_here |
| 86 | +DEFAULT_OUTPUT_FORMAT=webp |
| 87 | +DEFAULT_OUTPUT_DIR=./output |
| 88 | +``` |
| 89 | + |
| 90 | +## Building Executables |
| 91 | + |
| 92 | +Build cross-platform executables using pkg: |
| 93 | + |
| 94 | +```bash |
| 95 | +# Build for Windows |
| 96 | +npm run build:win |
| 97 | + |
| 98 | +# Build for macOS |
| 99 | +npm run build:mac |
| 100 | + |
| 101 | +# Build for Linux |
| 102 | +npm run build:linux |
| 103 | + |
| 104 | +# Build for all platforms |
| 105 | +npm run build:all |
| 106 | +``` |
| 107 | + |
| 108 | +The built executables will be in the project root: |
| 109 | +- `rembg-cli-win.exe` (Windows) |
| 110 | +- `rembg-cli-mac` (macOS) |
| 111 | +- `rembg-cli-linux` (Linux) |
| 112 | + |
| 113 | +## Supported Formats |
| 114 | + |
| 115 | +### Input Formats |
| 116 | +- JPG/JPEG |
| 117 | +- PNG |
| 118 | +- WEBP |
| 119 | + |
| 120 | +### Output Formats |
| 121 | +- WEBP (default) |
| 122 | +- PNG |
| 123 | + |
| 124 | +## Error Handling |
| 125 | + |
| 126 | +The CLI provides comprehensive error handling: |
| 127 | + |
| 128 | +- ✅ **Validation**: Checks for required parameters and file existence |
| 129 | +- 🔍 **API Errors**: Handles API failures gracefully |
| 130 | +- 📁 **File System**: Manages directory creation and file operations |
| 131 | +- 🚨 **User Feedback**: Clear error messages and suggestions |
| 132 | + |
| 133 | +## Performance Tips |
| 134 | + |
| 135 | +1. **Batch Processing**: Process multiple images in a single command for better efficiency |
| 136 | +2. **Output Format**: Use PNG for best quality, WEBP for smaller file sizes and perfect for most users |
| 137 | +3. **API Limits**: The tool processes images sequentially to respect API rate limits |
| 138 | +4. **Storage**: Ensure sufficient disk space for output files |
| 139 | + |
| 140 | +## Troubleshooting |
| 141 | + |
| 142 | +### Common Issues |
| 143 | + |
| 144 | +**"X_API_KEY is not set"** |
| 145 | +- Set your API key in the `.env` file or use the `--api-key` option |
| 146 | + |
| 147 | +**"Input path does not exist"** |
| 148 | +- Check that the file or directory path is correct |
| 149 | +- Use absolute paths if relative paths don't work |
| 150 | + |
| 151 | +**"No supported image files found"** |
| 152 | +- Ensure your files have supported extensions (.jpg, .jpeg, .png, .webp) |
| 153 | +- Check that the files are not corrupted |
| 154 | + |
| 155 | +**"Failed to process image"** |
| 156 | +- Verify your API key is valid and has sufficient credits |
| 157 | +- Check your internet connection |
| 158 | +- Try processing the image individually to isolate the issue |
| 159 | + |
| 160 | +### Getting Help |
| 161 | + |
| 162 | +- Use `rembg-cli --help` for command options |
| 163 | +- Use `rembg-cli --version` to check the version |
| 164 | +- Enable verbose mode with `-v` for detailed logging |
| 165 | + |
| 166 | +## License |
| 167 | + |
| 168 | +MIT License - see LICENSE file for details. |
| 169 | + |
| 170 | +## Contributing |
| 171 | + |
| 172 | +Contributions are welcome! Please feel free to submit issues and pull requests. |
| 173 | + |
| 174 | +## Support |
| 175 | + |
| 176 | +For API-related issues, visit [RemBG Support page](https://www.rembg.com/en/contact). |
0 commit comments