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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# BackgroundFX Pro Examples
|
| 2 |
+
|
| 3 |
+
Welcome to the BackgroundFX Pro examples collection! This directory contains practical, production-ready code examples in multiple programming languages and for various use cases.
|
| 4 |
+
|
| 5 |
+
## π Quick Start
|
| 6 |
+
|
| 7 |
+
1. **Get your API key** from [BackgroundFX Pro Dashboard](https://app.backgroundfx.pro)
|
| 8 |
+
2. **Set environment variable**: `export BACKGROUNDFX_API_KEY=your-api-key`
|
| 9 |
+
3. **Choose your language** and run the examples
|
| 10 |
+
|
| 11 |
+
## π Directory Structure
|
| 12 |
+
|
| 13 |
+
```
|
| 14 |
+
examples/
|
| 15 |
+
βββ python/ # Python examples
|
| 16 |
+
βββ javascript/ # JavaScript/Node.js examples
|
| 17 |
+
βββ go/ # Go examples
|
| 18 |
+
βββ curl/ # cURL command examples
|
| 19 |
+
βββ integrations/ # Platform integrations
|
| 20 |
+
βββ notebooks/ # Jupyter notebooks
|
| 21 |
+
βββ docker/ # Docker configurations
|
| 22 |
+
βββ use-cases/ # Industry-specific examples
|
| 23 |
+
```
|
| 24 |
+
|
| 25 |
+
## π Python Examples
|
| 26 |
+
|
| 27 |
+
### Basic Usage
|
| 28 |
+
```python
|
| 29 |
+
cd python
|
| 30 |
+
pip install -r requirements.txt
|
| 31 |
+
python basic_usage.py
|
| 32 |
+
```
|
| 33 |
+
|
| 34 |
+
**Available Examples:**
|
| 35 |
+
- `basic_usage.py` - Core API operations
|
| 36 |
+
- `batch_processing.py` - Process multiple images
|
| 37 |
+
- `video_processing.py` - Video background removal
|
| 38 |
+
- `webhook_handler.py` - Handle webhooks
|
| 39 |
+
- `async_processing.py` - Asynchronous operations
|
| 40 |
+
|
| 41 |
+
## π¨ JavaScript Examples
|
| 42 |
+
|
| 43 |
+
### Node.js
|
| 44 |
+
```bash
|
| 45 |
+
cd javascript/node
|
| 46 |
+
npm install
|
| 47 |
+
node basic_usage.js
|
| 48 |
+
```
|
| 49 |
+
|
| 50 |
+
### Browser/React
|
| 51 |
+
```bash
|
| 52 |
+
cd javascript/browser
|
| 53 |
+
# Open react_component.jsx in your React app
|
| 54 |
+
# Or open vanilla_js.html in a browser
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
**Available Examples:**
|
| 58 |
+
- `basic_usage.js` - Core API operations
|
| 59 |
+
- `express_integration.js` - Express.js server
|
| 60 |
+
- `websocket_client.js` - Real-time updates
|
| 61 |
+
- `react_component.jsx` - React component
|
| 62 |
+
|
| 63 |
+
## πΉ Go Examples
|
| 64 |
+
|
| 65 |
+
```bash
|
| 66 |
+
cd go
|
| 67 |
+
go mod download
|
| 68 |
+
go run basic_usage.go
|
| 69 |
+
```
|
| 70 |
+
|
| 71 |
+
**Available Examples:**
|
| 72 |
+
- `basic_usage.go` - Core API operations
|
| 73 |
+
- `gin_integration.go` - Gin framework integration
|
| 74 |
+
|
| 75 |
+
## π cURL Examples
|
| 76 |
+
|
| 77 |
+
```bash
|
| 78 |
+
cd curl
|
| 79 |
+
chmod +x *.sh
|
| 80 |
+
./basic_commands.sh
|
| 81 |
+
```
|
| 82 |
+
|
| 83 |
+
**Available Scripts:**
|
| 84 |
+
- `basic_commands.sh` - Essential API calls
|
| 85 |
+
- `batch_upload.sh` - Batch processing
|
| 86 |
+
- `webhook_test.sh` - Webhook testing
|
| 87 |
+
|
| 88 |
+
## π Platform Integrations
|
| 89 |
+
|
| 90 |
+
### WordPress Plugin
|
| 91 |
+
```php
|
| 92 |
+
cd integrations/wordpress
|
| 93 |
+
# Copy to wp-content/plugins/
|
| 94 |
+
# Activate in WordPress admin
|
| 95 |
+
```
|
| 96 |
+
|
| 97 |
+
### Shopify App
|
| 98 |
+
```javascript
|
| 99 |
+
cd integrations/shopify
|
| 100 |
+
npm install
|
| 101 |
+
npm run dev
|
| 102 |
+
```
|
| 103 |
+
|
| 104 |
+
### Next.js
|
| 105 |
+
```typescript
|
| 106 |
+
cd integrations/nextjs
|
| 107 |
+
# Copy components to your Next.js app
|
| 108 |
+
```
|
| 109 |
+
|
| 110 |
+
### Flask
|
| 111 |
+
```python
|
| 112 |
+
cd integrations/flask
|
| 113 |
+
pip install -r requirements.txt
|
| 114 |
+
python app.py
|
| 115 |
+
```
|
| 116 |
+
|
| 117 |
+
## π Jupyter Notebooks
|
| 118 |
+
|
| 119 |
+
Interactive notebooks for learning and experimentation:
|
| 120 |
+
|
| 121 |
+
```bash
|
| 122 |
+
cd notebooks
|
| 123 |
+
jupyter notebook
|
| 124 |
+
```
|
| 125 |
+
|
| 126 |
+
**Available Notebooks:**
|
| 127 |
+
- `getting_started.ipynb` - Interactive tutorial
|
| 128 |
+
- `model_comparison.ipynb` - Compare different models
|
| 129 |
+
- `batch_analysis.ipynb` - Batch processing analysis
|
| 130 |
+
- `custom_training.ipynb` - Train custom models
|
| 131 |
+
|
| 132 |
+
## π³ Docker Examples
|
| 133 |
+
|
| 134 |
+
### Simple Setup
|
| 135 |
+
```bash
|
| 136 |
+
cd docker/simple
|
| 137 |
+
docker-compose up
|
| 138 |
+
```
|
| 139 |
+
|
| 140 |
+
### Full Stack
|
| 141 |
+
```bash
|
| 142 |
+
cd docker/full-stack
|
| 143 |
+
docker-compose up -d
|
| 144 |
+
```
|
| 145 |
+
|
| 146 |
+
### Kubernetes
|
| 147 |
+
```bash
|
| 148 |
+
cd docker/kubernetes
|
| 149 |
+
kubectl apply -f deployment.yaml
|
| 150 |
+
```
|
| 151 |
+
|
| 152 |
+
## πΌ Use Cases
|
| 153 |
+
|
| 154 |
+
### E-commerce
|
| 155 |
+
Automated product photography workflow:
|
| 156 |
+
```python
|
| 157 |
+
cd use-cases/e-commerce
|
| 158 |
+
python product_automation.py
|
| 159 |
+
```
|
| 160 |
+
|
| 161 |
+
**Features:**
|
| 162 |
+
- Batch process product catalogs
|
| 163 |
+
- Generate platform-specific sizes
|
| 164 |
+
- Create marketing variations
|
| 165 |
+
- Shopify/WooCommerce integration
|
| 166 |
+
|
| 167 |
+
### Social Media
|
| 168 |
+
Content creation automation:
|
| 169 |
+
```python
|
| 170 |
+
cd use-cases/social-media
|
| 171 |
+
python instagram_stories.py
|
| 172 |
+
```
|
| 173 |
+
|
| 174 |
+
**Features:**
|
| 175 |
+
- Story templates
|
| 176 |
+
- Batch processing
|
| 177 |
+
- Auto-resizing
|
| 178 |
+
- Filter effects
|
| 179 |
+
|
| 180 |
+
### Real Estate
|
| 181 |
+
Property image enhancement:
|
| 182 |
+
```python
|
| 183 |
+
cd use-cases/real-estate
|
| 184 |
+
python property_images.py
|
| 185 |
+
```
|
| 186 |
+
|
| 187 |
+
**Features:**
|
| 188 |
+
- Virtual staging
|
| 189 |
+
- Sky replacement
|
| 190 |
+
- Batch processing
|
| 191 |
+
- MLS compliance
|
| 192 |
+
|
| 193 |
+
### Photography
|
| 194 |
+
Professional photo editing:
|
| 195 |
+
```python
|
| 196 |
+
cd use-cases/photography
|
| 197 |
+
python portrait_processing.py
|
| 198 |
+
```
|
| 199 |
+
|
| 200 |
+
**Features:**
|
| 201 |
+
- Portrait enhancement
|
| 202 |
+
- Wedding batch processing
|
| 203 |
+
- Background replacement
|
| 204 |
+
- Color grading
|
| 205 |
+
|
| 206 |
+
## π API Key Setup
|
| 207 |
+
|
| 208 |
+
### Environment Variable (Recommended)
|
| 209 |
+
```bash
|
| 210 |
+
export BACKGROUNDFX_API_KEY=your-api-key-here
|
| 211 |
+
```
|
| 212 |
+
|
| 213 |
+
### Configuration File
|
| 214 |
+
Create `.env` file:
|
| 215 |
+
```
|
| 216 |
+
BACKGROUNDFX_API_KEY=your-api-key-here
|
| 217 |
+
BACKGROUNDFX_API_URL=https://api.backgroundfx.pro/v1
|
| 218 |
+
```
|
| 219 |
+
|
| 220 |
+
### In Code
|
| 221 |
+
```python
|
| 222 |
+
client = BackgroundFXClient(api_key="your-api-key-here")
|
| 223 |
+
```
|
| 224 |
+
|
| 225 |
+
## π Performance Tips
|
| 226 |
+
|
| 227 |
+
### Batch Processing
|
| 228 |
+
- Use batch endpoints for multiple images
|
| 229 |
+
- Process in parallel when possible
|
| 230 |
+
- Implement retry logic with exponential backoff
|
| 231 |
+
|
| 232 |
+
### Quality Settings
|
| 233 |
+
- `low` - Fast processing, good for previews
|
| 234 |
+
- `medium` - Balanced quality/speed
|
| 235 |
+
- `high` - Professional quality
|
| 236 |
+
- `ultra` - Maximum quality
|
| 237 |
+
|
| 238 |
+
### Model Selection
|
| 239 |
+
- `rembg` - Fast, general purpose
|
| 240 |
+
- `u2net` - High quality, good for products
|
| 241 |
+
- `sam2` - Best quality, slower
|
| 242 |
+
- `auto` - Let API choose
|
| 243 |
+
|
| 244 |
+
## π§ Common Issues
|
| 245 |
+
|
| 246 |
+
### Rate Limiting
|
| 247 |
+
```python
|
| 248 |
+
# Implement exponential backoff
|
| 249 |
+
import time
|
| 250 |
+
|
| 251 |
+
def retry_with_backoff(func, max_retries=3):
|
| 252 |
+
for i in range(max_retries):
|
| 253 |
+
try:
|
| 254 |
+
return func()
|
| 255 |
+
except RateLimitError:
|
| 256 |
+
wait_time = 2 ** i
|
| 257 |
+
time.sleep(wait_time)
|
| 258 |
+
raise Exception("Max retries exceeded")
|
| 259 |
+
```
|
| 260 |
+
|
| 261 |
+
### Large Files
|
| 262 |
+
```python
|
| 263 |
+
# Compress before upload
|
| 264 |
+
from PIL import Image
|
| 265 |
+
|
| 266 |
+
def compress_image(path, max_size_mb=10):
|
| 267 |
+
img = Image.open(path)
|
| 268 |
+
img.thumbnail((4096, 4096))
|
| 269 |
+
img.save(path, optimize=True, quality=85)
|
| 270 |
+
```
|
| 271 |
+
|
| 272 |
+
### Memory Management
|
| 273 |
+
```python
|
| 274 |
+
# Process in chunks for large batches
|
| 275 |
+
def process_in_chunks(images, chunk_size=10):
|
| 276 |
+
for i in range(0, len(images), chunk_size):
|
| 277 |
+
chunk = images[i:i+chunk_size]
|
| 278 |
+
process_batch(chunk)
|
| 279 |
+
```
|
| 280 |
+
|
| 281 |
+
## π Additional Resources
|
| 282 |
+
|
| 283 |
+
- [API Documentation](https://api.backgroundfx.pro/docs)
|
| 284 |
+
- [Developer Portal](https://developers.backgroundfx.pro)
|
| 285 |
+
- [Community Forum](https://forum.backgroundfx.pro)
|
| 286 |
+
- [Video Tutorials](https://youtube.com/@backgroundfx)
|
| 287 |
+
|
| 288 |
+
## π€ Contributing
|
| 289 |
+
|
| 290 |
+
We welcome contributions! To add new examples:
|
| 291 |
+
|
| 292 |
+
1. Fork the repository
|
| 293 |
+
2. Create your example following the existing structure
|
| 294 |
+
3. Add documentation
|
| 295 |
+
4. Submit a pull request
|
| 296 |
+
|
| 297 |
+
## π License
|
| 298 |
+
|
| 299 |
+
All examples are provided under the MIT License. Feel free to use them in your projects!
|
| 300 |
+
|
| 301 |
+
## π Support
|
| 302 |
+
|
| 303 |
+
- **Email**: support@backgroundfx.pro
|
| 304 |
+
- **Discord**: [Join our community](https://discord.gg/backgroundfx)
|
| 305 |
+
- **GitHub Issues**: [Report issues](https://github.com/backgroundfx/examples/issues)
|
| 306 |
+
|
| 307 |
+
---
|
| 308 |
+
|
| 309 |
+
**Happy coding!** π Build amazing things with BackgroundFX Pro!
|