|
| 1 | +# Laravel Drift |
| 2 | + |
| 3 | +Optimize images on the fly. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +You can install the package via composer: |
| 8 | + |
| 9 | +``` |
| 10 | +composer require flowframe/laravel-drift |
| 11 | +``` |
| 12 | + |
| 13 | +## Usage |
| 14 | + |
| 15 | +Simply install the package, and register a configuration in `AppServiceProvider@boot`: |
| 16 | + |
| 17 | +```php |
| 18 | +use Flowframe\Drift\Config; |
| 19 | +use Flowframe\Drift\DriftManager; |
| 20 | +use Flowframe\Drift\CachingStrategies\FilesystemCachingStrategy; |
| 21 | + |
| 22 | +/** @var DriftManager $drift */ |
| 23 | +$drift = app(DriftManager::class); |
| 24 | + |
| 25 | +$drift->registerConfig(new Config( |
| 26 | + name: 'my-config-name', // Will be used in the slug |
| 27 | + filesystemDisk: 'filesystems-disk-name', // Local, public or s3 for example |
| 28 | + cachingStrategy: FilesystemCachingStrategy::class, // Create your own or use the defaults like FilesystemCachingStrategy or NullCachingStrategy |
| 29 | +)); |
| 30 | +``` |
| 31 | + |
| 32 | +### Image URLs |
| 33 | + |
| 34 | +To generate an image URL use the `\Flowframe\Drift\UrlBuilder` like so: |
| 35 | + |
| 36 | +```php |
| 37 | +use Flowframe\Drift\UrlBuilder; |
| 38 | + |
| 39 | +/** @var UrlBuilder $builder */ |
| 40 | +$builder = app(UrlBuilder::class); |
| 41 | + |
| 42 | +$image = $builder->url('my-config-name', 'example.png', [ |
| 43 | + 'resize' => [1920, 1080], |
| 44 | + 'encode' => 'webp', // The fallback encoding will be webp |
| 45 | +]); |
| 46 | +``` |
| 47 | + |
| 48 | +You can use most of [Intervention Image's](https://image.intervention.io/v2/usage/overview#editing-images) methods, simply use the method name as key and set the argument as value. Have more than one argument? Use an array instead like in the example above. |
| 49 | + |
| 50 | +### Blade Component |
| 51 | + |
| 52 | +```blade |
| 53 | +<x-drift::image |
| 54 | + class="w-full aspect-[16/9] object-cover" |
| 55 | + config="my-config-name" |
| 56 | + path="example.png" |
| 57 | + :manipulations="[ |
| 58 | + 'encode' => ['jpeg', 50], |
| 59 | + 'greyscale' => true, |
| 60 | + ]" |
| 61 | +/> |
| 62 | +``` |
0 commit comments