alex-bond/yii2-thumbler

自动创建图像缩略图的库

安装数: 2,015

依赖项: 0

建议者: 0

安全性: 0

星标: 10

关注者: 3

分支: 4

开放性问题: 0

类型:yii2-extension

1.2.0 2016-09-14 21:21 UTC

This package is auto-updated.

Last update: 2024-09-24 19:57:40 UTC


README

Gitter Chat

为 Yii 2 提供的带有自动缓存的图像缩放器

此扩展允许缩放图像并自动缓存它们。

安装

安装此扩展的首选方式是通过 composer

运行以下命令之一

php composer.phar require --prefer-dist alex-bond/yii2-thumbler

或将以下内容添加到您的 composer.json 的 require 部分

"alex-bond/yii2-thumbler": "*"

使用方法

要使用此扩展,您需要在应用程序配置中添加以下代码

return [
    //....
    'components' => [
        'thumbler'=> [
            'class' => 'alexBond\thumbler\Thumbler',
            'sourcePath' => '/path/to/source/files',
            'thumbsPath' => '/path/to/resize/cache',
        ],
    ],
];

之后,只需像这样调用 resize() 方法

$path = \Yii::$app->thumbler->resize('image.png',500,500);

此调用结果将返回相对于 $thumbsPath 的缩放图像路径。

方法

resize($image, $width, $height, $method = Thumbler::METHOD_NOT_BOXED, $backgroundColor = 'ffffff', $callExceptionOnError = true)

getLastError()

返回最后错误描述。

clearImageCache($image)

清除选定图像文件的全部缓存。

clearAllCache()

清除所有缓存。