# BackgroundFX Pro Examples Welcome to the BackgroundFX Pro examples collection! This directory contains practical, production-ready code examples in multiple programming languages and for various use cases. ## 🚀 Quick Start 1. **Get your API key** from [BackgroundFX Pro Dashboard](https://app.backgroundfx.pro) 2. **Set environment variable**: `export BACKGROUNDFX_API_KEY=your-api-key` 3. **Choose your language** and run the examples ## 📁 Directory Structure ``` examples/ ├── python/ # Python examples ├── javascript/ # JavaScript/Node.js examples ├── go/ # Go examples ├── curl/ # cURL command examples ├── integrations/ # Platform integrations ├── notebooks/ # Jupyter notebooks ├── docker/ # Docker configurations └── use-cases/ # Industry-specific examples ``` ## 🐍 Python Examples ### Basic Usage ```python cd python pip install -r requirements.txt python basic_usage.py ``` **Available Examples:** - `basic_usage.py` - Core API operations - `batch_processing.py` - Process multiple images - `video_processing.py` - Video background removal - `webhook_handler.py` - Handle webhooks - `async_processing.py` - Asynchronous operations ## 🟨 JavaScript Examples ### Node.js ```bash cd javascript/node npm install node basic_usage.js ``` ### Browser/React ```bash cd javascript/browser # Open react_component.jsx in your React app # Or open vanilla_js.html in a browser ``` **Available Examples:** - `basic_usage.js` - Core API operations - `express_integration.js` - Express.js server - `websocket_client.js` - Real-time updates - `react_component.jsx` - React component ## 🐹 Go Examples ```bash cd go go mod download go run basic_usage.go ``` **Available Examples:** - `basic_usage.go` - Core API operations - `gin_integration.go` - Gin framework integration ## 🔗 cURL Examples ```bash cd curl chmod +x *.sh ./basic_commands.sh ``` **Available Scripts:** - `basic_commands.sh` - Essential API calls - `batch_upload.sh` - Batch processing - `webhook_test.sh` - Webhook testing ## 🔌 Platform Integrations ### WordPress Plugin ```php cd integrations/wordpress # Copy to wp-content/plugins/ # Activate in WordPress admin ``` ### Shopify App ```javascript cd integrations/shopify npm install npm run dev ``` ### Next.js ```typescript cd integrations/nextjs # Copy components to your Next.js app ``` ### Flask ```python cd integrations/flask pip install -r requirements.txt python app.py ``` ## 📓 Jupyter Notebooks Interactive notebooks for learning and experimentation: ```bash cd notebooks jupyter notebook ``` **Available Notebooks:** - `getting_started.ipynb` - Interactive tutorial - `model_comparison.ipynb` - Compare different models - `batch_analysis.ipynb` - Batch processing analysis - `custom_training.ipynb` - Train custom models ## 🐳 Docker Examples ### Simple Setup ```bash cd docker/simple docker-compose up ``` ### Full Stack ```bash cd docker/full-stack docker-compose up -d ``` ### Kubernetes ```bash cd docker/kubernetes kubectl apply -f deployment.yaml ``` ## 💼 Use Cases ### E-commerce Automated product photography workflow: ```python cd use-cases/e-commerce python product_automation.py ``` **Features:** - Batch process product catalogs - Generate platform-specific sizes - Create marketing variations - Shopify/WooCommerce integration ### Social Media Content creation automation: ```python cd use-cases/social-media python instagram_stories.py ``` **Features:** - Story templates - Batch processing - Auto-resizing - Filter effects ### Real Estate Property image enhancement: ```python cd use-cases/real-estate python property_images.py ``` **Features:** - Virtual staging - Sky replacement - Batch processing - MLS compliance ### Photography Professional photo editing: ```python cd use-cases/photography python portrait_processing.py ``` **Features:** - Portrait enhancement - Wedding batch processing - Background replacement - Color grading ## 🔑 API Key Setup ### Environment Variable (Recommended) ```bash export BACKGROUNDFX_API_KEY=your-api-key-here ``` ### Configuration File Create `.env` file: ``` BACKGROUNDFX_API_KEY=your-api-key-here BACKGROUNDFX_API_URL=https://api.backgroundfx.pro/v1 ``` ### In Code ```python client = BackgroundFXClient(api_key="your-api-key-here") ``` ## 📊 Performance Tips ### Batch Processing - Use batch endpoints for multiple images - Process in parallel when possible - Implement retry logic with exponential backoff ### Quality Settings - `low` - Fast processing, good for previews - `medium` - Balanced quality/speed - `high` - Professional quality - `ultra` - Maximum quality ### Model Selection - `rembg` - Fast, general purpose - `u2net` - High quality, good for products - `sam2` - Best quality, slower - `auto` - Let API choose ## 🔧 Common Issues ### Rate Limiting ```python # Implement exponential backoff import time def retry_with_backoff(func, max_retries=3): for i in range(max_retries): try: return func() except RateLimitError: wait_time = 2 ** i time.sleep(wait_time) raise Exception("Max retries exceeded") ``` ### Large Files ```python # Compress before upload from PIL import Image def compress_image(path, max_size_mb=10): img = Image.open(path) img.thumbnail((4096, 4096)) img.save(path, optimize=True, quality=85) ``` ### Memory Management ```python # Process in chunks for large batches def process_in_chunks(images, chunk_size=10): for i in range(0, len(images), chunk_size): chunk = images[i:i+chunk_size] process_batch(chunk) ``` ## 📚 Additional Resources - [API Documentation](https://api.backgroundfx.pro/docs) - [Developer Portal](https://developers.backgroundfx.pro) - [Community Forum](https://forum.backgroundfx.pro) - [Video Tutorials](https://youtube.com/@backgroundfx) ## 🤝 Contributing We welcome contributions! To add new examples: 1. Fork the repository 2. Create your example following the existing structure 3. Add documentation 4. Submit a pull request ## 📄 License All examples are provided under the MIT License. Feel free to use them in your projects! ## 🆘 Support - **Email**: support@backgroundfx.pro - **Discord**: [Join our community](https://discord.gg/backgroundfx) - **GitHub Issues**: [Report issues](https://github.com/backgroundfx/examples/issues) --- **Happy coding!** 🎉 Build amazing things with BackgroundFX Pro!