spatie/image
Expressive PHP image manipulation by Spatie. Load an image, chain operations like resize/crop, rotate, greyscale, brightness, sharpen, and quality, then save. Supports common formats and integrates cleanly in Laravel or any PHP app.
Image::load()->method()->save()) aligns with Laravel’s expressive syntax (e.g., Eloquent, Blade). It can be encapsulated in a service layer (e.g., ImageProcessorService) to abstract business logic from controllers.image.processed or image.failed can be hooked into Laravel’s event system for post-processing (e.g., logging, analytics, or async tasks via queues).composer require + PHP extension enablement (GD/Imagick).config/image.php file.ImageJob) to avoid blocking HTTP requests, especially for large files or batch operations.Image class allows for unit testing without filesystem I/O. Use Laravel’s Storage facade for testing file operations.README and use phpinfo() checks in deployment scripts.if (!extension_loaded('exif')) die('EXIF extension required');).Vips driver or chunk processing for huge files.spatie/laravel-medialibrary for uploads.storage/app/public/processed/{hash}.jpg)?md5(file_path + manipulations))?Storage facade to handle file paths/URLs (e.g., Storage::disk('public')->put()).spatie/laravel-queue-job or Laravel’s native queues for async workflows.ImageProcessed/ImageFailed events to trigger notifications, analytics, or side effects.mimes:jpeg,png,webp) for uploads.route('images.processed', ['path' => 'user.jpg'])).Storage mocks (fake()->disk()) and Queue mocks (Queue::fake()) for unit tests.tests/Feature/ImageProcessingTest.config/services.php:
'image' => [
'driver' => env('IMAGE_DRIVER', 'imagick'), // or 'gd', 'vips'
],
app/Services/ImageProcessor.php):
class ImageProcessor {
public function __construct(private Image $image) {}
public function process(string $path, array $manipulations): string {
$image = $this->image->load($path);
foreach ($manipulations as $method => $args) {
$image->$method(...$args);
}
return $image->save(storage_path("app/public/processed/{$path}.jpg"));
}
}
AppServiceProvider:
$this->app->bind(Image::class, function ($app) {
return Image::useImageDriver(config('image.driver'));
});
app/Jobs/ProcessImageJob.php):
class ProcessImageJob implements ShouldQueue {
public function handle(ImageProcessor $processor) {
$processor->process($this->path, $this->manipulations);
}
}
ProcessImageJob::dispatch($filePath, ['width' => 800, 'height' => 600]);
extension=gd in php.ini.extension=imagick.jcupitt/vips and libvips.spatie/laravel-medialibrary for upload handling if needed.public, s3) for storage.ImageProcessor service class.php artisan queue:work).spatie/image for breaking changes (e.g., v2→v3 migration).How can I help you explore Laravel packages today?