lireincore/yii2-imgcache

The lireincore/imgcache integration for the Yii2 framework

Installs: 2 745

Dependents: 0

Suggesters: 0

Security: 0

Stars: 5

Watchers: 0

Forks: 2

Open Issues: 0

Type:yii2-extension

0.6.0 2019-11-10 13:50 UTC

This package is auto-updated.

Last update: 2024-04-10 23:48:51 UTC


README

Latest Stable Version Total Downloads License

About

The 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

$ 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

return [
    'srcdir' => '@app/files/images',
    'destdir' => '@webroot/thumbs',
    'webdir' => '@webroot',
    'baseurl' => '@web',
    //....
    'presets' => [
        'origin' => [
            'effects' => [
                //add the effects you need
                //....
            ],
        ],
    ],
];

See lireincore/imgcache README.md for more information about the available effects and other config options.

Also add the following code in your Yii2 application configuration:

$config = [
    //....
    'container' => [
        //....
        'singletons'  => [
            //....
            LireinCore\Yii2ImgCache\ImgCache::class => [
                ['class' => LireinCore\Yii2ImgCache\ImgCache::class],
                [
                    require(__DIR__ . '/imgcache.php'),
                ]
            ],
        ]
    ],
];

Use in your code:

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 for more information about the available functions.

License

This project is licensed under the MIT License - see the License File file for details