Thumb::make()   B
last analyzed

Complexity

Conditions 9
Paths 128

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 9
eloc 6
c 2
b 0
f 0
nc 128
nop 5
dl 0
loc 11
rs 7.8222
1
<?php
2
3
namespace whallysson;
4
5
use CodeBlog\Thumb\Thumb as Cropper;
6
7
/**
8
 * Class Thumb
9
 *
10
 * @author Whallysson Avelino <https://github.com/whallysson>
11
 * @package Source\Support
12
 */
13
class Thumb
14
{
15
16
    /** @var Cropper */
17
    private $cropper;
18
19
    /** @var string */
20
    private $uploads;
21
22
    /**
23
     * Thumb constructor.
24
     */
25
    public function __construct()
26
    {
27
        $this->cropper = new Cropper(CONF_IMAGE_CACHE, null, CONF_IMAGE_QUALITY['jpg'], CONF_IMAGE_QUALITY['png']);
28
        $this->uploads = CONF_UPLOAD_DIR;
29
    }
30
31
    /**
32
     * @return string
33
     */
34
    public function make($image, $width, $height = null, $zc = null, $imageName = null)
35
    {
36
        $sz = ($width ? "?w={$width}" : null);
37
        $sz .= (empty($sz) && !empty($height) ? "?h={$width}" : (!empty($sz) && !empty($height) ? "&h={$height}" : null));
38
        $sz .= (!empty($zc) ? "&zc={$zc}" : null);
39
40
        if (file_exists("{$this->uploads}/{$image}") && is_file("{$this->uploads}/{$image}")) {
41
            return $this->cropper->imgCreate("{$this->uploads}/{$image}{$sz}", $imageName);
42
        }
43
44
        return $this->cropper->imgCreate("{$image}{$sz}", $imageName);
45
    }
46
47
    /**
48
     * @param string|null $image
49
     */
50
    public function flush($image = null)
51
    {
52
        if ($image) {
53
            $this->cropper->flush("{$this->uploads}/{$image}");
54
            return;
55
        }
56
57
        $this->cropper->flush();
58
        return;
59
    }
60
61
    /**
62
     * @return Cropper
63
     */
64
    public function cropper()
65
    {
66
        return $this->cropper;
67
    }
68
69
}
70