Completed
Push — develop ( 92230b...218aa8 )
by Peter
02:10
created

ImageThumb   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 5
Bugs 1 Features 2
Metric Value
wmc 6
c 5
b 1
f 2
lcom 0
cbo 6
dl 0
loc 73
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A createReflection() 0 4 1
A createWhitespaceCropper() 0 4 1
A createSharpen() 0 4 1
A create() 0 10 2
A createWatermark() 0 4 1
1
<?php
2
3
/**
4
 * Webino (https://github.com/webino/)
5
 *
6
 * @link      https://github.com/webino/WebinoImageThumb/ for the canonical source repository
7
 * @copyright Copyright (c) 2013-2016 Webino, s. r. o. (http://webino.sk/)
8
 * @license   BSD-3-Clause
9
 */
10
11
namespace WebinoImageThumb\Service;
12
13
use PHPThumb\Plugins;
14
use PHPThumb\GD as PHPThumb;
15
use WebinoImageThumb\Exception;
16
use WebinoImageThumb\PhpThumb\Plugin as ExtraPlugins;
17
18
/**
19
 * Image Thumbnailer service
20
 *
21
 * Image thumbnailer powered by PHPThumb (https://github.com/masterexploder/PHPThumb)
22
 */
23
class ImageThumb
24
{
25
    /**
26
     * Create image thumbnail object
27
     *
28
     * @param string $filename
29
     * @param array $options
30
     * @param array $plugins
31
     * @return PHPThumb
32
     */
33
    public function create($filename = null, array $options = [], array $plugins = [])
34
    {
35
        try {
36
            $thumb = new PHPThumb($filename, $options, $plugins);
37
        } catch (\Exception $exc) {
38
            throw new Exception\RuntimeException($exc->getMessage(), $exc->getCode(), $exc);
39
        }
40
41
        return $thumb;
42
    }
43
44
    /**
45
     * Create reflection plugin
46
     *
47
     * @param int $percent
48
     * @param int $reflection
49
     * @param int $white
50
     * @param bool $border
51
     * @param string $borderColor hex
52
     * @return Plugins\Reflection
53
     */
54
    public function createReflection($percent, $reflection, $white, $border, $borderColor)
55
    {
56
        return new Plugins\Reflection($percent, $reflection, $white, $border, $borderColor);
57
    }
58
59
    /**
60
     * Create a plugin to crop the whitespace surrounding an image
61
     *
62
     * @param int $border
63
     * @param int $color
64
     * @return ExtraPlugins\WhitespaceCropper
65
     */
66
    public function createWhitespaceCropper($border = 0, $color = 0)
67
    {
68
        return new ExtraPlugins\WhitespaceCropper($border, $color);
69
    }
70
71
    /**
72
     * Create a beautifull sharpen image
73
     *
74
     * @param int $offset
75
     * @param array $matrix
76
     * @return ExtraPlugins\Sharpen
77
     */
78
    public function createSharpen($offset = 0, array $matrix = [])
79
    {
80
        return new ExtraPlugins\Sharpen($offset, $matrix);
81
    }
82
83
    /**
84
     * Create a watermark on image
85
     *
86
     * @param PHPThumb $watermarkThumb
87
     * @param array $position
88
     * @param float $scale
89
     * @return ExtraPlugins\Watermark
90
     */
91
    public function createWatermark(PHPThumb $watermarkThumb, array $position = [0, 0], $scale = .5)
92
    {
93
        return new ExtraPlugins\Watermark($watermarkThumb, $position, $scale);
94
    }
95
}
96