drishu / yii2-imagecache
更好的图片缓存
1.0.6
2015-07-14 20:23 UTC
Requires
- yiisoft/yii2: *
README
更好的图片缓存
安装
安装此扩展的首选方式是通过 composer。
运行以下命令之一
php composer.phar require --prefer-dist drishu/yii2-imagecache "*"
或
"drishu/yii2-imagecache": "*"
将以下内容添加到您的 composer.json
文件的 require 部分中。
imageCache 组件配置
您应在应用程序配置中添加 imageCache 组件。
$config = [ 'components' => [ ... 'imagecache' => [ 'class' => 'drishu\yii2imagecache\ImageCache', // the below paths depend very much on your image upload setup 'sourcePath' => Yii::getAlias('@base'), // base path to your uploads dir 'cachePath' => '/data', // relative path to your uploads dir ], ... ], ];
用法
在您的视图、控制器、组件等中,只需调用
<?= Html::img(Yii::$app->imagecache->get($image->path, '0x160'))?>```