codificar/yii2imagecache
Composer 安装命令:
composer require codificar/yii2imagecache
包简介
ImageCache for Yii2
README 文档
README
Yii2 ImageCache
Biblioteca desenvolvida pela Codificar .
Based in yii2-imagecache
Installation
The preferred way to install this helper is through composer.
Either run
php composer.phar require "codificar/yii2imagecache" "0.0.5"
or add
"codificar/yii2imagecache" : "0.0.5"
to the require section of your application's composer.json file.
Configuration
You should :
- Add
ThumbActionin one of your controller. - Modify your application configuration :
- add imageCache component,
- add url rule to handle request to missing thumbs.
Add ThumbAction
You need to add ThumbAction in one of your controller so that imageCache can handle requests to missing thumbs and create them on demand. You could use site controller :
class SiteController extends Controller { ... public function actions() { return [ ... 'thumb' => 'codificar\yii2imagecache\ThumbAction', ... ]; } ... }
imageCache component config
You should add imageCache component in your application configuration :
$config = [ 'components' => [ ... 'imageCache' => [ 'class' => 'iutbay\yii2imagecache\ImageCache', 'sourcePath' => '@app/web/images', 'sourceUrl' => '@web/images', //'thumbsPath' => '@app/web/thumbs', //'thumbsUrl' => '@web/thumbs', //'sizes' => [ // 'thumb' => [150, 150], // 'medium' => [300, 300], // 'large' => [600, 600], //], ], ... ], ];
urlManager config
You should modify your urlManager configuration :
$config = [ 'components' => [ ... 'urlManager' => [ 'enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => [ ... 'thumbs/<path:.*>' => 'site/thumb', ... ], ], ... ], ];
How to use
<?= Yii::$app->imageCache->thumb('/your-app/images/2014/test.jpg') ?> // <img src="/your-app/thumbs/2014/test_thumb.jpg" alt=""> <?= Yii::$app->imageCache->thumbSrv('/your-app/images/2014/test.jpg') ?> // url_string ="/your-app/thumbs/2014/test_medium.jpg"
统计信息
- 总下载量: 2.64k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-07-21