Yii2 module for image manipulating.
Documentation is at docs/guide/README.md.
- image upload
- display image widget
- watermark (text and image)
- image resize on demand
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.
- Add module to config section:
'modules' => [
'image' => [
'class' => 'xtracode\yii2-image\ImageModule'
]
]
- Run migrations:
php yii migrate --migrationPath=@xtracode/yii2-image/migrations
- Add actions to your controller:
public function actions()
{
return [
'delete-image' => [
'class' => '\xtracode\image\actions\DeleteImageAction',
],
'main-image' => [
'class' => '\xtracode\image\actions\MainImageAction',
],
];
}
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>
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.