BaseController.php
827 Bytes
1
2
3
4
5
6
7
8
9
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
40
<?php
/**
* Created by PhpStorm.
* User: Cibermag
* Date: 31.08.2015
* Time: 9:58
*/
namespace backend\components\base;
use yii\web\Controller;
class BaseController extends Controller {
private function resizeImg($w, $h, $imageAlias,$imageAliasSave){
$img = Image::getImagine()->open(Yii::getAlias($imageAlias));
$size = $img->getSize();
$ratio = $size->getWidth()/$size->getHeight();
$height = $h;
$width = round($height * $ratio);
$imagine = new Imagine();
$imagine->open($imageAlias)
->resize(new Box($width, $h))
->save($imageAlias, array('flatten' => false));
Image::crop($imageAlias, $w, $h,[($width/2)-($w/2),0])
->save(Yii::getAlias($imageAliasSave), ['quality' =>
100]);
}
}