enstart / glide
enstart 框架对 Glide(按需图像处理)的包装
0.1.0
2017-07-01 13:19 UTC
Requires
- php: >=7.0
- league/glide: ^1.2
- league/glide-symfony: ^1.0
This package is not auto-updated.
Last update: 2024-09-25 02:21:31 UTC
README
enstart 框架对 Glide(按需图像处理)的包装
依赖项
enstart/core
版本 0.2+- PHP 7.0+,并使用 gd- 或 imagick 库之一
安装
composer require enstart/glide
配置
// Settings
'glide' => [
'source' => /path/to/upload/folder,
'cache' => /path/to/cache/folder',
],
// Register the service provider
'providers' => [
...
'Enstart\Ext\Glide\ServiceProvider',
],
可选设置
还有一些可选设置
'glide' => [
// If you want to make sure that all resize-requests are from your app, you can
// add a sign key. This prevents mass image-resize attacks
'sign_key' => 'a-128-bit-random-key',
// The default driver is 'gd', but if you rather use imagick, simply change it
'driver' => 'imagick',
// To set some presets (predefined manipulators) which you then access through `?p=thumb`
'presets' => [
'thumb' => [
'w' => 200,
'h' => 200,
'fit' => 'crop',
],
],
]
要了解更多关于 glide 的设置,请访问 Glides 文档。此包只是将 glide
-config 传递给 Glide,因此 Glide 文档中提到的任何内容在此处也适用。
访问扩展
// Get a copy of the instance
$glide = $app->container->make('Enstart\Ext\Glide\Glide');
// or through the alias:
$app->glide
// or through dependency injection (if you type hint it in your constructor)
use Enstart\Ext\ImageResize\Glide;
获取缩放图像的链接
在你的代码中
$url = $app->glide->getResizedImage('/path/to/image.jpg', [
'w' => 200,
'h' => 200,
'fit' => crop
]);
// or through a preset
$url = $app->glide->getResizedImage('/path/to/image.jpg', ['p' => 'thumb']);
// alternative preset request
$url = $app->glide->getResizedImage('/path/to/image.jpg', 'thumb');
视图辅助函数
当你处于视图状态时,你可以使用视图辅助函数
<img src="<?= $this->glide('/path/to/image.jpg', 'thumb') ?>" />
路径相对于配置中的源文件夹。视图辅助函数接受与上述 $app->glide->getResizedImage()
方法相同的所有参数;
路由
有一个名为(glide
)的路由,也具有相同的别名(glide
)。任何对 yoursite.com/glide/{anything}
的请求都将由扩展处理。
如果你希望更改路由别名,只需在 routes.php 中创建一个具有相同名称的新路由。
$app->get('/something-else/(:all)', function ($file) use ($app) {
return $app->glide->getResizedImage($file, $app->request->get()->all());
}, ['name' => 'glide']);
删除文件
仅删除缓存文件
$app->glide->deleteCache('/path/to/image.jpg');
删除缓存和原始文件
$app->glide->remove('/path/to/image.jpg');