maks757/yii2-imagable

Image saving extension for yii2


Keywords
image, thumbnail, yii2, save
License
GPL-3.0

Documentation

#Instalation

php composer.phar install maks757/yii2-imagable

or add

"maks757/yii2-imagable": "*"

to the require section of your composer.json. #Confiugation After extension is installed you need to setup imagable application component:

'imagable' => [
    'class' => 'maks757\imagable\Imagable',
    'imageClass' => 'maks757\imagable\instances\CreateImageImagine',
    'categories' => [
        'origin' => false,
        'category' => [
            'galery' => [
                'origin' => true,
            ],
            'galery/more' => [
                'origin' => false,
            ],
            'avatars' => [
                'size' => [
                    'big' => [
                        'width' => 1000,
                        'height' => 500,
                    ]
                ]
            ]
        ]
    ]
    ...

#Usage

###Create image

$imageName = \Yii::$app->imagable->create('avatars', 'pathToImage');
// Or
$imageName = \Yii::$app->imagable->createMultiply(['avatars', 'galery/more'], 'pathToImage');

###Get Image

$fullPathToImage = \Yii::$app->imagable->get('avatars', 'big', $imageName);

###Delete Image

$isDeleted = \Yii::$app->imagable->delete('avatars', $imageName);

###Data provider

//To action
/** @var Imagable $image */
$imagable = \Yii::$app->imagable;
$imagable->dataProvider = [
    'key' => $data
];
//...

//To class
class ImageClass extends Object implements CreateImageInterface
{
    public $dataProvider;
    
    public function init()
    {
        parent::init(); // TODO: Change the autogenerated stub
        echo $this->dataProvider['key'];
    }
    
    //...
}