- How do I install Spatie Image in a Laravel project?
- Run `composer require spatie/image` in your project directory. The package requires PHP 8.1+ and at least one image processing extension (GD, Imagick, or Vips). Imagick is recommended for advanced features like WebP support.
- Which Laravel versions does Spatie Image support?
- The package is compatible with Laravel 9.x and 10.x. Check the [documentation](https://spatie.be/docs/image/v3/introduction) for version-specific notes, as minor updates may align with Laravel releases.
- Can I use Spatie Image with Laravel’s Storage facade?
- Yes. Load images from Laravel’s filesystem using `Storage::disk('public')->path('image.jpg')` or directly from `storage_path()`. The package integrates seamlessly with Laravel’s storage system for local or cloud-based assets.
- How do I process images asynchronously in Laravel queues?
- Wrap image operations in a Laravel job (e.g., `ImageProcessJob`). Use `Image::load()->resize()->save()` inside the job’s `handle()` method. This avoids blocking HTTP requests and is ideal for large files or batch processing.
- What’s the best driver for production: GD, Imagick, or Vips?
- Imagick is the most feature-rich (supports WebP, advanced filters) but requires installation. GD is lightweight and widely available but lacks some formats. Vips is fast for large images but less commonly used. Benchmark with your workload—Imagick is often the best balance.
- How do I handle mobile uploads with incorrect EXIF orientation?
- Enable the `exif` PHP extension (usually included in Laravel’s default setup) and use `Image::load()->autoOrient()->save()`. This automatically corrects rotated images from devices like smartphones.
- Can I use Spatie Image to generate dynamic thumbnails in API responses?
- Absolutely. Load an image, apply transformations (e.g., `fit(200, 200)`), and stream the result directly in a controller: `return response()->stream(fn() => Image::load($path)->encode(), 200, ['Content-Type' => 'image/jpeg']);`
- What are the memory limits for processing large images?
- Large images (e.g., 10MB+) may hit PHP’s memory limit. Monitor usage with `memory_get_usage()` and chunk processing for batches. For cloud storage (S3), stream files instead of loading entirely into memory.
- How do I integrate Spatie Image with Eloquent model observers?
- In an observer’s `saving` or `saved` method, use `Image::load(storage_path('app/' . $model->image_path))->resize()->save()`. This auto-processes images when models are saved, like resizing uploads on-the-fly.
- Are there alternatives to Spatie Image for Laravel?
- Yes. For simpler needs, consider `intervention/image` (older but widely used). For cloud-optimized workflows, `spatie/media-library` pairs with this package. For headless CMS integrations, `spatie/laravel-medialibrary` extends image handling further.