https://github.com/lireincore/yii2-imgcache
The imgcache integration for Yii2 framework
https://github.com/lireincore/yii2-imgcache
cache effect image php preset resize thumb thumbnail yii2 yii2-extension
Last synced: about 1 year ago
JSON representation
The imgcache integration for Yii2 framework
- Host: GitHub
- URL: https://github.com/lireincore/yii2-imgcache
- Owner: lireincore
- License: mit
- Created: 2017-03-17T17:47:11.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2019-11-10T13:51:11.000Z (over 6 years ago)
- Last Synced: 2025-03-25T15:35:23.668Z (about 1 year ago)
- Topics: cache, effect, image, php, preset, resize, thumb, thumbnail, yii2, yii2-extension
- Language: PHP
- Homepage:
- Size: 13.7 KB
- Stars: 5
- Watchers: 0
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.MD
- License: LICENSE
Awesome Lists containing this project
README
# Image effect, thumb and cache extension for Yii2
[](https://packagist.org/packages/lireincore/yii2-imgcache)
[](https://packagist.org/packages/lireincore/yii2-imgcache)
[](https://packagist.org/packages/lireincore/yii2-imgcache)
## About
The [lireincore/imgcache](https://github.com/lireincore/imgcache) integration for Yii2 framework.
## Install
Add the `"lireincore/yii2-imgcache": "^0.6"` package to your `require` section in the `composer.json` file
or
``` bash
$ php composer.phar require lireincore/yii2-imgcache
```
## Usage
To use this extension, you need to create the `imgcache.php` file in your `config` folder and add this code:
```php
'@app/files/images',
'destdir' => '@webroot/thumbs',
'webdir' => '@webroot',
'baseurl' => '@web',
//....
'presets' => [
'origin' => [
'effects' => [
//add the effects you need
//....
],
],
],
];
```
See `lireincore/imgcache` [README.md](https://github.com/lireincore/imgcache/blob/master/README.md) for more information about the available effects and other config options.
Also add the following code in your Yii2 application configuration:
```php
$config = [
//....
'container' => [
//....
'singletons' => [
//....
LireinCore\Yii2ImgCache\ImgCache::class => [
['class' => LireinCore\Yii2ImgCache\ImgCache::class],
[
require(__DIR__ . '/imgcache.php'),
]
],
]
],
];
```
Use in your code:
```php
use LireinCore\Yii2ImgCache\ImgCache;
$imgCache = Yii::$container->get(ImgCache::class);
// get thumb url for image '{srcdir}/blog/image.jpg' (preset 'origin')
$url = $imgcache->url('blog/image.jpg', 'origin');
// get thumb url for image '{srcdir}/blog/image.jpg' (preset 'origin')
$url = \Yii::$app->imgcache->url('blog/image.jpg', 'origin');
```
See `lireincore/imgcache` [README.md](https://github.com/lireincore/imgcache/blob/master/README.md) for more information about the available functions.
## License
This project is licensed under the MIT License - see the [License File](LICENSE) file for details