PHP code example of artkost / yii2-image-style-behavior

1. Go to this page and download the library: Download artkost/yii2-image-style-behavior 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/ */

    

artkost / yii2-image-style-behavior example snippets


use artkost\imagestyle\ImageStyleBehavior;

class ImageFile extends \yii\db\ActiveRecord
{
    public function behaviors()
    {
        return [
            'styles' => [
                'class' => ImageStyleBehavior::className(),
                'path' => '@webroot/uploads/styles',
                'url' => '@web/uploads/styles',
                'attribute' => 'uri',
                'styles' => [
                    'big' => [$this, 'styleBig'], //can be any valid callable
                    'small' => [$this, 'styleSmall']
                ]
            ]
        ];
    }

    /**
     * @return \Imagine\Image\ManipulatorInterface
     */
    public function styleBig()
    {
        return Image::thumbnail($this->filePath, 814, 458)->save($this->style('big')->path);
    }
}

$file = ImageFile::findOne($id);
echo $file->style('big')->url;