yiicod/yii2-easyimage
Composer 安装命令:
composer require yiicod/yii2-easyimage
包简介
Yii 2 Framework extension for easy creating and caching thumbnails in real time.
README 文档
README
You don't need to create many types of thumbnails for images in your project.
You can create a thumbnail directly in the View. Thumbnail will automatically cached. It's easy!
Features:
- Easy to use
- Support
Imagick,GmagickandGD2 - Automatically images caching
- Cache sorting to subdirectories
Installing and configuring
Add the following to your config file components section:
'easyimage' => [ 'class' => 'yiicod\easyimage\EasyImage', 'webrootAlias' => '@frontend/web', 'cachePath' => '/uploads/easyimage/', 'imageOptions' => [ 'quality' => 100 ], ],
Parameters
- string
webrootAliaswebroot folder path - string
cachePathcache directory path in webroot folder - array
imageOptionsarray with default output image options which will used by Imagine to save image
Usage
Yii::$app->easyimage->getUrl($file, $params, $absolute); //Get cached image url Yii::$app->easyimage->getPath($file, $params); //Get cached image path Note: you can get access to the component using static method EasyImage::getInstance()
Parameters
- string
$filerequired - Image file path - array
$paramsimage tools params Default: [] - mixed
$absoluteget absolute (true) url or not (false). Will use in Url::to() helper method
Available tools and parameters
'crop' => [ 'width' => 200, //Required 'height' => 200, //Required 'offset_x' => 100, 'offset_y' => 100, ], 'flip' => [ 'axis' => 'vertical', //Required available 'vertical' or 'horizontal' ], 'resize' => [ 'width' => 200, //Required 'height' => 200, //Required ], 'scale' => [ 'width' => 200, //Required 'height' => 200, //Required ], 'rotate' => [ 'angle' => 45 //Required ], 'thumbnail' => [ 'width' => 100, //Required one of dimensions 'height' => 100, //Required one of dimensions ], 'watermark' => [ 'image' => $file, //Required 'offset_x' => 100, 'offset_y' => 100, ], 'background' => [ 'color' => '#000', //Required 'alpha' => 0 //Background color's alpha ],
Tools
You can add additional tools in config:
'easyimage' => [ 'class' => 'yiicod\easyimage\EasyImage', 'webrootAlias' => '@frontend/web', 'cachePath' => '/uploads/easyimage/', 'tools' => [ 'crop' => Crop::class, ], ],
- 'crop' - tool name which will use in getUrl() or getPath() params
- Crop::class - tool class name which must implement yiicod\easyimage\base\ToolInterface
统计信息
- 总下载量: 1.56k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-08-25