|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* vim: set expandtab tabstop=4 shiftwidth=4: */ |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Image Transformation interface using old ImageMagick extension |
|
7
|
|
|
* |
|
8
|
|
|
* PHP versions 4 and 5 |
|
9
|
|
|
* |
|
10
|
|
|
* LICENSE: This source file is subject to version 3.0 of the PHP license |
|
11
|
|
|
* that is available through the world-wide-web at the following URI: |
|
12
|
|
|
* http://www.php.net/license/3_0.txt. If you did not receive a copy of |
|
13
|
|
|
* the PHP License and are unable to obtain it through the web, please |
|
14
|
|
|
* send a note to [email protected] so we can mail you a copy immediately. |
|
15
|
|
|
* |
|
16
|
|
|
* @category Image |
|
17
|
|
|
* @package Image_Transform |
|
18
|
|
|
* @author Peter Bowyer <[email protected]> |
|
19
|
|
|
* @copyright 2002-2005 The PHP Group |
|
20
|
|
|
* @license http://www.php.net/license/3_0.txt PHP License 3.0 |
|
21
|
|
|
* @deprecated |
|
22
|
|
|
* @link http://pear.php.net/package/Image_Transform |
|
23
|
|
|
*/ |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Include of base class |
|
27
|
|
|
*/ |
|
28
|
|
|
require_once XOOPS_ROOT_PATH . '/modules/extgallery/class/pear/Image/Image/Transform.php'; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Image Transformation interface using old ImageMagick extension |
|
32
|
|
|
* |
|
33
|
|
|
* DEPRECATED: current CVS/release imagick extension should use |
|
34
|
|
|
* the Imagick2 driver |
|
35
|
|
|
* |
|
36
|
|
|
* @deprecated |
|
37
|
|
|
*/ |
|
38
|
|
|
class Image_Transform_Driver_Imagick extends Image_Transform |
|
39
|
|
|
{ |
|
40
|
|
|
/** |
|
41
|
|
|
* Handler of the imagick image ressource |
|
42
|
|
|
* @var array |
|
43
|
|
|
*/ |
|
44
|
|
|
public $imageHandle; |
|
45
|
|
|
/** |
|
46
|
|
|
* Handler of the image ressource before |
|
47
|
|
|
* the last transformation |
|
48
|
|
|
* @var array |
|
49
|
|
|
*/ |
|
50
|
|
|
public $oldImage; |
|
51
|
|
|
|
|
52
|
|
|
public function __construct() |
|
53
|
|
|
{ |
|
54
|
|
|
if (!PEAR::loadExtension('imagick')) { |
|
55
|
|
|
return PEAR::raiseError('The imagick extension can not be found.', true); |
|
|
|
|
|
|
56
|
|
|
} |
|
57
|
|
|
require_once __DIR__ . '/Image/Transform/Driver/Imagick/ImageTypes.php'; |
|
58
|
|
|
//return true; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
// End Image_IM |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Load image |
|
65
|
|
|
* |
|
66
|
|
|
* @param mixed $image |
|
67
|
|
|
* |
|
68
|
|
|
* @return mixed none or a PEAR error object on error |
|
69
|
|
|
* @see PEAR::isError() |
|
70
|
|
|
*/ |
|
71
|
|
|
public function load($image) |
|
72
|
|
|
{ |
|
73
|
|
|
$this->imageHandle = imagick_create(); |
|
|
|
|
|
|
74
|
|
|
if (!is_resource($this->imageHandle)) { |
|
75
|
|
|
return PEAR::raiseError('Cannot initialize imagick image.', true); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
if (!imagick_read($this->imageHandle, $image)) { |
|
|
|
|
|
|
79
|
|
|
return PEAR::raiseError('The image file ' . $image . ' does\'t exist', true); |
|
80
|
|
|
} |
|
81
|
|
|
$this->image = $image; |
|
82
|
|
|
$result = $this->_get_image_details($image); |
|
83
|
|
|
if (PEAR::isError($result)) { |
|
84
|
|
|
return $result; |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
// End load |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Resize Action |
|
92
|
|
|
* |
|
93
|
|
|
* @param mixed $new_x |
|
94
|
|
|
* @param mixed $new_y |
|
95
|
|
|
* |
|
96
|
|
|
* @return none |
|
|
|
|
|
|
97
|
|
|
* @see PEAR::isError() |
|
98
|
|
|
*/ |
|
99
|
|
|
public function _resize($new_x, $new_y) |
|
100
|
|
|
{ |
|
101
|
|
|
$img2 = imagick_copy_resize($this->imageHandle, $new_x, $new_y, IMAGICK_FILTER_CUBIC, 1); |
|
|
|
|
|
|
102
|
|
|
if ($img2) { |
|
103
|
|
|
$this->oldImage = $this->imageHandle; |
|
104
|
|
|
$this->imageHandle = $img2; |
|
105
|
|
|
$this->new_x = $new_x; |
|
106
|
|
|
$this->new_y = $new_y; |
|
107
|
|
|
} else { |
|
108
|
|
|
return PEAR::raiseError('Cannot create a new imagick imagick image for the resize.', true); |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
// End resize |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* rotate |
|
116
|
|
|
* Note: color mask are currently not supported |
|
117
|
|
|
* |
|
118
|
|
|
* @param float $angle |
|
119
|
|
|
* @param null|mixed $options |
|
120
|
|
|
* |
|
121
|
|
|
* @return none |
|
122
|
|
|
* @see PEAR::isError() |
|
123
|
|
|
*/ |
|
124
|
|
|
public function rotate($angle, $options = null) |
|
125
|
|
|
{ |
|
126
|
|
|
$img2 = imagick_copy_rotate($this->imageHandle, $angle); |
|
|
|
|
|
|
127
|
|
|
if ($img2) { |
|
128
|
|
|
$this->oldImage = $this->imageHandle; |
|
129
|
|
|
$this->imageHandle = $img2; |
|
130
|
|
|
$this->new_x = imagick_get_attribute($img2, 'width'); |
|
|
|
|
|
|
131
|
|
|
$this->new_y = imagick_get_attribute($img2, 'height'); |
|
132
|
|
|
} else { |
|
133
|
|
|
return PEAR::raiseError('Cannot create a new imagick imagick image for the resize.', true); |
|
134
|
|
|
} |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
// End rotate |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* addText |
|
141
|
|
|
* |
|
142
|
|
|
* @param mixed $params |
|
143
|
|
|
* |
|
144
|
|
|
* @see PEAR::isError() |
|
145
|
|
|
*/ |
|
146
|
|
|
public function addText($params) |
|
147
|
|
|
{ |
|
148
|
|
|
$default_params = [ |
|
149
|
|
|
'text' => 'This is a Text', |
|
150
|
|
|
'x' => 10, |
|
151
|
|
|
'y' => 20, |
|
152
|
|
|
'size' => 12, |
|
153
|
|
|
'color' => 'red', |
|
154
|
|
|
'font' => 'Arial.ttf', |
|
155
|
|
|
'resize_first' => false, // Carry out the scaling of the image before annotation? |
|
156
|
|
|
]; |
|
157
|
|
|
$params = array_merge($default_params, $params); |
|
158
|
|
|
extract($params); |
|
159
|
|
|
|
|
160
|
|
|
$color = is_array($color) ? $this->colorarray2colorhex($color) : mb_strtolower($color); |
|
161
|
|
|
|
|
162
|
|
|
imagick_annotate( |
|
|
|
|
|
|
163
|
|
|
$this->imageHandle, |
|
164
|
|
|
[ |
|
165
|
|
|
'primitive' => "text $x,$y " . $text, |
|
166
|
|
|
'pointsize' => $size, |
|
167
|
|
|
'antialias' => 0, |
|
168
|
|
|
'fill' => $color, |
|
169
|
|
|
'font' => $font, |
|
170
|
|
|
] |
|
171
|
|
|
); |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
// End addText |
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* Save the image file |
|
178
|
|
|
* |
|
179
|
|
|
* @param string $filename the name of the file to write to |
|
180
|
|
|
* |
|
181
|
|
|
* @param string $type |
|
182
|
|
|
* @param int $quality |
|
183
|
|
|
*/ |
|
184
|
|
|
public function save($filename, $type = '', $quality = 75) |
|
185
|
|
|
{ |
|
186
|
|
|
if ('' == $type) { |
|
187
|
|
|
$type = mb_strtoupper($type); |
|
188
|
|
|
imagick_write($this->imageHandle, $filename, $type); |
|
|
|
|
|
|
189
|
|
|
} else { |
|
190
|
|
|
imagick_write($this->imageHandle, $filename); |
|
191
|
|
|
} |
|
192
|
|
|
imagick_free($handle); |
|
|
|
|
|
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
// End save |
|
196
|
|
|
|
|
197
|
|
|
/** |
|
198
|
|
|
* Display image without saving and lose changes |
|
199
|
|
|
* |
|
200
|
|
|
* @param mixed $type |
|
201
|
|
|
* @param mixed $quality |
|
202
|
|
|
*/ |
|
203
|
|
|
public function display($type = '', $quality = 75) |
|
204
|
|
|
{ |
|
205
|
|
|
if ('' == $type) { |
|
206
|
|
|
header('Content-type: image/' . $this->type); |
|
207
|
|
|
if (!imagick_dump($this->imageHandle)) { |
|
|
|
|
|
|
208
|
|
|
} |
|
209
|
|
|
} else { |
|
210
|
|
|
header('Content-type: image/' . $type); |
|
211
|
|
|
if (!imagick_dump($this->imageHandle, $this->type)) { |
|
212
|
|
|
} |
|
213
|
|
|
} |
|
214
|
|
|
$this->free(); |
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
|
|
/** |
|
218
|
|
|
* Destroy image handle |
|
219
|
|
|
* |
|
220
|
|
|
* @return bool |
|
221
|
|
|
*/ |
|
222
|
|
|
public function free() |
|
223
|
|
|
{ |
|
224
|
|
|
if (is_resource($this->imageHandle)) { |
|
|
|
|
|
|
225
|
|
|
imagick_free($this->imageHandle); |
|
|
|
|
|
|
226
|
|
|
} |
|
227
|
|
|
if (is_resource($this->oldImage)) { |
|
|
|
|
|
|
228
|
|
|
imagick_free($this->oldImage); |
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
|
|
return true; |
|
232
|
|
|
} |
|
233
|
|
|
} // End class ImageIM |
|
234
|
|
|
|