README.md or DEPLOYMENT.md.config/color-extractor.php):
return [
'default_background' => '#FFFFFF',
'max_colors' => 5,
];
Log::debug('Color extraction completed', [
'image' => $path,
'colors' => $colors,
'duration_ms' => $duration,
]);
Palette with a background color.docs/ folder covering:
/health/color-extractor) to verify GD and extraction functionality:
Route::get('/health/color-extractor', function () {
if (!extension_loaded('gd')) {
return response()->json(['status' => 'error', 'message' => 'GD extension missing'], 500);
}
$palette = Palette::fromFilename(public_path('assets/health-check.png'));
return response()->json(['status' => 'ok', 'colors' => $palette->getMostUsedColors(3)]);
});
php artisan queue:work --daemon) to handle concurrent extractions.memory_limit in php.ini for large images (e.g., 256M or 512M).$cacheKey = "color_palette:{$imagePath}";
$palette = cache()->remember($cacheKey, now()->addHours(1), function () use ($imagePath) {
return Palette::fromFilename($imagePath);
});
| Failure Scenario | Impact | Mitigation |
|---|---|---|
| GD extension missing | Extraction fails silently | Validate GD at runtime; provide fallback (e.g., Imagick or API proxy). |
| Unreadable image file | InvalidArgumentException |
Log errors; retry or return cached/default palette. |
| Large image (OOM) | PHP crashes or timeouts | Resize images pre-extraction; increase memory limit. |
| Transparent images (unexpected) | Incorrect color palettes | Document transparency handling; provide config for background blending. |
| Queue worker crashes | Pending extractions pile up | Implement dead-letter queues; monitor worker health. |
| Database/cache failures | Cached palettes stale | Fallback to live extraction; alert ops team. |
| High concurrency | Queue backlog | Scale workers; implement bulk processing. |
// app/Http/Controllers/ColorController.php
public function extract(Request $request) {
$image = $request->file('image');
$palette = Palette::fromFilename($image->getPathname());
return response()->json(['palette' => $palette->getMostUsedColors(5)]);
}
@php
$palette = Palette::fromFilename(storage_path('app/product.jpg'));
$primary = $palette->getMostUsedColors(1)[0] ?? '#000000';
@endphp
<div style="background-color: {{ League\ColorExtractor\Color::fromIntToHex($primary) }};">
Dynamic theming!
</div>
How can I help you explore Laravel packages today?