PHP code example of yii2mod / yii2-image

1. Go to this page and download the library: Download yii2mod/yii2-image library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

yii2mod / yii2-image example snippets


'components' => [
    'image' => [
        'class' => 'yii2mod\image\ImageComponent',
    ],
],

public function behaviors()
{
    return [
        'image' => [
            'class' => ImageBehavior::class,
            'pathAttribute' => 'path',
        ],
    ];
}

public function actions()
{
    return [
        'image' => 'yii2mod\image\actions\ImageAction'
    ];
}

'params' => [
    'image' => [
        'medium' => [
            'thumbnail' => [
                'box' => [194, 194],
                'mode' => 'outbound'
            ],
            'visible' => 'user', //checking role before outputing url
        ],
        'home' => [
            'thumbnail' => [
                'box' => [640, 480],
                'mode' => 'inset',
            ],
            'watermark' => [
                'watermarkFilename' => '@app/web/images/watermark.png',
            ],
        ],
    ],
],

$model = Model::find()->one();
echo $model->url('medium'); // home is the type of photo.

php composer.phar