예제 #1
0
 /**
  * @return string
  * @throws \yii\base\Exception
  */
 public function actionCropImg()
 {
     $path = Cloud::getInstance()->cloudPath;
     $pathWeb = Cloud::getInstance()->webCloudPath;
     FileHelper::createDirectory($path);
     $filename = basename(Yii::$app->request->post('imgUrl'));
     // original sizes
     $imgInitW = Yii::$app->request->post('imgInitW');
     $imgInitH = Yii::$app->request->post('imgInitH');
     // resized sizes
     $imgW = Yii::$app->request->post('imgW');
     $imgH = Yii::$app->request->post('imgH');
     // offsets
     $imgX1 = Yii::$app->request->post('imgX1');
     $imgY1 = Yii::$app->request->post('imgY1');
     // crop box
     $cropW = Yii::$app->request->post('cropW');
     $cropH = Yii::$app->request->post('cropH');
     // rotation angle
     $angle = Yii::$app->request->post('rotation');
     $originalImage = Image::getImagine()->open($path . $filename);
     $cropFilename = strtr($filename, ['big_' => 'crop_']);
     $originalImage->resize(new Box($imgW, $imgH))->rotate($angle)->crop(new Point($imgX1, $imgY1), new Box($cropW, $cropH));
     $originalImage->save($path . $cropFilename);
     if (strpos($filename, 'big_') === 0) {
         unlink($path . $filename);
     }
     $json['status'] = 'success';
     $json['url'] = Url::to($pathWeb . $cropFilename, true);
     return Json::encode($json);
 }