How To Resize Image

i have use this code

Yii::$app->params[‘uploadPath’] = Yii::$app->basePath . ‘/uploads/’;

  if ($model->load(Yii::$app->request->post())) {


      $image = UploadedFile::getInstance($model, 'photo');


      $model->photo = $image->name;


      $ext = end((explode(".", $image->name)));


      $model->photo = Security::generateRandomKey().".{$ext}"; 


      $path = Yii::$app->params['uploadPath'] . $model->photo;


      if($model->save()){


        $model->photo;


        $image->saveAs($path);


        return $this->redirect(['view', 'id' => $model->id]);


      }


  } else {


      return $this->render('create', [


          'model' => $model,


      ]);


  }

which coded added…so image resize??

You can use yii2-imagine extension which is available on GitHub.

i know but how to use this code??

One of the usage examples.

In your model:




use yii\imagine\Image;


...


Image::thumbnail($imgPath, $thumbnailWidth, $thumbnailHeight)->save($thumbnailPath);



As I remember $imgPath and $thumbnailPath must be full paths including image name and extension.