alex-bond / yii2-thumbler
自动创建图像缩略图的库
1.2.0
2016-09-14 21:21 UTC
Requires
- php: >=5.4.0
- stefangabos/zebra_image: 2.2.*
- symfony/filesystem: *
- yiisoft/yii2: *
README
为 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()
清除所有缓存。