Commit 55bd0bb9f0db81fb629eed7df86c1e19c95bdd35
1 parent
282b6e56
Commit
Showing
9 changed files
with
118 additions
and
40 deletions
Show diff stats
common/behaviors/ShowImage.php
1 | 1 | <?php |
2 | - | |
2 | + | |
3 | 3 | namespace common\behaviors; |
4 | - | |
4 | + | |
5 | 5 | use common\modules\file\components\UploaderComponent; |
6 | 6 | use yii; |
7 | 7 | use yii\base\Behavior; |
8 | - | |
8 | + use yii\imagine\Image; | |
9 | + | |
9 | 10 | class ShowImage extends Behavior |
10 | 11 | { |
11 | - | |
12 | + | |
12 | 13 | /** |
13 | 14 | * Resize image and return its path. |
14 | 15 | * |
... | ... | @@ -24,14 +25,14 @@ |
24 | 25 | if(empty( $dir )) { |
25 | 26 | return '/images/imageNotFound.jpg'; |
26 | 27 | } |
27 | - | |
28 | + | |
28 | 29 | if($width == 'original') { |
29 | 30 | $preg = '/\/(.[^\/]*)$/'; |
30 | 31 | preg_match('/\.(.[^.]*)$/', $dir, $type); |
31 | 32 | if(isset( $type[ 1 ] )) { |
32 | 33 | $dir = preg_replace($preg, '/original.' . $type[ 1 ], $dir); |
33 | 34 | } |
34 | - | |
35 | + | |
35 | 36 | } else { |
36 | 37 | $preg = '/\/(.[^\/]*)$/'; |
37 | 38 | preg_match('/\.(.[^.]*)$/', $dir, $type); |
... | ... | @@ -40,32 +41,27 @@ |
40 | 41 | $storage = dirname(yii\helpers\Url::to('@storage')); |
41 | 42 | $filename = $storage . $dir; |
42 | 43 | if(!file_exists($filename)) { |
43 | - | |
44 | + | |
44 | 45 | $original = $storage . dirname($dir) . '/original.' . $type[ 1 ]; |
45 | 46 | $resizer = new UploaderComponent(); |
46 | 47 | if(file_exists($original)) { |
47 | 48 | $resizer->resizeImg($width, $height, $original, $filename); |
48 | 49 | } else { |
49 | - | |
50 | - $imageNotFound = yii\helpers\Url::to('@storage')."/imageNotFound".$width."x".$height.".jpg"; | |
51 | - if(!file_exists($imageNotFound)){ | |
52 | - $resizer->resizeImg($width, $height, yii\helpers\Url::to('@storage')."/imageNotFound.jpg", $imageNotFound ); | |
50 | + $imageNotFound = yii\helpers\Url::to('@storage') . "/imageNotFound" . $width . "x" . $height . ".jpg"; | |
51 | + if(!file_exists($imageNotFound)) { | |
52 | + $resizer->resizeImg($width, $height, yii\helpers\Url::to('@storage') . "/imageNotFound.jpg", $imageNotFound); | |
53 | 53 | } |
54 | - return "/storage/imageNotFound".$width."x".$height.".jpg"; | |
55 | - | |
56 | - | |
54 | + return "/storage/imageNotFound" . $width . "x" . $height . ".jpg"; | |
57 | 55 | } |
58 | - | |
56 | + | |
59 | 57 | } |
60 | - | |
58 | + | |
61 | 59 | } |
62 | - | |
60 | + | |
63 | 61 | } |
64 | - | |
65 | 62 | return $dir; |
66 | - | |
67 | 63 | } |
68 | - | |
64 | + | |
69 | 65 | /** |
70 | 66 | * @param string $array String to split |
71 | 67 | * |
... | ... | @@ -73,23 +69,71 @@ |
73 | 69 | */ |
74 | 70 | function ShowGallery($array) |
75 | 71 | { |
76 | - | |
72 | + | |
77 | 73 | $gallery = explode(',', $array); |
78 | 74 | if(is_array($gallery)) { |
79 | 75 | array_splice($gallery, -1); |
80 | 76 | return $gallery; |
81 | 77 | } else { |
82 | - return [ ]; | |
78 | + return []; | |
83 | 79 | } |
84 | - | |
80 | + | |
85 | 81 | } |
86 | - | |
87 | - public function ShowAvatar($dir, $width, $height = NULL) { | |
88 | - if(empty($dir)) { | |
82 | + | |
83 | + public function ShowAvatar($dir, $width, $height = NULL) | |
84 | + { | |
85 | + if(empty( $dir )) { | |
89 | 86 | return '/images/avatar-bg.png'; |
90 | 87 | } else { |
91 | 88 | return $this->minImg($dir, $width, $height); |
92 | 89 | } |
93 | 90 | } |
94 | - | |
91 | + | |
92 | + /** | |
93 | + * Add watermark to image | |
94 | + * | |
95 | + * @param string $path image path | |
96 | + * | |
97 | + * @return yii\base\Component | |
98 | + */ | |
99 | + public function watermark($path) | |
100 | + { | |
101 | + $watermark_path = Yii::getAlias('@webroot/images/watermark.png'); | |
102 | + $image = Image::getImagine() | |
103 | + ->open($path); | |
104 | + $watermark = Image::getImagine() | |
105 | + ->open($watermark_path); | |
106 | + $image_size = $image->getSize(); | |
107 | + $watermark_size = $watermark->getSize(); | |
108 | + if($image_size->getWidth() < ($watermark_size->getWidth() + 20) || ($image_size->getHeight() + 20) < $watermark_size->getHeight()) { | |
109 | + return $this->owner; | |
110 | + } | |
111 | + $position_left = $image_size->getWidth() - ($watermark_size->getWidth() + 10); | |
112 | + Image::watermark($path, $watermark_path, [$position_left, 10])->save(preg_replace('/^(.*)(\.\w+)$/', '${1}_watermark${2}', $path)); | |
113 | + return $this->owner; | |
114 | + } | |
115 | + | |
116 | + function getWatermark($path, $width, $height = NULL) | |
117 | + { | |
118 | + if($width == 'original') { | |
119 | + $path_original = $this->minImg($path, 'original'); | |
120 | + $path_watermark = str_replace('original', 'original_watermark', $path_original); | |
121 | + if(!file_exists(Yii::getAlias('@documentRoot').$path_watermark)) { | |
122 | + $this->watermark(Yii::getAlias('@documentRoot').$path_original); | |
123 | + } | |
124 | + return $path_watermark; | |
125 | + } else { | |
126 | + $path_original = $this->minImg($path, $width, $height); | |
127 | + preg_match('/^.*(\.\w+)$/', $path_original, $extension); | |
128 | + $path_watermark = $path_original; | |
129 | + if(isset($extension[1])) { | |
130 | + $path_watermark = str_replace($extension[1], '_watermark'.$extension[1], $path_original); | |
131 | + } | |
132 | + if(!file_exists(Yii::getAlias('@documentRoot').$path_watermark)) { | |
133 | + $this->watermark(Yii::getAlias('@documentRoot').$path_original); | |
134 | + } | |
135 | + return $path_watermark; | |
136 | + } | |
137 | + } | |
138 | + | |
95 | 139 | } |
96 | 140 | \ No newline at end of file | ... | ... |
common/models/Portfolio.php
... | ... | @@ -10,6 +10,7 @@ |
10 | 10 | use yii\behaviors\TimestampBehavior; |
11 | 11 | use yii\db\ActiveQuery; |
12 | 12 | use yii\db\Expression; |
13 | + use yii\base\Component; | |
13 | 14 | |
14 | 15 | /** |
15 | 16 | * This is the model class for table "portfolio". |
... | ... | @@ -34,6 +35,8 @@ |
34 | 35 | * @property Rating[] $rating |
35 | 36 | * @property string $ratingValue |
36 | 37 | * @method string minImg( string $dir, $width, $height = NULL ) Resizes image |
38 | + * @method Component watermark(string $path) Add watermark to image | |
39 | + * @method string getWatermark(string $path, mixed $width, mixed $height) Get watermarked image | |
37 | 40 | * @method array ShowGallery( string $array ) Splits string to image paths array |
38 | 41 | */ |
39 | 42 | class Portfolio extends \yii\db\ActiveRecord | ... | ... |
frontend/views/company/portfolio-view.php
... | ... | @@ -40,7 +40,7 @@ |
40 | 40 | if(!empty( $portfolio_user )) { |
41 | 41 | echo Html::img($portfolio->minImg(ArrayHelper::getValue($portfolio_user_gallery, 0, ''), '720', '280')); |
42 | 42 | } else { |
43 | - echo Html::img($portfolio->minImg($portfolio->cover, '720', '280')); | |
43 | + echo Html::img($portfolio->getWatermark($portfolio->cover, '720', '280')); | |
44 | 44 | } |
45 | 45 | ?> |
46 | 46 | </div> |
... | ... | @@ -122,7 +122,7 @@ |
122 | 122 | foreach($portfolio->ShowGallery($portfolio->gallery->photo) as $one_photo) { |
123 | 123 | ?> |
124 | 124 | <li> |
125 | - <img src="<?= $portfolio->minImg($one_photo, 210, 150) ?>" alt=""/> | |
125 | + <img src="<?= $portfolio->getWatermark($one_photo, 210, 150) ?>" data-original="<?=$portfolio->getWatermark($one_photo, 720, 280)?>" alt=""/> | |
126 | 126 | </li> |
127 | 127 | <?php |
128 | 128 | } | ... | ... |
frontend/views/performer/blog-view.php
... | ... | @@ -4,9 +4,11 @@ |
4 | 4 | * @var Blog $article |
5 | 5 | */ |
6 | 6 | use common\models\Blog; |
7 | - | |
7 | + use yii\helpers\Html; | |
8 | + use yii\helpers\Url; | |
9 | + | |
8 | 10 | $this->params[ 'user' ] = $user; |
9 | - | |
11 | + | |
10 | 12 | $this->title = $article->name; |
11 | 13 | ?> |
12 | 14 | <div class="performer-vacancy-vacant-title-reclam-wr style"> |
... | ... | @@ -29,6 +31,22 @@ |
29 | 31 | <div class="blog-post-content style"> |
30 | 32 | <?= $article->description ?> |
31 | 33 | </div> |
34 | + <div class="share-buttons-new"> | |
35 | + <p class="share-buttons-new-title">Поделиться</p> | |
36 | + <p class="share-buttons-new-link"> | |
37 | + <?php | |
38 | + echo Html::a(Html::img('/images/ico-vk.png'), 'http://vk.com/share.php?url=' . Url::current([], true), [ | |
39 | + 'target' => '_blank', | |
40 | + ]); | |
41 | + echo Html::a(Html::img('/images/ico-fb.png'), 'http://www.facebook.com/sharer/sharer.php?u=' . Url::current([], true), [ | |
42 | + 'target' => '_blank', | |
43 | + ]); | |
44 | + echo Html::a(Html::img('/images/ico-google.png'), 'https://plus.google.com/share?url=' . Url::current([], true), [ | |
45 | + 'target' => '_blank', | |
46 | + ]); | |
47 | + ?> | |
48 | + </p> | |
49 | + </div> | |
32 | 50 | </div> |
33 | 51 | </div> |
34 | 52 | <?php | ... | ... |
frontend/views/performer/portfolio-view.php
... | ... | @@ -7,6 +7,7 @@ |
7 | 7 | use yii\helpers\ArrayHelper; |
8 | 8 | use yii\helpers\Html; |
9 | 9 | use yii\helpers\Url; |
10 | + use yii\imagine\Image; | |
10 | 11 | use yii\web\ViewAction; |
11 | 12 | use yii\web\View; |
12 | 13 | use yii\widgets\Pjax; |
... | ... | @@ -42,7 +43,7 @@ |
42 | 43 | if(!empty( $portfolio_user )) { |
43 | 44 | echo Html::img($portfolio->minImg(ArrayHelper::getValue($portfolio_user_gallery, 0, ''), '720', '280')); |
44 | 45 | } else { |
45 | - echo Html::img($portfolio->minImg($portfolio->cover, '720', '280')); | |
46 | + echo Html::img($portfolio->getWatermark($portfolio->cover, '720', '280')); | |
46 | 47 | } |
47 | 48 | ?> |
48 | 49 | </div> |
... | ... | @@ -124,7 +125,7 @@ |
124 | 125 | foreach($portfolio->ShowGallery($portfolio->gallery->photo) as $one_photo) { |
125 | 126 | ?> |
126 | 127 | <li> |
127 | - <img src="<?= $portfolio->minImg($one_photo, 210, 150) ?>" alt="" data-original="<?=$portfolio->minImg($one_photo, 720, 280)?>"/> | |
128 | + <img src="<?= $portfolio->getWatermark($one_photo, 210, 150) ?>" alt="" data-original="<?=$portfolio->getWatermark($one_photo, 720, 280)?>"/> | |
128 | 129 | </li> |
129 | 130 | <?php |
130 | 131 | } |
... | ... | @@ -141,7 +142,6 @@ |
141 | 142 | } |
142 | 143 | ?> |
143 | 144 | </div> |
144 | - | |
145 | 145 | <div class="new-portfolio-txt-wrapper style"> |
146 | 146 | <div class="new-portfolio-excerpt style"> |
147 | 147 | <?php | ... | ... |
frontend/web/css/style.css
... | ... | @@ -12623,4 +12623,17 @@ li.active-menu-admin:hover a .ico_num { |
12623 | 12623 | |
12624 | 12624 | .left-search-work .admin-specialization-selected ul li:before { |
12625 | 12625 | right: 8px; |
12626 | +} | |
12627 | +.share-buttons-new { | |
12628 | + margin-top: 10px; | |
12629 | + float: left; | |
12630 | +} | |
12631 | +.share-buttons-new .share-buttons-new-title { | |
12632 | + text-transform: uppercase; | |
12633 | + font-size: 15px; | |
12634 | + font-weight: bold; | |
12635 | +} | |
12636 | +.share-buttons-new .share-buttons-new-link a { | |
12637 | + margin-top: 5px; | |
12638 | + margin-right: 10px; | |
12626 | 12639 | } |
12627 | 12640 | \ No newline at end of file | ... | ... |
2.52 KB
4.27 KB
storage/.htaccess