n8n-image-generator
# π¨ AI Image Generator > **Production-ready AI image generator built with n8n, featuring advanced rate limiting, content filtering, and multiple AI providers** [](https://opensource.org/licenses/MIT) [](https://n8n.io/) [](https://reactjs.org/) [](https://restfulapi.net/) [](https://pollinations.ai/) ## π Features - **π€ Multiple AI Models**: Flux, Turbo, and fallback providers for maximum reliability - **π‘οΈ Advanced Security**: Content filtering, rate limiting, and input validation - **β‘ High Performance**: 45-second timeout with intelligent fallback system - **π― Customizable Styles**: 7+ built-in styles (photorealistic, artistic, cartoon, cyberpunk, etc.) - **π± React Frontend**: Beautiful, responsive web interface included - **π§ Production Ready**: Enterprise-grade error handling and monitoring - **ποΈ Flexible API**: Support for custom dimensions, seeds, quality levels - **π¦ Rate Limiting**: 10 requests per minute per IP with automatic cleanup ## π Table of Contents - [Quick Start](#quick-start) - [Installation](#installation) - [API Documentation](#api-documentation) - [Frontend Setup](#frontend-setup) - [Configuration](#configuration) - [Deployment](#deployment) - [Contributing](#contributing) - [License](#license) ## π Quick Start ### 1. Import n8n Workflow ```bash # Import the workflow JSON into your n8n instance # File: n8n/image_generate_3.json ``` ### 2. Set Up Frontend ```bash # Navigate to the React app directory cd n8n-image-generator # Install dependencies npm install # Start development server npm start ``` ### 3. Test the API ```bash curl -X POST "https://your-n8n-instance.com/webhook/generate-image" \ -H "Content-Type: application/json" \ -d '{ "message": "A beautiful sunset over mountains", "style": "photorealistic", "size": "1024x1024", "quality": "high" }' ``` ## π§ Installation ### Prerequisites - n8n instance (cloud or self-hosted) - Node.js 16+ (for React frontend) - Domain with SSL certificate (recommended) ### Step-by-Step Setup 1. **Clone the Repository** ```bash git clone https://github.com/YatharthSanghavi/n8n-image-generator.git cd n8n-image-generator ``` 2. **Import n8n Workflow** - Open your n8n instance - Go to Workflows β Import from File - Select `image_generate_3.json` - Activate the workflow 3. **Configure Webhook** - Copy the webhook URL from n8n - Update the endpoint in your frontend configuration 5. **Configure Environment Variables** ```bash # Go to src/ImageGenerator.tsx paste your n8n url here under try section webhookUrl=https://your-n8n-webhook-url.com ``` ## π API Documentation ### Request Body ```json { "message": "Your image description", "style": "photorealistic", "size": "1024x1024", "quality": "high", "seed": 123456, "model": "flux" } ``` ### Parameters | Parameter | Type | Default | Description | |-----------|------|---------|-------------| | `message` | string | **required** | Image description (3-500 characters) | | `style` | string | `photorealistic` | Style preset (see styles below) | | `size` | string | `1024x1024` | Image dimensions (256x256 to 2048x2048) | | `quality` | string | `high` | Quality level: `low`, `medium`, `high` | | `seed` | number | random | Seed for reproducible results | | `model` | string | `flux` | AI model: `flux`, `turbo` by pollinations.ai | ### Available Styles | Style | Description | |-------|-------------| | `photorealistic` | High-quality, photo-like images | | `artistic` | Oil painting, masterpiece style | | `cartoon` | Animated, Disney-like illustrations | | `cyberpunk` | Futuristic, neon-lit sci-fi | | `fantasy` | Magical, mystical artwork | | `minimalist` | Clean, simple, modern design | | `vintage` | Retro, classic, aged aesthetic | ### Response **Success (200)** ``` Content-Type: image/png [Binary image data] ``` **Error (400/429)** ```json { "error": "Error type", "message": "Detailed error message", "code": "ERROR_CODE" } ``` ### Rate Limiting - **Limit**: 10 requests per minute per IP - **Window**: 60 seconds - **Response**: 429 Too Many Requests ## π¨ Frontend Setup The included React frontend provides a beautiful, user-friendly interface for your image generation API. ### Features - **Responsive Design**: Works on all devices - **Real-time Preview**: See parameters as you adjust them - **Gallery View**: Browse generated images - **Download Support**: Save images locally - **Style Presets**: Quick style selection - **Advanced Options**: Seed, model, quality controls ## βοΈ Configuration ### n8n Workflow Settings 1. **Rate Limiting** ```javascript const maxRequestsPerWindow = 10; // Adjust as needed const rateLimitWindow = 60000; // 1 minute ``` 2. **Content Filtering** ```javascript const inappropriateTerms = ['nude', 'naked', 'nsfw', 'explicit']; // Add custom terms to filter ``` 3. **API Providers** ```javascript const apiConfigs = [ { name: 'Pollinations AI - Flux', url: `https://image.pollinations.ai/prompt/${prompt}?model=flux`, priority: 1 } // Add custom providers ]; ``` ## π Deployment ### n8n Workflow 1. **Cloud Deployment** - Use n8n Cloud for easiest setup - Configure webhook URL in your domain ### React Frontend 1. **Netlify/Vercel** ```bash # Build for production npm run build # Deploy to Netlify netlify deploy --prod --dir=build ``` 2. **Traditional Hosting** ```bash npm run build # Upload build/ folder to your web server ``` ## π Monitoring & Analytics ### Built-in Monitoring - Request counting and rate limiting - Error tracking and logging - Performance metrics - Content filter statistics ## π οΈ Advanced Features ### Custom AI Providers Add your own AI image generation APIs: ```javascript const customProvider = { name: 'Custom AI Provider', url: 'https://your-api.com/generate', headers: { 'Authorization': 'Bearer your-token', 'Content-Type': 'application/json' }, transform: (prompt, options) => ({ prompt: prompt, style: options.style, dimensions: options.size }) }; ``` ### Development Setup ```bash # Fork the repository git clone https://github.com/YatharthSanghavi/n8n-image-generator.git cd n8n-image-generator # Install dependencies npm install # Start development server npm run dev ``` ### Contribution Areas - π Bug fixes and improvements - π New AI provider integrations - π¨ Frontend enhancements - π Documentation improvements - π§ͺ Test coverage expansion ## π Roadmap - [ ] **v2.0**: Multi-model support visit here:- [fluxgen](https://github.com/YatharthSanghavi/fluxgen/) - [ ] **v2.1**: Batch processing capabilities - [ ] **v2.2**: Advanced content filtering with AI - [ ] **v2.3**: User authentication and quotas - [ ] **v2.4**: Image editing and variations - [ ] **v2.5**: Mobile app (Flutter) ## π License This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. ## π Acknowledgments - **n8n Team**: For the amazing automation platform - **Pollinations AI**: For providing free AI image generation - **React Community**: For the excellent frontend framework ## π Star History [](https://star-history.com/#YatharthSanghavi/n8n-image-generator&Date) --- <div align="center"> <strong>Made with β€οΈ by Yatharth</strong> <br> <br> <a href="https://github.com/YatharthSanghavi/n8n-image-generator/">β Star this repo if you found it helpful!</a> </div>