- How do I install Intervention/GIF in a Laravel project?
- Run `composer require intervention/gif` in your project directory. The package requires PHP 8.3+, so ensure your Laravel app meets this requirement. No additional Laravel-specific setup is needed beyond Composer installation.
- Can I decode a GIF from a binary stream instead of a file?
- Yes, the `Decoder::decode()` method accepts both file paths and binary content. Pass the raw binary data directly to decode GIFs from HTTP requests, database blobs, or other streams without saving to disk.
- What’s the difference between `Builder` and `Decoder` in this package?
- `Decoder` reads and parses existing GIFs into structured data (e.g., frames, metadata), while `Builder` constructs new GIFs frame-by-frame with custom delays, offsets, and loop settings. Use `Decoder` for analysis and `Builder` for creation.
- Does Intervention/GIF work with Laravel’s service container?
- Absolutely. Bind the `Decoder` or `Builder` classes as singletons in your `AppServiceProvider` for reusable instances. Example: `$this->app->bind(Decoder::class, fn() => new Decoder());` This optimizes performance in high-traffic Laravel apps.
- How do I create an animated GIF with custom frame delays in Laravel?
- Use the `Builder` class: `$gif = Builder::canvas(32, 32);` then chain `addFrame()` with delay values (in seconds). Set loops with `$gif->setLoops(3)` and encode with `$gif->encode()`. Example: `$gif->addFrame('frame1.png', 0.5)->addFrame('frame2.png', 0.5);`
- Will this package work in Laravel without the GD extension?
- Most features work without GD, but the `Splitter` class (for extracting frames as GDImage objects) requires GD. Check `extension_loaded('gd')` before using `Splitter` and implement fallbacks if needed, like queueing jobs to a server with GD.
- Can I validate GIF metadata (e.g., loop count, frame delays) in Laravel forms?
- Yes. Use Laravel’s validation rules with custom callbacks. Example: `$request->validate(['gif' => ['required', function($attribute, $value) { $gif = Decoder::decode($value); if ($gif->getLoops() > 5) return false; }]])` to enforce business rules.
- How do I integrate this with Intervention/Image for unified media processing?
- Create a service class that uses both packages. Inject `Decoder`, `Builder`, and `ImageManager` into a `MediaProcessor` class. Process GIF frames with `Intervention/Image` while preserving metadata using `Intervention/GIF` methods like `getFrames()`.
- What Laravel versions are supported by Intervention/GIF?
- The package requires PHP 8.3+, which aligns with Laravel 10+. For older Laravel versions, use feature flags or polyfills to abstract version-specific dependencies, though some advanced features may not work.
- Are there performance concerns when processing thousands of GIFs daily?
- The package is lightweight, but high-volume processing may require optimization. Benchmark your workflows and consider caching decoded GIFs or offloading tasks to queues. The `Builder` and `Decoder` are stateless, so they scale well in Laravel’s service container.