webwizardsusa / laravel-image-cache
Drupal-style image styles for Laravel: Variants generated on demand, when an Image is stored or on a queue, for public and private Images, with optional usage tracking.
Package info
github.com/webwizardsusa/laravel-image-cache
pkg:composer/webwizardsusa/laravel-image-cache
Requires
- php: ^8.3
- illuminate/console: ^12.0 || ^13.0
- illuminate/contracts: ^12.0 || ^13.0
- illuminate/database: ^12.0 || ^13.0
- illuminate/filesystem: ^12.0 || ^13.0
- illuminate/http: ^12.0 || ^13.0
- illuminate/queue: ^12.0 || ^13.0
- illuminate/routing: ^12.0 || ^13.0
- illuminate/support: ^12.0 || ^13.0
- intervention/image: ^4.2
- spatie/laravel-package-tools: ^1.92
Requires (Dev)
- orchestra/testbench: ^11.0
- pestphp/pest: ^5.2
- pestphp/pest-plugin-laravel: ^5.0
Suggests
- ext-imagick: For the imagick driver.
- intervention/image-driver-vips: For the vips driver.
Provides
None
Conflicts
None
Replaces
None
README
Drupal-style image styles for Laravel. Image Styles are classes that transform an Image with Intervention Image into a Variant. Variants are generated on demand (under a lock, so only once), while the Image is stored, or on a queue, and they're tracked so deleting an Image deletes them too. Images are public or private, with temporary URLs for private ones. Optionally, models report the Images they use, and Images nothing uses any more are pruned.
Requires PHP 8.3+, Laravel 12 or 13, and the gd extension (or imagick, or the vips driver).
composer require webwizardsusa/laravel-image-cache php artisan vendor:publish --tag=image-cache-config php artisan vendor:publish --tag=image-cache-migrations php artisan migrate
Usage
use Intervention\Image\Interfaces\ImageInterface; use Webwizardsusa\ImageCache\ImageStyle; class ThumbStyle extends ImageStyle { public static function name(): string { return 'thumb'; } public function apply(ImageInterface $image): ImageInterface { return $image->cover(300, 300); } }
List it in config/image-cache.php ('styles' => [ThumbStyle::class]), then store Images and show their Variants:
use Webwizardsusa\ImageCache\Models\Image; $image = Image::store($request->file('photo')); $image->url('thumb');
<x-image-cache::image :image="$image" image-style="card" :srcset="['thumb', 'card', 'banner']" alt="A cat" />
Documentation
Read the full documentation in the docs folder.