pxlrbt/filament-image-compare
Installation:
composer require pxlrbt/filament-image-compare
Ensure your Laravel project is using Filament v3 (check compatibility in the README).
First Use Case:
Add the entry to a Filament Resource or Page via an Infolist:
use Pxlrbt\FilamentImageCompare\ImageCompareEntry;
Infolist::columns(2)->schema([
ImageCompareEntry::make()
->leftImage(fn ($record) => $record->before_image)
->rightImage(fn ($record) => $record->after_image),
]);
Where to Look First:
ImageCompareEntry.php for configuration options and default props.tests/ for edge cases (e.g., missing images, non-square ratios).Dynamic Image Sources: Use closures for flexibility (e.g., API responses, computed paths):
ImageCompareEntry::make()
->leftImage(fn ($record) => $record->getOriginal('image_before'))
->rightImage(fn ($record) => Storage::disk('s3')->url($record->image_after));
Conditional Rendering: Hide the entry if either image is missing:
ImageCompareEntry::make()
->leftImage(fn ($record) => optional($record->before_image)->path)
->rightImage(fn ($record) => optional($record->after_image)->path)
->hidden(fn ($record) => !$record->before_image || !$record->after_image);
Custom Styling:
Override default CSS via Filament’s tailwind config or inline styles:
->extraAttributes(['class' => 'h-64 w-full'])
->extraAttributes(['style' => 'border: 2px solid #3b82f6'])
Integration with Forms:
Pair with FileUpload for editable comparisons (e.g., A/B testing):
use Filament\Forms\Components\FileUpload;
Forms\Components\Group::make([
FileUpload::make('before_image')->image(),
FileUpload::make('after_image')->image(),
]);
->image() on FileUpload to defer image processing.->height()/->width():
->height('300px')->width('auto')
__() helper.Image Paths:
storage/app/image.jpg) may break in production.Storage::url():
->leftImage(fn ($record) => Storage::disk('public')->url($record->path))
Missing Images:
->leftImage(fn ($record) => $record->before_image ?? 'path/to/fallback.jpg')
CORS Issues:
imgix/Cloudinary for dynamic URLs.Filament Version Mismatch:
schema() syntax.src attributes).debug mode in config/filament.php for entry rendering errors.Custom Comparison Logic: Override the default slider behavior by extending the component:
class CustomCompareEntry extends ImageCompareEntry {
protected function getView(): string {
return 'custom-image-compare';
}
}
Add Metadata:
Include alt text or captions via extraAttributes:
->extraAttributes(['aria-label' => 'Before/After Comparison'])
Server-Side Processing: Use Laravel queues to generate comparison thumbnails for performance:
->leftImage(fn ($record) => route('images.compare', ['id' => $record->id, 'side' => 'left']))
Accessibility: Add keyboard navigation or ARIA labels for screen readers:
->extraAttributes([
'role' => 'region',
'aria-label' => 'Side-by-side image comparison',
])
How can I help you explore Laravel packages today?