xtracode/yii2-image

There is no license information available for the latest version (dev-master) of this package.

Yii2 image module

Installs: 242

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 1

Forks: 1

Open Issues: 0

Type:yii2-extension

dev-master 2018-08-15 12:23 UTC

This package is not auto-updated.

Last update: 2024-05-25 16:12:19 UTC


README

License Latest Stable Version Latest Unstable Version Total Downloads

Yii2 module for image manipulating.

Documentation is at docs/guide/README.md.

Features

  • image upload
  • display image widget
  • watermark (text and image)
  • image resize on demand

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require "xtracode/yii2-image" "dev-master"

or add

"xtracode/yii2-image" : "dev-master"

to the require section of your application's composer.json file.

Configuration

  • Add module to config section:
'modules' => [
    'image' => [
        'class' => 'xtracode\yii2-image\ImageModule'
    ]
]
  • Run migrations:
php yii migrate --migrationPath=@xtracode/yii2-image/migrations

Usage

  • Add actions to your controller:
public function actions()
{
    return [
        'delete-image' => [
            'class' => '\xtracode\image\actions\DeleteImageAction',
        ],
        'main-image' => [
            'class' => '\xtracode\image\actions\MainImageAction',
        ],
    ];
}

Upload multiple image

Use method $model->uploadSingleImage() in controller:

public function actionCreate()
{
    $model = new Article;

    if ($model->load($_POST) && $model->save()) {
        $model->uploadImage();

        \Yii::$app->session->setFlash('success', \Yii::t('article', 'Article successfully saved'));
        return $this->redirect(['view', 'id' => $model->id]);
    } else {
        return $this->render('create', [
            'model' => $model,
        ]);
    }
}

In view:

<div class="col-sm-offset-1">
    <?= \xtracode\image\widgets\ImageList::widget([
        'model' => $model,
        'model_id' => $model->id,
    ]) ?>
</div>

Upload single image

use method $model->uploadSingleImage() in controller:

public function actionCreate()
{
    $model = new Article;

    if ($model->load($_POST) && $model->save()) {
        $model->uploadSingleImage();

        \Yii::$app->session->setFlash('success', \Yii::t('article', 'Article successfully saved'));
        return $this->redirect(['view', 'id' => $model->id]);
    } else {
        return $this->render('create', [
            'model' => $model,
        ]);
    }
}

In view:

<div class="col-sm-offset-1">
    <?= \xtracode\image\widgets\ImageList::widget([
        'model' => $model,
        'model_id' => $model->id,
    ]) ?>
</div>

For more details see the guide.