|
1
|
|
|
<?php |
|
2
|
|
|
class EThumbnail extends CComponent |
|
3
|
|
|
{ |
|
4
|
|
|
/** |
|
5
|
|
|
* @var ThumbBase |
|
6
|
|
|
*/ |
|
7
|
|
|
private $_thumbnail; |
|
8
|
|
|
|
|
9
|
|
|
public function getDimensions() |
|
10
|
|
|
{ |
|
11
|
|
|
return $this->_thumbnail->getCurrentDimensions(); |
|
|
|
|
|
|
12
|
|
|
} |
|
13
|
|
|
|
|
14
|
1 |
|
public function __construct($thumbnail) { |
|
15
|
1 |
|
$this->_thumbnail=$thumbnail; |
|
16
|
1 |
|
} |
|
17
|
|
|
/** |
|
18
|
|
|
* Re-sizes this image to the given dimensions. |
|
19
|
|
|
* @param integer $width the maximum width. |
|
20
|
|
|
* @param integer $height the maximum height. |
|
21
|
|
|
* @return EThumbnail |
|
22
|
|
|
*/ |
|
23
|
1 |
|
public function resize($width=0,$height=0) |
|
24
|
|
|
{ |
|
25
|
1 |
|
$this->_thumbnail=$this->_thumbnail->resize($width,$height); |
|
|
|
|
|
|
26
|
1 |
|
return $this; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Resizes the image to the given dimensions as close as possible, |
|
31
|
|
|
* then crops it from center. |
|
32
|
|
|
* @param integer $width the width to crop the image to. |
|
33
|
|
|
* @param integer $height the height to crop the image to. |
|
34
|
|
|
* @return EThumbnail |
|
35
|
|
|
*/ |
|
36
|
|
|
public function adaptiveResize($width,$height) |
|
37
|
|
|
{ |
|
38
|
|
|
$this->_thumbnail=$this->_thumbnail->adaptiveResize($width,$height); |
|
|
|
|
|
|
39
|
|
|
return $this; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Resizes this image by the given percent uniformly. |
|
44
|
|
|
* @param integer $percent the percent to resize by. |
|
45
|
|
|
* @return EThumbnail |
|
46
|
|
|
*/ |
|
47
|
|
|
public function resizePercent($percent) |
|
48
|
|
|
{ |
|
49
|
|
|
$this->_thumbnail=$this->_thumbnail->resizePercent($percent); |
|
|
|
|
|
|
50
|
|
|
return $this; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Crops this image from the given coordinates with the specified width and height. |
|
55
|
|
|
* This is also known as Vanilla-cropping. |
|
56
|
|
|
* @param integer $x the starting x-coordinate. |
|
57
|
|
|
* @param integer $y the starting y-coordinate. |
|
58
|
|
|
* @param integer $width the width to crop with. |
|
59
|
|
|
* @param integer $height the height to crop with. |
|
60
|
|
|
* @return EThumbnail |
|
61
|
|
|
*/ |
|
62
|
|
|
public function crop($x,$y,$width,$height) |
|
63
|
|
|
{ |
|
64
|
|
|
$this->_thumbnail=$this->_thumbnail->crop($x,$y,$width,$height); |
|
|
|
|
|
|
65
|
|
|
return $this; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Crops this image from the center with the specified width and height. |
|
70
|
|
|
* @param integer $width the width to crop with. |
|
71
|
|
|
* @param integer $height the height to crop with, if null the height will be the same as the width. |
|
72
|
|
|
* @return EThumbnail |
|
73
|
|
|
*/ |
|
74
|
|
|
public function cropFromCenter($width,$height=null) |
|
75
|
|
|
{ |
|
76
|
|
|
$this->_thumbnail=$this->_thumbnail->cropFromCenter($width,$height); |
|
|
|
|
|
|
77
|
|
|
return $this; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Rotates this image by 90 degrees in the specified direction. |
|
82
|
|
|
* @param string $direction the direction to rotate the image in. |
|
83
|
|
|
* @return EThumbnail |
|
84
|
|
|
*/ |
|
85
|
|
|
public function rotateImage($direction='CW') |
|
86
|
|
|
{ |
|
87
|
|
|
$this->_thumbnail=$this->_thumbnail->rotateImage($direction); |
|
|
|
|
|
|
88
|
|
|
return $this; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Rotates this image by the specified amount of degrees. |
|
93
|
|
|
* The image is always rotated clock-wise. |
|
94
|
|
|
* @param integer $degrees the amount of degrees. |
|
95
|
|
|
* @return EThumbnail |
|
96
|
|
|
*/ |
|
97
|
|
|
public function rotateImageNDegrees($degrees) |
|
98
|
|
|
{ |
|
99
|
|
|
$this->_thumbnail=$this->_thumbnail->rotateImageNDegrees($degrees); |
|
|
|
|
|
|
100
|
|
|
return $this; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Saves this image. |
|
105
|
|
|
* @param string $path the path where to save the image. |
|
106
|
|
|
* @param string $extension the file extension. |
|
107
|
|
|
* @return EThumbnail |
|
108
|
|
|
*/ |
|
109
|
1 |
|
public function save($path,$extension=null) |
|
110
|
|
|
{ |
|
111
|
1 |
|
$this->_thumbnail=$this->_thumbnail->save($path,$extension); |
|
|
|
|
|
|
112
|
1 |
|
return $this; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* Renders this image. |
|
117
|
|
|
* @return EThumbnail |
|
118
|
|
|
*/ |
|
119
|
|
|
public function show() |
|
120
|
|
|
{ |
|
121
|
|
|
$this->_thumbnail=$this->_thumbnail->show(); |
|
|
|
|
|
|
122
|
|
|
return $this; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Returns the Working Image as a String |
|
127
|
|
|
* @return string |
|
128
|
|
|
*/ |
|
129
|
1 |
|
public function getImageAsString() |
|
130
|
|
|
{ |
|
131
|
1 |
|
return $this->_thumbnail->getImageAsString(); |
|
|
|
|
|
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* Add watermark to Image |
|
136
|
|
|
* |
|
137
|
|
|
* @param $wm |
|
138
|
|
|
* @param $pos |
|
139
|
|
|
* @param $opacity |
|
140
|
|
|
* @param $offsetX |
|
141
|
|
|
* @param $offsetY |
|
142
|
|
|
* |
|
143
|
|
|
* @return EThumbnail |
|
144
|
|
|
*/ |
|
145
|
|
|
public function addWatermark($wm, $pos, $opacity, $offsetX, $offsetY) |
|
146
|
|
|
{ |
|
147
|
|
|
$this->_thumbnail=$this->_thumbnail->addWatermark($wm->_thumbnail, $pos, $opacity, $offsetX, $offsetY); |
|
|
|
|
|
|
148
|
|
|
return $this; |
|
149
|
|
|
} |
|
150
|
|
|
} |
|
151
|
|
|
?> |
|
|
|
|
|
|
152
|
|
|
|
If you implement
__calland you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__callis implemented by a parent class and only the child class knows which methods exist: