bg-remove
v2.0.0
Published
Fast AI-powered background removal - instant transparent backgrounds
Maintainers
Readme
bg-remove
⚡ Fast AI-powered background removal - instant transparent backgrounds
A lightning-fast NPM package that removes backgrounds from images using advanced algorithms. Get transparent backgrounds in seconds, not minutes. Perfect for e-commerce, portraits, and any image processing workflow.
✨ Features
- ⚡ Ultra-fast processing - Instant results with optimized algorithms
- 🔍 Transparent backgrounds only - Clean, simple output
- 🧠 Multiple AI algorithms - Choose the best approach for your needs
- 📸 Multiple formats - Supports JPG, PNG, WebP, URLs
- 🎛️ Quality control - Fast, balanced, or high quality modes
- 🔄 Batch processing - Process multiple images at once
- 📦 Lightweight - No heavy AI models to download
📦 Installation
npm install bg-remove🚀 Quick Start
const { removeBackground } = require('bg-remove');
const fs = require('fs');
// Remove background from an image
async function example() {
const result = await removeBackground('input.jpg');
// Save the transparent image
fs.writeFileSync('output.png', result.data);
console.log(`✅ Background removed! Size: ${result.width}x${result.height}`);
}
example();📖 API Reference
removeBackground(input, options?)
Removes the background from an image and returns a transparent PNG.
Parameters:
input(string | Buffer) - Image file path, URL, or Bufferoptions(object, optional) - Processing options
Options:
quality('fast' | 'balanced' | 'high') - Processing quality (default: 'fast')algorithm('ultra-fast' | 'instant' | 'color-similarity' | 'edge-detection' | 'smart-detection') - Algorithm to use (default: 'ultra-fast')
Returns:
Promise<ProcessingResult>- Object with image data and metadata
Example:
const result = await removeBackground('photo.jpg', {
quality: 'high',
algorithm: 'instant'
});removeBackgroundBatch(inputs, options?)
Process multiple images in batch.
Parameters:
inputs(Array<string | Buffer>) - Array of image inputsoptions(object, optional) - Processing options
Returns:
Promise<ProcessingResult[]>- Array of processing results
Example:
const results = await removeBackgroundBatch([
'photo1.jpg',
'photo2.png',
'photo3.webp'
]);
results.forEach((result, index) => {
fs.writeFileSync(`output-${index}.png`, result.data);
});🎯 Use Cases
- E-commerce - Product photos with transparent backgrounds
- Profile pictures - Remove backgrounds from portraits
- Logos - Clean logo extraction
- Design assets - Prepare images for graphic design
- Automation - Batch process images in workflows
⚙️ Algorithm Options
ultra-fast- Lightning fast processing, good for real-time applications (default)instant- Very fast with better quality than ultra-fastcolor-similarity- Fast color-based background detectionedge-detection- Advanced edge detection for complex backgroundssmart-detection- Combines multiple approaches for best results
🎛️ Quality Settings
fast- Quick processing, good for batch operations (default)balanced- Good quality with reasonable speedhigh- Best quality, slower processing
🔧 Advanced Usage
TypeScript Support
import { removeBackground, ProcessingResult } from 'bg-remove';
const result: ProcessingResult = await removeBackground('image.jpg');Error Handling
try {
const result = await removeBackground('image.jpg');
console.log('Success!', result);
} catch (error) {
console.error('Failed to remove background:', error.message);
}Processing Large Images
// For large images, use 'fast' quality for better performance
const result = await removeBackground('large-image.jpg', {
quality: 'fast'
});📊 Performance
Ultra-Fast Algorithm (Default)
- Small images (< 500KB): ~1-3 seconds
- Medium images (500KB - 2MB): ~3-6 seconds
- Large images (> 2MB): ~6-10 seconds
Instant Algorithm
- Small images (< 500KB): ~2-4 seconds
- Medium images (500KB - 2MB): ~4-8 seconds
- Large images (> 2MB): ~8-15 seconds
Performance varies based on image complexity, size, and algorithm choice. All algorithms provide transparent backgrounds only.
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
📄 License
MIT License - see LICENSE file for details.
🙋♂️ Support
If you have any questions or issues, please open an issue on GitHub.
Made with ❤️ for simple background removal
