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-2018 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
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Image Thumbnailer service |
19
|
|
|
* |
20
|
|
|
* Image thumbnailer powered by PHPThumb (https://github.com/masterexploder/PHPThumb) |
21
|
|
|
*/ |
22
|
|
|
class ImageThumb |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* Create image thumbnail object |
26
|
|
|
* |
27
|
|
|
* @param string $filename |
28
|
|
|
* @param array $options |
29
|
|
|
* @param array $plugins |
30
|
|
|
* @return PHPThumb |
31
|
|
|
*/ |
32
|
|
|
public function create($filename = null, array $options = [], array $plugins = []) |
33
|
|
|
{ |
34
|
|
|
try { |
35
|
|
|
$thumb = new PHPThumb($filename, $options, $plugins); |
36
|
|
|
} catch (\Exception $exc) { |
37
|
|
|
throw new Exception\RuntimeException($exc->getMessage(), $exc->getCode(), $exc); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
return $thumb; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Create reflection plugin |
45
|
|
|
* |
46
|
|
|
* @param int $percent |
47
|
|
|
* @param int $reflection |
48
|
|
|
* @param int $white |
49
|
|
|
* @param bool $border |
50
|
|
|
* @param string $borderColor hex |
51
|
|
|
* @return Plugins\Reflection |
52
|
|
|
*/ |
53
|
|
|
public function createReflection($percent, $reflection, $white, $border, $borderColor) |
54
|
|
|
{ |
55
|
|
|
return new Plugins\Reflection($percent, $reflection, $white, $border, $borderColor); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Create a plugin to crop the whitespace surrounding an image |
60
|
|
|
* |
61
|
|
|
* @param int $border |
62
|
|
|
* @param int $color |
63
|
|
|
* @return Plugins\WhitespaceCropper |
64
|
|
|
*/ |
65
|
|
|
public function createWhitespaceCropper($border = 0, $color = 0) |
66
|
|
|
{ |
67
|
|
|
return new Plugins\WhitespaceCropper($border, $color); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Create a beautifull sharpen image |
72
|
|
|
* |
73
|
|
|
* @param int $offset |
74
|
|
|
* @param array $matrix |
75
|
|
|
* @return Plugins\Sharpen |
76
|
|
|
*/ |
77
|
|
|
public function createSharpen($offset = 0, array $matrix = []) |
78
|
|
|
{ |
79
|
|
|
return new Plugins\Sharpen($offset, $matrix); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Create a watermark on image |
84
|
|
|
* |
85
|
|
|
* @param PHPThumb $watermarkThumb |
86
|
|
|
* @param array $position |
87
|
|
|
* @param float $scale |
88
|
|
|
* @return Plugins\Watermark |
89
|
|
|
*/ |
90
|
|
|
public function createWatermark(PHPThumb $watermarkThumb, array $position = [0, 0], $scale = .5) |
91
|
|
|
{ |
92
|
|
|
return new Plugins\Watermark($watermarkThumb, $position, $scale); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|