9217ef8e
Administrator
09.02.16
|
1
2
3
4
|
<?php
namespace common\behaviors;
|
6676fbc7
Administrator
28.04.16 перенес ...
|
5
|
use common\modules\file\components\UploaderComponent;
|
9217ef8e
Administrator
09.02.16
|
6
7
8
9
10
11
|
use yii;
use yii\base\Behavior;
class ShowImage extends Behavior
{
function minImg($dir, $width, $height=null){
|
1aca8918
Administrator
09.02.16
|
12
|
if(empty($dir)){
|
0eb4e7fc
Yarik
test
|
13
|
return '/images/avatar-bg.png';
|
1aca8918
Administrator
09.02.16
|
14
15
|
}
|
9217ef8e
Administrator
09.02.16
|
16
17
18
|
if($width=='original'){
$preg = '/\/(.[^\/]*)$/';
preg_match('/\.(.[^.]*)$/', $dir, $type);
|
df799956
Administrator
16.03.16
|
19
20
21
22
|
if(isset($type[1])){
$dir = preg_replace( $preg, '/original.'.$type[1], $dir);
}
|
9217ef8e
Administrator
09.02.16
|
23
24
25
|
} else {
$preg = '/\/(.[^\/]*)$/';
preg_match('/\.(.[^.]*)$/', $dir, $type);
|
df799956
Administrator
16.03.16
|
26
27
|
if(isset($type[1])){
$dir = preg_replace( $preg, '/'.$width.'x'.$height.'.'.$type[1], $dir);
|
6676fbc7
Administrator
28.04.16 перенес ...
|
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
$storage = dirname(yii\helpers\Url::to('@storage'));
$filename = $storage.$dir;
if (!file_exists($filename)) {
$original = $storage.dirname($dir).'/original.'.$type[1];
if (file_exists($original)) {
$resizer = new UploaderComponent();
$resizer->resizeImg($width,$height, $original,$filename);
} else {
throw new \Exception("Файл $original не существует");
}
}
|
df799956
Administrator
16.03.16
|
43
44
|
}
|
9217ef8e
Administrator
09.02.16
|
45
46
|
}
|
df799956
Administrator
16.03.16
|
47
|
return $dir;
|
9217ef8e
Administrator
09.02.16
|
48
49
50
51
|
}
|
34e7b1a4
Administrator
15.02.16
|
52
53
54
55
56
57
58
59
60
61
62
63
|
function ShowGallery($array){
$gallery = explode(',', $array );
if(is_array($gallery)){
array_splice($gallery,-1);
return $gallery;
} else {
return [];
}
}
|
1a7bb1e7
Administrator
09.02.16
|
64
|
|
9217ef8e
Administrator
09.02.16
|
65
|
}
|