geofftech / laravel-imagestyle
2.3.1
2024-08-15 12:30 UTC
Requires
- php: ^8.2
- illuminate/console: ^11.20
- illuminate/support: ^11.1
- intervention/image: ^3.5
Requires (Dev)
- laravel/pint: ^1.17
README
- 调整和存储图像,如缩略图或原始图像
- 调整后的图像存储在专门的 '缓存' 磁盘上,以与实际数据分离
- 通过生成一个指向调整后文件的URL来工作
- 如果查看该URL,它最初会命中一个路由,该路由生成并保存该调整后的图像
- 这使用了这样一个概念:实际文件将在处理路由之前始终被提供
使用 Intervention Images
示例属性
public function thumbnailUrl(): Attribute { return Attribute::make( get: fn () => img($this->image)->thumbnail() ); }
配置
1. 配置缓存磁盘
- 创建并链接一个新本地磁盘
- 编辑
/config/filesystem.php
- 添加一个缓存磁盘
'disks' => [ ... 'cache' => [ 'driver' => 'local', 'root' => storage_path('app/cache'), 'url' => env('APP_URL') . '/cache', 'visibility' => 'public', 'throw' => false, ], ],
2. 添加存储链接条目
'links' => [ public_path('storage') => storage_path('app/public'), public_path('cache') => storage_path('app/cache'), ],
3. 运行存储链接
a storage:link
- 现在可以从域名中的
/cache
文件夹访问/storage/app/cache
文件夹中的文件