- How do I install Intervention Image Laravel in my Laravel 9/10 project?
- Run `composer require intervention/image-laravel` in your project root. The package auto-registers its service provider, so no manual bootstrapping is needed. Publish the config file with `php artisan vendor:publish --provider="Intervention\Image\Laravel\ServiceProvider"` to customize driver settings (GD/Imagick) globally.
- What’s the difference between using this package vs. raw Intervention Image in Laravel?
- This package adds Laravel-specific features like a facade (`Image::make()`), publishable config (`config/image.php`), and a `response()->image()` macro for API responses. It also centralizes driver settings (GD/Imagick) to avoid per-call configuration, reducing boilerplate.
- Can I switch between GD and Imagick drivers dynamically in production?
- No, the driver is set in `config/image.php` and applies globally. For dynamic switching, extend the package or use environment-based configs (e.g., `.env` overrides). Test fallback logic if Imagick fails (e.g., `try-catch` blocks around `Image::make()`).
- How do I use the facade in a Laravel controller to resize an uploaded image?
- Use `Image::make($filePath)->resize(300, 200)->save($destination)`. The facade is a shortcut for `app('image')->make()`. For file uploads, access the file via `$request->file('image')->store()` or `$request->image->path()`.
- Does this package support async image processing with Laravel queues?
- Yes, but avoid the facade in queue jobs (global state risks). Instead, inject the `ImageManager` via constructor: `public function __construct(private ImageManager $image)`. Process images in `handle()` and use `dispatch()` for async execution.
- How do I handle memory limits when processing large images (e.g., 10MB+)?
- Increase `memory_limit` in `php.ini` or use chunked processing: `Image::make($file)->stream()->resize()->save()`. For APIs, stream responses directly: `return response()->streamDownload($stream, 'image.jpg')`. Test with `ini_set('memory_limit', '512M')` in development.
- Can I cache processed images to avoid reprocessing the same file?
- Yes, use Laravel’s filesystem (e.g., `storage/app/public`) or a CDN. Implement a cache key like `md5($originalPath.$width.$height)`. For dynamic URLs, append query params: `/images/{hash}?w=300`. Clear cache when originals update.
- What Laravel versions are supported, and are there breaking changes?
- This package supports Laravel 8+. Breaking changes are rare but may occur with major Intervention Image updates. Check the [changelog](https://github.com/Intervention/image-laravel/blob/main/CHANGELOG.md) for version-specific notes. Test upgrades in a staging environment.
- How do I test image processing in PHPUnit without hitting memory limits?
- Mock the `ImageManager` in tests: `$this->partialMock(ImageManager::class, ['make'])->willReturn($mockImage)`. Use small test images (e.g., 100x100px) and set `ini_set('memory_limit', '128M')` in `phpunit.xml`. Test edge cases like corrupt files with `Image::make()->exceptionOnNotFound(false)`.
- Are there alternatives to this package for Laravel image processing?
- Alternatives include `spatie/laravel-image-optimization` (for optimization), `league/glide` (serverless-friendly), or raw Intervention Image. This package is ideal for Laravel-specific needs like facades, response macros, and centralized config. Compare based on your stack (e.g., Glide for cloud storage).