drishu / yii2-imagecache

更好的图片缓存

安装次数: 55

依赖者: 0

建议者: 0

安全: 0

星标: 2

关注者: 2

分支: 0

开放问题: 0

类型:yii2-extension

1.0.6 2015-07-14 20:23 UTC

This package is auto-updated.

Last update: 2024-09-06 16:50:52 UTC


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'))?>```