gfh151 / yii2-image-resize
一个用于调整图片大小(并缓存)的Yii2组件
v0.0.6
2021-05-24 14:35 UTC
Requires
- yiisoft/yii2: ^2.0
- yiisoft/yii2-imagine: ^2.0.0
README
一个用于调整图片大小并将其存储在缓存文件夹中的Yii2组件
安装
安装此扩展的首选方式是通过 composer.
- 运行以下命令之一
php composer require "fgh151/yii2-image-resize" "*"
或
"fgh151/yii2-image-resize" : "*"
将以下内容添加到您的应用程序的 composer.json
文件的require部分。
- 在应用程序配置文件的
components
部分添加一个新的组件,例如
'components' => [ 'imageresize' => [ 'class' => 'fgh151\imageresize\ImageResize', //path web root 'cachePath' => '@frontend/web', //path where to store thumbs 'cacheFolder' => 'upload/thumb', //use filename (seo friendly) for resized images else use a hash 'useFilename' => true, //show full url (for example in case of a API) 'absoluteUrl' => false, ], ],
使用方法
如果您想获取图片URL
/* * $sImageFilePath_id: (required) path to file * $width/$height: (required) width height of the image * $mode: "outbound" or "inset" * $$quality: (1 - 100) * $chosenFileName: if config -> components -> imageresize -> useFilename is true? its an option to give a custom name else use original file name */ \Yii::$app->imageresize->getUrl($imageFile, $width, $height, $mode, $quality, $chosenFileName);