elgorm/yii2-uploadable-cropable-image

Yii2 extension for upload and crop images

This package's canonical repository appears to be gone and the package has been frozen as a result.

Installs: 132

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 10

Type:yii2-extension

v2.2.4 2015-10-20 07:25 UTC

This package is not auto-updated.

Last update: 2020-01-28 20:12:24 UTC


README

Yii2 extension for upload and crop images

Latest Version Software License Quality Score Code Climate Total Downloads

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist elgorm/yii2-uploadable-cropable-image "*"

or add

"elgorm/yii2-uploadable-cropable-image": "*"

to the require section of your composer.json file.

Usage

Once the extension is installed, simply use it in your code by :

In your model:

public function behaviors()
{
    return [
        [
            'class' => \elgorm\image\Behavior::className(),
            'savePathAlias' => '@web/images/',
            'urlPrefix' => '/images/',
            'crop' => true,
            'attributes' => [
                'avatar' => [
                    'savePathAlias' => '@web/images/avatars/',
                    'urlPrefix' => '/images/avatars/',
                    'width' => 100,
                    'height' => 100,
                ],
                'logo' => [
                    'crop' => false,
                    'thumbnails' => [
                        'mini' => [
                            'width' => 50,
                        ],
                    ],
                ],
            ],
        ],
    //other behaviors
    ];
}

Use rules for validate attribute.

In your view file:

echo $form->field($model, 'avatar')->widget('elgorm\image\Widget');

After, in your view:

echo Html::img($model->getImageUrl('avatar'));
echo Html::img($model->getImageUrl('logo', 'mini')); //get url of thumbnail named 'mini' for 'logo' attribute

If you use Advanced App Template and this behavior attached in backend model, then in frontend model add trait

use \elgorm\image\GetImageUrlTrait

and use getImageUrl() method for frontend model too.