Blame view

backend/controllers/ImageController.php 1.68 KB
01ebf78c   Administrator   Initial commit
1
2
3
4
5
6
7
8
  <?php
  
  namespace backend\controllers;
  
  use backend\components\croppers\CropContext;
  use backend\components\croppers\CropFactory;
  
  use Yii;
f9404a23   Administrator   Start gallery
9
  use yii\helpers\FileHelper;
01ebf78c   Administrator   Initial commit
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
  use yii\web\Controller;
  use backend\models\UploadForm;
  use yii\web\UploadedFile;
  
  class ImageController extends Controller
  {
      public function actionIndex()
      {
          $request = Yii::$app->request;
          $model = new UploadForm();
          $ukrSeeds = Yii::$app->params['ukrSeeds'];
  
          if ($request->isPost) {
              $model->imageFiles = UploadedFile::getInstances($model, 'imageFiles');
              $model->upload();
  
              $crop_id = $request->post('crop_id');
  
              $cropFactory = CropFactory::getInstance();
              $cropContext = new CropContext($cropFactory->getCrop($crop_id));
  
              foreach($model->imageFiles as $file) {
                  $path = dirname(dirname(__DIR__)) . '/uploads/' . $file->baseName . '.' . $file->extension;
                  $image = Yii::$app->imagine->open($path);
                  $cropContext->cropImage($image, $path);
              }
          }
          return $this->render('index', ['model' => $model, 'ukrSeeds' => $ukrSeeds]);
      }
  
f9404a23   Administrator   Start gallery
40
41
42
43
44
45
      public function actionGallery()
      {
          $files = FileHelper::findFiles(dirname(dirname(__DIR__)) . '/uploads/');
          return $this->render('gallery', ['files' => $files]);
      }
  
01ebf78c   Administrator   Initial commit
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
      public function actionGetParams($crop_id)
      {
          if (Yii::$app->request->isAjax) {
  
              $cropFactory = CropFactory::getInstance();
  
              $res = [
                  'body'    => $cropFactory->getCrop($crop_id)->getConstants(),
                  'success' => true,
              ];
  
              return json_encode($res);
          }
      }
  }