01ebf78c
Administrator
Initial commit
|
1
2
3
4
5
6
7
|
<?php
namespace backend\controllers;
use backend\components\croppers\CropContext;
use backend\components\croppers\CropFactory;
|
d3e38cf8
Administrator
Adding transliter...
|
8
|
use backend\components\Helper;
|
01ebf78c
Administrator
Initial commit
|
9
|
use Yii;
|
f9404a23
Administrator
Start gallery
|
10
|
use yii\helpers\FileHelper;
|
3ff61e27
Administrator
Adding basic gallery
|
11
|
use yii\helpers\StringHelper;
|
01ebf78c
Administrator
Initial commit
|
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
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();
|
bfa22e8e
Administrator
Adding resizing a...
|
31
|
$minHeight = $cropFactory->findMinHeight();
|
01ebf78c
Administrator
Initial commit
|
32
33
34
|
$cropContext = new CropContext($cropFactory->getCrop($crop_id));
foreach($model->imageFiles as $file) {
|
d3e38cf8
Administrator
Adding transliter...
|
35
36
|
$baseName = Helper::transliterate($file->baseName);
$path = dirname(dirname(__DIR__)) . '/uploads/' . $baseName . '.' . $file->extension;
|
01ebf78c
Administrator
Initial commit
|
37
|
$image = Yii::$app->imagine->open($path);
|
bfa22e8e
Administrator
Adding resizing a...
|
38
39
40
|
$image = $cropContext->cropImage($image, $path);
$box = $image->getSize()->heighten($minHeight);
$image->resize($box)
|
d3e38cf8
Administrator
Adding transliter...
|
41
|
->save(dirname(dirname(__DIR__)) . '/uploads/' . $baseName . '-resized' . '.' . $file->extension);
|
01ebf78c
Administrator
Initial commit
|
42
43
44
45
46
|
}
}
return $this->render('index', ['model' => $model, 'ukrSeeds' => $ukrSeeds]);
}
|
f9404a23
Administrator
Start gallery
|
47
48
49
|
public function actionGallery()
{
$files = FileHelper::findFiles(dirname(dirname(__DIR__)) . '/uploads/');
|
bfa22e8e
Administrator
Adding resizing a...
|
50
51
52
53
54
55
56
57
58
59
|
$images = [];
foreach($files as $file) {
$a = getimagesize($file);
$image_type = $a[2];
if(in_array($image_type , [IMAGETYPE_GIF , IMAGETYPE_JPEG ,IMAGETYPE_PNG , IMAGETYPE_BMP]))
{
$images[] = '/uploads/' . StringHelper::basename($file);
}
|
3ff61e27
Administrator
Adding basic gallery
|
60
|
}
|
bfa22e8e
Administrator
Adding resizing a...
|
61
|
return $this->render('gallery', ['files' => $images]);
|
f9404a23
Administrator
Start gallery
|
62
63
|
}
|
01ebf78c
Administrator
Initial commit
|
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
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);
}
}
|
bfa22e8e
Administrator
Adding resizing a...
|
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
public function actionDownloadAll()
{
$files = FileHelper::findFiles(dirname(dirname(__DIR__)) . '/uploads/');
$zip = new \ZipArchive();
$filename = dirname(dirname(__DIR__)) . '/uploads/images.zip';
$zip->open($filename, \ZipArchive::CREATE);
foreach($files as $k => $file) {
$a = getimagesize($file);
$image_type = $a[2];
if(in_array($image_type , [IMAGETYPE_GIF , IMAGETYPE_JPEG ,IMAGETYPE_PNG , IMAGETYPE_BMP]))
{
$zip->addFile($file, StringHelper::basename($file));
}
}
$zip->close();
$response = Yii::$app->response;
$response->sendFile($filename);
}
|
01ebf78c
Administrator
Initial commit
|
99
|
}
|