vedanshi-shethia / ai-banner-generator
Laravel package to generate website banners using Gemini AI
Package info
github.com/vedanshi-shethia/ai-banner-generator
pkg:composer/vedanshi-shethia/ai-banner-generator
Requires
- php: ^8.1
- illuminate/support: ^9.0|^10.0|^11.0|^12.0
- prism-php/prism: ^0.99
This package is auto-updated.
Last update: 2026-03-29 01:14:10 UTC
README
A driver-based, extensible Laravel package for generating high-quality website banners using AI image models (Gemini, OpenAI, or custom providers).
This package abstracts AI image generation, prompt building, image handling, and storage, while allowing developers to plug in their own AI drivers without touching core logic.
โจ Features
- ๐ Driver-based architecture (Gemini, OpenAI, Null, Custom)
- ๐ง Centralized AI model management
- ๐ผ๏ธ Supports image-to-image generation
- ๐งฉ Fully extensible with custom drivers
- ๐งผ Automatic temporary file cleanup
- ๐ฆ Clean separation of concerns (Service, Drivers, Helpers)
- ๐ก๏ธ Safe base64 image validation before storage
๐ฆ Installation
1๏ธโฃ Install via Composer
composer require vedanshi/ai-banner-generator
2๏ธโฃ Publish Configuration
php artisan vendor:publish --tag=ai-banner-generator
This will create:
config/ai-banner-generator.php
3๏ธโฃ Configure Storage
Ensure your output disk is publicly accessible.
php artisan storage:link
๐ Environment variables
AI_BANNER_DRIVER = 'driver_name' # Storage GEMINI_INPUT_DISK=local GEMINI_OUTPUT_DISK=public
๐ง Storage Design (Important)
This package follows industry best practices:
| Type | Disk | Visibility |
|---|---|---|
| Input images | local |
๐ Private |
| Generated banners | public |
๐ Public |
storage/
โโโ app/
โ โโโ private/
โ โ โโโ banner/input/
โ โโโ public/
โ โโโ banner/output/
โ๏ธ Configuration (config/ai-banner-generator.php)
return [ /* |-------------------------------------------------------------------------- | Driver Configuration |-------------------------------------------------------------------------- */ 'driver' => env('AI_BANNER_DRIVER', 'gemini'), 'drivers' => [ 'gemini' => [ 'model' => env('GEMINI_MODEL', 'gemini-2.5-flash-image'), 'api_key' => env('GEMINI_API_KEY'), ], 'openai' => [ 'model' => env('OPENAI_MODEL', 'gpt-4o-mini'), 'api_key' => env('OPENAI_API_KEY'), ], ], /* |-------------------------------------------------------------------------- | Storage Configuration |-------------------------------------------------------------------------- */ 'disks' => [ 'input' => env('BANNER_INPUT_IMAGE_DISK', 'local'), // private 'output' => env('BANNER_OUTPUT_IMAGE_DISK', 'public'), // public ], 'paths' => [ // Input uploads 'front' => 'banner/front', 'back' => 'banner/back', 'reference' => 'banner/ref', // Output (generated banners) 'output' => 'banner/output', ], 'cleanup' => [ 'enabled' => true, ], /* |-------------------------------------------------------------------------- | Output Configuration |-------------------------------------------------------------------------- */ 'output' => [ 'format' => 'png', 'allowed_mime_types' => ['image/png', 'image/jpeg'], ], ];
๐ Important
- Users switch models only via config
- No runtime config injection
- Drivers stay clean and predictable
๐ง Architecture Overview
Controller / App
โ
BannerService
โ
BannerDriverFactory
โ
Driver (Gemini / OpenAI / Custom)
โ
AI Model
Key Components
| Layer | Responsibility |
|---|---|
| Service | Business flow |
| Factory | Driver resolution |
| Driver | AI interaction |
| Helpers | Image / prompt handling |
| Storage | File persistence |
๐งฉ Banner Generation Flow
- Input images are uploaded
- Images are loaded & converted to Base64
- Prompt is generated
- Driver is resolved
- AI generates banner
- Image is validated & stored
- Temporary files are cleaned
- Public URL is returned
๐ Usage
1๏ธโฃ Sync Generation (Facade)
use Vedanshi\Banner\Facades\Banner; use Vedanshi\Banner\Http\Requests\BannerGenerationRequest; function (BannerGenerationRequest $request) { $result = Banner::generate($request->payload()); }
Returns a public URL of the generated banner.
2๏ธโฃ Async Generation (Queue)
use Vedanshi\Banner\Jobs\BannerGenerationJob; use Vedanshi\Banner\Http\Requests\BannerGenerationRequest; function (BannerGenerationRequest $request) { BannerGenerationJob::dispatch($request->payload()); }
โ Ideal for:
- Heavy image processing
- High-traffic systems
- Background workflows
๐งพ Expected Payload Structure
[
'front_image' => string, // path on input disk
'back_image' => string, // path on input disk
'transparent_image' => string, // path on input disk
'product_name' => string,
]
โ ๏ธ Do NOT pass temp paths (
php/tmp). Files must be stored first using Laravel storage.
๐งน Automatic Cleanup
- Input images are deleted immediately after successful generation
- Cleanup is retry-safe
- Cleanup can be disabled via config
'cleanup' => [ 'enabled' => false, ],
๐ผ๏ธ Image Handling & Safety
Before storing the generated image:
data:image/*;base64,...is handled- Strict Base64 decoding
- Image validity is verified
- MIME type is validated
ImageStorage::store($base64);
This prevents:
- Invalid data storage
- Corrupt images
- Security risks
๐ Built-in Drivers
Gemini Driver
new GeminiDriver($config);
Uses Prism internally for image generation.
OpenAI Driver
new OpenAIDriver($config);
Abstracted behind the same interface.
Null Driver
new NullDriver($config);
Useful for:
- Testing
- CI pipelines
- Fallback mode
๐งฉ Creating a Custom Driver (User Extensible)
1๏ธโฃ Implement the Contract
use Vedanshi\Banner\Contracts\BannerDriver; class MyDriver implements BannerDriver { public function __construct(protected array $config) {} public function generate(string $prompt, array $images): string { // Custom AI logic return $base64; } }
2๏ธโฃ Register the Driver
use Vedanshi\Banner\Factory\BannerDriverFactory; BannerDriverFactory::extend('my-driver', function ($config) { return new MyDriver($config); });
3๏ธโฃ Add Key in .env
AI_BANNER_DRIVER = 'my-driver'
๐ Done โ no core code touched.
๐ง Why This Design Works
- โ Manager-controlled configuration
- โ No runtime config injection
- โ Clean SOLID design
- โ Laravel-style driver extension
- โ Production-ready
This is the same architecture Laravel uses for Cache, Queue, Mail, and Filesystems.
๐งช Testing
Use the null driver:
AI_BANNER_DRIVER = 'null'
This avoids API calls and allows fast testing.
๐ Summary
- AI-agnostic banner generation
- Driver-based extensibility
- Safe image handling
- Clean separation of concerns
- Enterprise-grade Laravel architecture
๐ License
MIT License
๐ Credits
Developed by Vedanshi Shethia
๐ค Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss improvements.