intervention/gif
Native PHP GIF encoder/decoder for GIF data streams with no image extensions required. Decode files or binary content, and build animated GIFs via a Builder. Includes optional GD-based Splitter to extract frames into GDImage objects. Supports PHP 8.3+.
Decoder, Builder, Splitter) aligns seamlessly with Laravel’s service-oriented architecture. The Decoder and Builder classes can be registered as Laravel services, enabling dependency injection and testability. For example:
$this->app->bind(Decoder::class, fn() => new Decoder());
$this->app->bind(Builder::class, fn() => new Builder());
Intervention/Image, this package extends Laravel’s existing image-processing pipeline. Use cases like resizing GIF frames before encoding or validating GIF metadata alongside static images are straightforward. Example:
use Intervention\Image\Facades\Image;
use Intervention\Gif\Facades\Gif;
$image = Image::make($frame)->resize(320, 240);
$gif->addFrame($image->encode(), 0.5);
use Illuminate\Validation\Rule;
$request->validate([
'gif' => ['required', 'file', Rule::gif()->maxFrames(10)->maxDuration(5)],
]);
Gif::decode(), Gif::build()) to provide a fluent, framework-native API. Example:
namespace App\Facades;
use Illuminate\Support\Facades\Facade;
class Gif extends Facade { protected static function getFacadeAccessor() { return 'gif'; } }
Storage facade can handle file I/O for GIF operations, ensuring consistency with other media types. Example:
use Illuminate\Support\Facades\Storage;
$contents = Storage::disk('s3')->get('animations/frame.gif');
$gif = Gif::decode($contents);
GifEncoded, GifDecoded). Example:
event(new GifEncoded($gifData, auth()->id()));
Listen for these events in service providers or controllers to log, notify, or cache GIF operations.GifEncodeJob) to handle high-volume workloads without blocking the request. Example:
GifEncodeJob::dispatch($request->file('gif'), $userId)->onQueue('gifs');
Splitter class requires GD to extract frames from animated GIFs, which may not be available in all environments (e.g., serverless, shared hosting).if (!extension_loaded('gd')) {
throw new RuntimeException('GD extension required for animated GIF frame extraction.');
}
Image or imagick) via a decorator pattern:
interface FrameExtractor { public function extractFrames(string $gifData): array; }
class GdFrameExtractor implements FrameExtractor { ... }
class FallbackFrameExtractor implements FrameExtractor { ... }
benchmark() helper:
$time = benchmark(fn() => Gif::decode($largeGif));
Storage facade with chunked reads/writes.use Illuminate\Validation\Rule;
Rule::gif()->validate($request->file('gif'));
class ValidateGifMiddleware { public function handle($request, Closure $next) { ... } }
spatie/laravel-ffmpeg).Image)?Intervention/Image for hybrid workflows (e.g., resizing GIF frames)? If so, how will dependencies be managed?Decoder and Builder for dependency injection. Example:
$this->app->singleton(Decoder::class, fn() => new Decoder());
$this->app->singleton(Builder::class, fn() => new Builder());
Gif::decode(), Gif::build()) to integrate seamlessly with Laravel’s syntax.max_frames, max_duration).Intervention/Image for static image processing with Intervention/Gif for animated content. Example:
use Intervention\Image\Facades\Image;
use Intervention\Gif\Facades\Gif;
$image = Image::make($frame)->resize(320, 240);
$gif = Gif::build()->addFrame($image->encode(), 0.5);
Splitter class (GD-dependent) to extract frames from animated GIFs for further processing (e.g., resizing, filtering).Storage facade to handle file operations (e.g., reading from S3, writing to local storage) with consistency across media types.Phase 1: Core Integration
Decoder and Builder to provide a Laravel-native API.Phase 2: Advanced Features
Intervention/Image for hybrid workflows (e.g., resizing GIF frames).How can I help you explore Laravel packages today?