fewdji / ii-cache
用于 Laravel 和 Intervention Image Package 的缓存扩展。
dev-master
2023-10-31 19:27 UTC
Requires
- php: >=7.0.0
- illuminate/support: ~5.2
- intervention/image: ~2.4
This package is not auto-updated.
Last update: 2024-09-30 00:10:02 UTC
README
用于 Laravel 和 Intervention Image Package 的缓存扩展
安装
composer require fewdji/ii-cache
设置
为缓存图像的目录创建符号链接
ln -s {PROJECT_DIR}/storage/app/public/images {PROJECT_DIR}/public/images
发布配置文件
php artisan vendor:publish
在 config/ii-cache.php
文件中为您的图像设置预设。所有 InterventionImage 类方法都可用。
'presets' => [
'hq' => [
'widen' => '720',
'watermark' => 'default'
],
'sd' => [
'resize' => ['120', '120'],
'quality' => '85'
]
],
'watermarks' => [
'default' => [
'path' => 'img/copy.png',
'size' => '10',
'position' => 'bottom-right',
'opacity' => '90'
]
]
使用方法
将原始图像放在 storage/app/private/images
目录下。然后您可以通过链接如 images/directory/presetName/imgName.ext
或使用内置的 blade 指令来访问修改后的缓存图像。
@image('tag', ['avatars', 'user1.jpg', 'sd', ['alt' => 'User 1']])
// will output
// <img src="images/avatars/sd/user1.jpg" alt="User 1" />