1 
2 #ifdef HAVE_CONFIG_H
3 #include "../../../ext_config.h"
4 #endif
5 
6 #include <php.h>
7 #include "../../../php_ext.h"
8 #include "../../../ext.h"
9 
10 #include <Zend/zend_operators.h>
11 #include <Zend/zend_exceptions.h>
12 #include <Zend/zend_interfaces.h>
13 
14 #include "kernel/main.h"
15 #include "kernel/object.h"
16 #include "kernel/operators.h"
17 #include "kernel/memory.h"
18 #include "kernel/exception.h"
19 #include "kernel/fcall.h"
20 #include "kernel/file.h"
21 #include "kernel/concat.h"
22 #include "ext/spl/spl_exceptions.h"
23 #include "kernel/array.h"
24 
25 
26 /**
27  * Phalcon\Image\Adapter\Imagick
28  *
29  * Image manipulation support. Allows images to be resized, cropped, etc.
30  *
31  *<code>
32  * $image = new \Phalcon\Image\Adapter\Imagick("upload/test.jpg");
33  *
34  * $image->resize(200, 200)->rotate(90)->crop(100, 100);
35  *
36  * if ($image->save()) {
37  *     echo "success";
38  * }
39  *</code>
40  */
ZEPHIR_INIT_CLASS(Phalcon_Image_Adapter_Imagick)41 ZEPHIR_INIT_CLASS(Phalcon_Image_Adapter_Imagick) {
42 
43 	ZEPHIR_REGISTER_CLASS_EX(Phalcon\\Image\\Adapter, Imagick, phalcon, image_adapter_imagick, phalcon_image_adapter_ce, phalcon_image_adapter_imagick_method_entry, 0);
44 
45 	zend_declare_property_long(phalcon_image_adapter_imagick_ce, SL("_version"), 0, ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC);
46 
47 	zend_declare_property_bool(phalcon_image_adapter_imagick_ce, SL("_checked"), 0, ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC);
48 
49 	return SUCCESS;
50 
51 }
52 
53 /**
54  * Checks if Imagick is enabled
55  */
PHP_METHOD(Phalcon_Image_Adapter_Imagick,check)56 PHP_METHOD(Phalcon_Image_Adapter_Imagick, check) {
57 
58 	zval *_0, _1, _2, *_3 = NULL, *_6, _4$$5, *_5$$5 = NULL;
59 	zend_long ZEPHIR_LAST_CALL_STATUS;
60 
61 	ZEPHIR_MM_GROW();
62 
63 	_0 = zephir_fetch_static_property_ce(phalcon_image_adapter_imagick_ce, SL("_checked") TSRMLS_CC);
64 	if (zephir_is_true(_0)) {
65 		RETURN_MM_BOOL(1);
66 	}
67 	ZEPHIR_SINIT_VAR(_1);
68 	ZVAL_STRING(&_1, "imagick", 0);
69 	if (!(zephir_class_exists(&_1, 1 TSRMLS_CC))) {
70 		ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_image_exception_ce, "Imagick is not installed, or the extension is not loaded", "phalcon/image/adapter/imagick.zep", 55);
71 		return;
72 	}
73 	ZEPHIR_SINIT_VAR(_2);
74 	ZVAL_STRING(&_2, "Imagick::IMAGICK_EXTNUM", 0);
75 	ZEPHIR_CALL_FUNCTION(&_3, "defined", NULL, 37, &_2);
76 	zephir_check_call_status();
77 	if (zephir_is_true(_3)) {
78 		ZEPHIR_SINIT_VAR(_4$$5);
79 		ZVAL_STRING(&_4$$5, "Imagick::IMAGICK_EXTNUM", 0);
80 		ZEPHIR_CALL_FUNCTION(&_5$$5, "constant", NULL, 38, &_4$$5);
81 		zephir_check_call_status();
82 		zephir_update_static_property_ce(phalcon_image_adapter_imagick_ce, SL("_version"), &_5$$5 TSRMLS_CC);
83 	}
84 	zephir_update_static_property_ce(phalcon_image_adapter_imagick_ce, SL("_checked"), &ZEPHIR_GLOBAL(global_true) TSRMLS_CC);
85 	_6 = zephir_fetch_static_property_ce(phalcon_image_adapter_imagick_ce, SL("_checked") TSRMLS_CC);
86 	RETURN_CTOR(_6);
87 
88 }
89 
90 /**
91  * \Phalcon\Image\Adapter\Imagick constructor
92  */
PHP_METHOD(Phalcon_Image_Adapter_Imagick,__construct)93 PHP_METHOD(Phalcon_Image_Adapter_Imagick, __construct) {
94 
95 	zend_bool _20$$8;
96 	zend_long width, height, ZEPHIR_LAST_CALL_STATUS;
97 	zval *file_param = NULL, *width_param = NULL, *height_param = NULL, *image = NULL, *_0, *_1, *_2, *_31, *_32 = NULL, *_33, *_34 = NULL, *_35, *_36 = NULL, *_37, *_38 = NULL, *_39, *_3$$4, *_4$$4 = NULL, *_5$$4, *_6$$4 = NULL, *_7$$4, *_11$$4, *_12$$4 = NULL, *_16$$4, *_8$$5, *_9$$5, *_10$$5, *_13$$6, _14$$6, *_15$$6 = NULL, *_17$$7, *_18$$7, *_19$$7, *_24$$8, *_25$$8, *_26$$8 = NULL, *_27$$8, *_28$$8, *_29$$8, *_30$$8, *_21$$9, *_22$$9, *_23$$9;
98 	zval *file = NULL;
99 
100 	ZEPHIR_MM_GROW();
101 	zephir_fetch_params(1, 1, 2, &file_param, &width_param, &height_param);
102 
103 	if (UNEXPECTED(Z_TYPE_P(file_param) != IS_STRING && Z_TYPE_P(file_param) != IS_NULL)) {
104 		zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'file' must be a string") TSRMLS_CC);
105 		RETURN_MM_NULL();
106 	}
107 	if (EXPECTED(Z_TYPE_P(file_param) == IS_STRING)) {
108 		zephir_get_strval(file, file_param);
109 	} else {
110 		ZEPHIR_INIT_VAR(file);
111 		ZVAL_EMPTY_STRING(file);
112 	}
113 	if (!width_param) {
114 		width = 0;
115 	} else {
116 		width = zephir_get_intval(width_param);
117 	}
118 	if (!height_param) {
119 		height = 0;
120 	} else {
121 		height = zephir_get_intval(height_param);
122 	}
123 
124 
125 	_0 = zephir_fetch_static_property_ce(phalcon_image_adapter_imagick_ce, SL("_checked") TSRMLS_CC);
126 	if (!(zephir_is_true(_0))) {
127 		ZEPHIR_CALL_SELF(NULL, "check", NULL, 0);
128 		zephir_check_call_status();
129 	}
130 	zephir_update_property_this(getThis(), SL("_file"), file TSRMLS_CC);
131 	ZEPHIR_INIT_VAR(_1);
132 	object_init_ex(_1, zephir_get_internal_ce(SS("imagick") TSRMLS_CC));
133 	ZEPHIR_CALL_METHOD(NULL, _1, "__construct", NULL, 0);
134 	zephir_check_call_status();
135 	zephir_update_property_this(getThis(), SL("_image"), _1 TSRMLS_CC);
136 	_2 = zephir_fetch_nproperty_this(this_ptr, SL("_file"), PH_NOISY_CC);
137 	if ((zephir_file_exists(_2 TSRMLS_CC) == SUCCESS)) {
138 		_3$$4 = zephir_fetch_nproperty_this(this_ptr, SL("_file"), PH_NOISY_CC);
139 		ZEPHIR_CALL_FUNCTION(&_4$$4, "realpath", NULL, 67, _3$$4);
140 		zephir_check_call_status();
141 		zephir_update_property_this(getThis(), SL("_realpath"), _4$$4 TSRMLS_CC);
142 		_5$$4 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
143 		_7$$4 = zephir_fetch_nproperty_this(this_ptr, SL("_realpath"), PH_NOISY_CC);
144 		ZEPHIR_CALL_METHOD(&_6$$4, _5$$4, "readimage", NULL, 0, _7$$4);
145 		zephir_check_call_status();
146 		if (!(zephir_is_true(_6$$4))) {
147 			ZEPHIR_INIT_VAR(_8$$5);
148 			object_init_ex(_8$$5, phalcon_image_exception_ce);
149 			_9$$5 = zephir_fetch_nproperty_this(this_ptr, SL("_file"), PH_NOISY_CC);
150 			ZEPHIR_INIT_VAR(_10$$5);
151 			ZEPHIR_CONCAT_SVS(_10$$5, "Imagick::readImage ", _9$$5, " failed");
152 			ZEPHIR_CALL_METHOD(NULL, _8$$5, "__construct", NULL, 9, _10$$5);
153 			zephir_check_call_status();
154 			zephir_throw_exception_debug(_8$$5, "phalcon/image/adapter/imagick.zep", 86 TSRMLS_CC);
155 			ZEPHIR_MM_RESTORE();
156 			return;
157 		}
158 		_11$$4 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
159 		ZEPHIR_CALL_METHOD(&_12$$4, _11$$4, "getimagealphachannel", NULL, 0);
160 		zephir_check_call_status();
161 		if (!(zephir_is_true(_12$$4))) {
162 			_13$$6 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
163 			ZEPHIR_SINIT_VAR(_14$$6);
164 			ZVAL_STRING(&_14$$6, "Imagick::ALPHACHANNEL_SET", 0);
165 			ZEPHIR_CALL_FUNCTION(&_15$$6, "constant", NULL, 38, &_14$$6);
166 			zephir_check_call_status();
167 			ZEPHIR_CALL_METHOD(NULL, _13$$6, "setimagealphachannel", NULL, 0, _15$$6);
168 			zephir_check_call_status();
169 		}
170 		_16$$4 = zephir_fetch_nproperty_this(this_ptr, SL("_type"), PH_NOISY_CC);
171 		if (ZEPHIR_IS_LONG(_16$$4, 1)) {
172 			_17$$7 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
173 			ZEPHIR_CALL_METHOD(&image, _17$$7, "coalesceimages", NULL, 0);
174 			zephir_check_call_status();
175 			_18$$7 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
176 			ZEPHIR_CALL_METHOD(NULL, _18$$7, "clear", NULL, 0);
177 			zephir_check_call_status();
178 			_19$$7 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
179 			ZEPHIR_CALL_METHOD(NULL, _19$$7, "destroy", NULL, 0);
180 			zephir_check_call_status();
181 			zephir_update_property_this(getThis(), SL("_image"), image TSRMLS_CC);
182 		}
183 	} else {
184 		_20$$8 = !width;
185 		if (!(_20$$8)) {
186 			_20$$8 = !height;
187 		}
188 		if (_20$$8) {
189 			ZEPHIR_INIT_VAR(_21$$9);
190 			object_init_ex(_21$$9, phalcon_image_exception_ce);
191 			_22$$9 = zephir_fetch_nproperty_this(this_ptr, SL("_file"), PH_NOISY_CC);
192 			ZEPHIR_INIT_VAR(_23$$9);
193 			ZEPHIR_CONCAT_SV(_23$$9, "Failed to create image from file ", _22$$9);
194 			ZEPHIR_CALL_METHOD(NULL, _21$$9, "__construct", NULL, 9, _23$$9);
195 			zephir_check_call_status();
196 			zephir_throw_exception_debug(_21$$9, "phalcon/image/adapter/imagick.zep", 102 TSRMLS_CC);
197 			ZEPHIR_MM_RESTORE();
198 			return;
199 		}
200 		_24$$8 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
201 		ZEPHIR_INIT_VAR(_25$$8);
202 		object_init_ex(_25$$8, zephir_get_internal_ce(SS("imagickpixel") TSRMLS_CC));
203 		ZEPHIR_INIT_VAR(_26$$8);
204 		ZVAL_STRING(_26$$8, "transparent", ZEPHIR_TEMP_PARAM_COPY);
205 		ZEPHIR_CALL_METHOD(NULL, _25$$8, "__construct", NULL, 0, _26$$8);
206 		zephir_check_temp_parameter(_26$$8);
207 		zephir_check_call_status();
208 		ZEPHIR_INIT_NVAR(_26$$8);
209 		ZVAL_LONG(_26$$8, width);
210 		ZEPHIR_INIT_VAR(_27$$8);
211 		ZVAL_LONG(_27$$8, height);
212 		ZEPHIR_CALL_METHOD(NULL, _24$$8, "newimage", NULL, 0, _26$$8, _27$$8, _25$$8);
213 		zephir_check_call_status();
214 		_28$$8 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
215 		ZEPHIR_INIT_NVAR(_26$$8);
216 		ZVAL_STRING(_26$$8, "png", ZEPHIR_TEMP_PARAM_COPY);
217 		ZEPHIR_CALL_METHOD(NULL, _28$$8, "setformat", NULL, 0, _26$$8);
218 		zephir_check_temp_parameter(_26$$8);
219 		zephir_check_call_status();
220 		_29$$8 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
221 		ZEPHIR_INIT_NVAR(_26$$8);
222 		ZVAL_STRING(_26$$8, "png", ZEPHIR_TEMP_PARAM_COPY);
223 		ZEPHIR_CALL_METHOD(NULL, _29$$8, "setimageformat", NULL, 0, _26$$8);
224 		zephir_check_temp_parameter(_26$$8);
225 		zephir_check_call_status();
226 		_30$$8 = zephir_fetch_nproperty_this(this_ptr, SL("_file"), PH_NOISY_CC);
227 		zephir_update_property_this(getThis(), SL("_realpath"), _30$$8 TSRMLS_CC);
228 	}
229 	_31 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
230 	ZEPHIR_CALL_METHOD(&_32, _31, "getimagewidth", NULL, 0);
231 	zephir_check_call_status();
232 	zephir_update_property_this(getThis(), SL("_width"), _32 TSRMLS_CC);
233 	_33 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
234 	ZEPHIR_CALL_METHOD(&_34, _33, "getimageheight", NULL, 0);
235 	zephir_check_call_status();
236 	zephir_update_property_this(getThis(), SL("_height"), _34 TSRMLS_CC);
237 	_35 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
238 	ZEPHIR_CALL_METHOD(&_36, _35, "getimagetype", NULL, 0);
239 	zephir_check_call_status();
240 	zephir_update_property_this(getThis(), SL("_type"), _36 TSRMLS_CC);
241 	_37 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
242 	ZEPHIR_CALL_METHOD(&_38, _37, "getimageformat", NULL, 0);
243 	zephir_check_call_status();
244 	ZEPHIR_INIT_VAR(_39);
245 	ZEPHIR_CONCAT_SV(_39, "image/", _38);
246 	zephir_update_property_this(getThis(), SL("_mime"), _39 TSRMLS_CC);
247 	ZEPHIR_MM_RESTORE();
248 
249 }
250 
251 /**
252  * Execute a resize.
253  */
PHP_METHOD(Phalcon_Image_Adapter_Imagick,_resize)254 PHP_METHOD(Phalcon_Image_Adapter_Imagick, _resize) {
255 
256 	zephir_fcall_cache_entry *_3 = NULL, *_5 = NULL;
257 	zval *width_param = NULL, *height_param = NULL, *image = NULL, *_0, *_6 = NULL, *_7 = NULL, *_1$$3 = NULL, *_2$$3 = NULL, *_4$$3 = NULL;
258 	zend_long width, height, ZEPHIR_LAST_CALL_STATUS;
259 
260 	ZEPHIR_MM_GROW();
261 	zephir_fetch_params(1, 2, 0, &width_param, &height_param);
262 
263 	width = zephir_get_intval(width_param);
264 	height = zephir_get_intval(height_param);
265 
266 
267 	ZEPHIR_OBS_VAR(image);
268 	zephir_read_property_this(&image, this_ptr, SL("_image"), PH_NOISY_CC);
269 	ZEPHIR_INIT_VAR(_0);
270 	ZVAL_LONG(_0, 0);
271 	ZEPHIR_CALL_METHOD(NULL, image, "setiteratorindex", NULL, 0, _0);
272 	zephir_check_call_status();
273 	while (1) {
274 		ZEPHIR_INIT_NVAR(_1$$3);
275 		ZVAL_LONG(_1$$3, width);
276 		ZEPHIR_INIT_NVAR(_2$$3);
277 		ZVAL_LONG(_2$$3, height);
278 		ZEPHIR_CALL_METHOD(NULL, image, "scaleimage", &_3, 0, _1$$3, _2$$3);
279 		zephir_check_call_status();
280 		ZEPHIR_CALL_METHOD(&_4$$3, image, "nextimage", &_5, 0);
281 		zephir_check_call_status();
282 		if (ZEPHIR_IS_FALSE_IDENTICAL(_4$$3)) {
283 			break;
284 		}
285 	}
286 	ZEPHIR_CALL_METHOD(&_6, image, "getimagewidth", NULL, 0);
287 	zephir_check_call_status();
288 	zephir_update_property_this(getThis(), SL("_width"), _6 TSRMLS_CC);
289 	ZEPHIR_CALL_METHOD(&_7, image, "getimageheight", NULL, 0);
290 	zephir_check_call_status();
291 	zephir_update_property_this(getThis(), SL("_height"), _7 TSRMLS_CC);
292 	ZEPHIR_MM_RESTORE();
293 
294 }
295 
296 /**
297  * This method scales the images using liquid rescaling method. Only support Imagick
298  *
299  * @param int $width   new width
300  * @param int $height  new height
301  * @param int $deltaX How much the seam can traverse on x-axis. Passing 0 causes the seams to be straight.
302  * @param int $rigidity Introduces a bias for non-straight seams. This parameter is typically 0.
303  */
PHP_METHOD(Phalcon_Image_Adapter_Imagick,_liquidRescale)304 PHP_METHOD(Phalcon_Image_Adapter_Imagick, _liquidRescale) {
305 
306 	zephir_fcall_cache_entry *_5 = NULL, *_7 = NULL;
307 	zval *width_param = NULL, *height_param = NULL, *deltaX_param = NULL, *rigidity_param = NULL, *ret = NULL, *image = NULL, *_0, *_8 = NULL, *_9 = NULL, *_1$$3 = NULL, *_2$$3 = NULL, *_3$$3 = NULL, *_4$$3 = NULL, *_6$$3 = NULL;
308 	zend_long width, height, deltaX, rigidity, ZEPHIR_LAST_CALL_STATUS;
309 
310 	ZEPHIR_MM_GROW();
311 	zephir_fetch_params(1, 4, 0, &width_param, &height_param, &deltaX_param, &rigidity_param);
312 
313 	width = zephir_get_intval(width_param);
314 	height = zephir_get_intval(height_param);
315 	deltaX = zephir_get_intval(deltaX_param);
316 	rigidity = zephir_get_intval(rigidity_param);
317 
318 
319 	ZEPHIR_OBS_VAR(image);
320 	zephir_read_property_this(&image, this_ptr, SL("_image"), PH_NOISY_CC);
321 	ZEPHIR_INIT_VAR(_0);
322 	ZVAL_LONG(_0, 0);
323 	ZEPHIR_CALL_METHOD(NULL, image, "setiteratorindex", NULL, 0, _0);
324 	zephir_check_call_status();
325 	while (1) {
326 		ZEPHIR_INIT_NVAR(_1$$3);
327 		ZVAL_LONG(_1$$3, width);
328 		ZEPHIR_INIT_NVAR(_2$$3);
329 		ZVAL_LONG(_2$$3, height);
330 		ZEPHIR_INIT_NVAR(_3$$3);
331 		ZVAL_LONG(_3$$3, deltaX);
332 		ZEPHIR_INIT_NVAR(_4$$3);
333 		ZVAL_LONG(_4$$3, rigidity);
334 		ZEPHIR_CALL_METHOD(&ret, image, "liquidrescaleimage", &_5, 0, _1$$3, _2$$3, _3$$3, _4$$3);
335 		zephir_check_call_status();
336 		if (!ZEPHIR_IS_TRUE_IDENTICAL(ret)) {
337 			ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_image_exception_ce, "Imagick::liquidRescale failed", "phalcon/image/adapter/imagick.zep", 157);
338 			return;
339 		}
340 		ZEPHIR_CALL_METHOD(&_6$$3, image, "nextimage", &_7, 0);
341 		zephir_check_call_status();
342 		if (ZEPHIR_IS_FALSE_IDENTICAL(_6$$3)) {
343 			break;
344 		}
345 	}
346 	ZEPHIR_CALL_METHOD(&_8, image, "getimagewidth", NULL, 0);
347 	zephir_check_call_status();
348 	zephir_update_property_this(getThis(), SL("_width"), _8 TSRMLS_CC);
349 	ZEPHIR_CALL_METHOD(&_9, image, "getimageheight", NULL, 0);
350 	zephir_check_call_status();
351 	zephir_update_property_this(getThis(), SL("_height"), _9 TSRMLS_CC);
352 	ZEPHIR_MM_RESTORE();
353 
354 }
355 
356 /**
357  * Execute a crop.
358  */
PHP_METHOD(Phalcon_Image_Adapter_Imagick,_crop)359 PHP_METHOD(Phalcon_Image_Adapter_Imagick, _crop) {
360 
361 	zephir_fcall_cache_entry *_5 = NULL, *_6 = NULL, *_8 = NULL;
362 	zval *width_param = NULL, *height_param = NULL, *offsetX_param = NULL, *offsetY_param = NULL, *image = NULL, *_0, *_9 = NULL, *_10 = NULL, *_1$$3 = NULL, *_2$$3 = NULL, *_3$$3 = NULL, *_4$$3 = NULL, *_7$$3 = NULL;
363 	zend_long width, height, offsetX, offsetY, ZEPHIR_LAST_CALL_STATUS;
364 
365 	ZEPHIR_MM_GROW();
366 	zephir_fetch_params(1, 4, 0, &width_param, &height_param, &offsetX_param, &offsetY_param);
367 
368 	width = zephir_get_intval(width_param);
369 	height = zephir_get_intval(height_param);
370 	offsetX = zephir_get_intval(offsetX_param);
371 	offsetY = zephir_get_intval(offsetY_param);
372 
373 
374 	ZEPHIR_OBS_VAR(image);
375 	zephir_read_property_this(&image, this_ptr, SL("_image"), PH_NOISY_CC);
376 	ZEPHIR_INIT_VAR(_0);
377 	ZVAL_LONG(_0, 0);
378 	ZEPHIR_CALL_METHOD(NULL, image, "setiteratorindex", NULL, 0, _0);
379 	zephir_check_call_status();
380 	while (1) {
381 		ZEPHIR_INIT_NVAR(_1$$3);
382 		ZVAL_LONG(_1$$3, width);
383 		ZEPHIR_INIT_NVAR(_2$$3);
384 		ZVAL_LONG(_2$$3, height);
385 		ZEPHIR_INIT_NVAR(_3$$3);
386 		ZVAL_LONG(_3$$3, offsetX);
387 		ZEPHIR_INIT_NVAR(_4$$3);
388 		ZVAL_LONG(_4$$3, offsetY);
389 		ZEPHIR_CALL_METHOD(NULL, image, "cropimage", &_5, 0, _1$$3, _2$$3, _3$$3, _4$$3);
390 		zephir_check_call_status();
391 		ZEPHIR_INIT_NVAR(_1$$3);
392 		ZVAL_LONG(_1$$3, width);
393 		ZEPHIR_INIT_NVAR(_2$$3);
394 		ZVAL_LONG(_2$$3, height);
395 		ZEPHIR_INIT_NVAR(_3$$3);
396 		ZVAL_LONG(_3$$3, 0);
397 		ZEPHIR_INIT_NVAR(_4$$3);
398 		ZVAL_LONG(_4$$3, 0);
399 		ZEPHIR_CALL_METHOD(NULL, image, "setimagepage", &_6, 0, _1$$3, _2$$3, _3$$3, _4$$3);
400 		zephir_check_call_status();
401 		ZEPHIR_CALL_METHOD(&_7$$3, image, "nextimage", &_8, 0);
402 		zephir_check_call_status();
403 		if (!(zephir_is_true(_7$$3))) {
404 			break;
405 		}
406 	}
407 	ZEPHIR_CALL_METHOD(&_9, image, "getimagewidth", NULL, 0);
408 	zephir_check_call_status();
409 	zephir_update_property_this(getThis(), SL("_width"), _9 TSRMLS_CC);
410 	ZEPHIR_CALL_METHOD(&_10, image, "getimageheight", NULL, 0);
411 	zephir_check_call_status();
412 	zephir_update_property_this(getThis(), SL("_height"), _10 TSRMLS_CC);
413 	ZEPHIR_MM_RESTORE();
414 
415 }
416 
417 /**
418  * Execute a rotation.
419  */
PHP_METHOD(Phalcon_Image_Adapter_Imagick,_rotate)420 PHP_METHOD(Phalcon_Image_Adapter_Imagick, _rotate) {
421 
422 	zval *degrees_param = NULL, *pixel = NULL, *_0, *_1, *_10, *_11 = NULL, *_12, *_13 = NULL, *_2$$3, *_3$$3 = NULL, *_4$$3, *_5$$3, *_6$$3, *_7$$3 = NULL, *_8$$3, *_9$$3 = NULL;
423 	zend_long degrees, ZEPHIR_LAST_CALL_STATUS;
424 
425 	ZEPHIR_MM_GROW();
426 	zephir_fetch_params(1, 1, 0, &degrees_param);
427 
428 	degrees = zephir_get_intval(degrees_param);
429 
430 
431 	_0 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
432 	ZEPHIR_INIT_VAR(_1);
433 	ZVAL_LONG(_1, 0);
434 	ZEPHIR_CALL_METHOD(NULL, _0, "setiteratorindex", NULL, 0, _1);
435 	zephir_check_call_status();
436 	ZEPHIR_INIT_VAR(pixel);
437 	object_init_ex(pixel, zephir_get_internal_ce(SS("imagickpixel") TSRMLS_CC));
438 	ZEPHIR_CALL_METHOD(NULL, pixel, "__construct", NULL, 0);
439 	zephir_check_call_status();
440 	while (1) {
441 		_2$$3 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
442 		ZEPHIR_INIT_NVAR(_3$$3);
443 		ZVAL_LONG(_3$$3, degrees);
444 		ZEPHIR_CALL_METHOD(NULL, _2$$3, "rotateimage", NULL, 0, pixel, _3$$3);
445 		zephir_check_call_status();
446 		_4$$3 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
447 		_5$$3 = zephir_fetch_nproperty_this(this_ptr, SL("_width"), PH_NOISY_CC);
448 		_6$$3 = zephir_fetch_nproperty_this(this_ptr, SL("_height"), PH_NOISY_CC);
449 		ZEPHIR_INIT_NVAR(_3$$3);
450 		ZVAL_LONG(_3$$3, 0);
451 		ZEPHIR_INIT_NVAR(_7$$3);
452 		ZVAL_LONG(_7$$3, 0);
453 		ZEPHIR_CALL_METHOD(NULL, _4$$3, "setimagepage", NULL, 0, _5$$3, _6$$3, _3$$3, _7$$3);
454 		zephir_check_call_status();
455 		_8$$3 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
456 		ZEPHIR_CALL_METHOD(&_9$$3, _8$$3, "nextimage", NULL, 0);
457 		zephir_check_call_status();
458 		if (ZEPHIR_IS_FALSE_IDENTICAL(_9$$3)) {
459 			break;
460 		}
461 	}
462 	_10 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
463 	ZEPHIR_CALL_METHOD(&_11, _10, "getimagewidth", NULL, 0);
464 	zephir_check_call_status();
465 	zephir_update_property_this(getThis(), SL("_width"), _11 TSRMLS_CC);
466 	_12 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
467 	ZEPHIR_CALL_METHOD(&_13, _12, "getimageheight", NULL, 0);
468 	zephir_check_call_status();
469 	zephir_update_property_this(getThis(), SL("_height"), _13 TSRMLS_CC);
470 	ZEPHIR_MM_RESTORE();
471 
472 }
473 
474 /**
475  * Execute a flip.
476  */
PHP_METHOD(Phalcon_Image_Adapter_Imagick,_flip)477 PHP_METHOD(Phalcon_Image_Adapter_Imagick, _flip) {
478 
479 	zval *direction_param = NULL, *func = NULL, *_0, *_1, *_2$$4, *_3$$4, *_4$$4 = NULL;
480 	zend_long direction, ZEPHIR_LAST_CALL_STATUS;
481 
482 	ZEPHIR_MM_GROW();
483 	zephir_fetch_params(1, 1, 0, &direction_param);
484 
485 	direction = zephir_get_intval(direction_param);
486 
487 
488 	ZEPHIR_INIT_VAR(func);
489 	ZVAL_STRING(func, "flipImage", 1);
490 	if (direction == 11) {
491 		ZEPHIR_INIT_NVAR(func);
492 		ZVAL_STRING(func, "flopImage", 1);
493 	}
494 	_0 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
495 	ZEPHIR_INIT_VAR(_1);
496 	ZVAL_LONG(_1, 0);
497 	ZEPHIR_CALL_METHOD(NULL, _0, "setiteratorindex", NULL, 0, _1);
498 	zephir_check_call_status();
499 	while (1) {
500 		_2$$4 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
501 		ZEPHIR_CALL_METHOD_ZVAL(NULL, _2$$4, func, NULL, 0);
502 		zephir_check_call_status();
503 		_3$$4 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
504 		ZEPHIR_CALL_METHOD(&_4$$4, _3$$4, "nextimage", NULL, 0);
505 		zephir_check_call_status();
506 		if (ZEPHIR_IS_FALSE_IDENTICAL(_4$$4)) {
507 			break;
508 		}
509 	}
510 	ZEPHIR_MM_RESTORE();
511 
512 }
513 
514 /**
515  * Execute a sharpen.
516  */
PHP_METHOD(Phalcon_Image_Adapter_Imagick,_sharpen)517 PHP_METHOD(Phalcon_Image_Adapter_Imagick, _sharpen) {
518 
519 	zval *amount_param = NULL, *_0 = NULL, *_1, *_2, *_3$$3, *_4$$3 = NULL, *_5$$3 = NULL, *_6$$3, *_7$$3 = NULL;
520 	zend_long amount, ZEPHIR_LAST_CALL_STATUS;
521 
522 	ZEPHIR_MM_GROW();
523 	zephir_fetch_params(1, 1, 0, &amount_param);
524 
525 	amount = zephir_get_intval(amount_param);
526 
527 
528 	ZEPHIR_INIT_VAR(_0);
529 	if (amount < 5) {
530 		ZEPHIR_INIT_NVAR(_0);
531 		ZVAL_LONG(_0, 5);
532 	} else {
533 		ZEPHIR_INIT_NVAR(_0);
534 		ZVAL_LONG(_0, amount);
535 	}
536 	amount = zephir_get_numberval(_0);
537 	amount = (long) (zephir_safe_div_long_long(((amount * 3.0)), 100 TSRMLS_CC));
538 	_1 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
539 	ZEPHIR_INIT_VAR(_2);
540 	ZVAL_LONG(_2, 0);
541 	ZEPHIR_CALL_METHOD(NULL, _1, "setiteratorindex", NULL, 0, _2);
542 	zephir_check_call_status();
543 	while (1) {
544 		_3$$3 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
545 		ZEPHIR_INIT_NVAR(_4$$3);
546 		ZVAL_LONG(_4$$3, 0);
547 		ZEPHIR_INIT_NVAR(_5$$3);
548 		ZVAL_LONG(_5$$3, amount);
549 		ZEPHIR_CALL_METHOD(NULL, _3$$3, "sharpenimage", NULL, 0, _4$$3, _5$$3);
550 		zephir_check_call_status();
551 		_6$$3 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
552 		ZEPHIR_CALL_METHOD(&_7$$3, _6$$3, "nextimage", NULL, 0);
553 		zephir_check_call_status();
554 		if (ZEPHIR_IS_FALSE_IDENTICAL(_7$$3)) {
555 			break;
556 		}
557 	}
558 	ZEPHIR_MM_RESTORE();
559 
560 }
561 
562 /**
563  * Execute a reflection.
564  */
PHP_METHOD(Phalcon_Image_Adapter_Imagick,_reflection)565 PHP_METHOD(Phalcon_Image_Adapter_Imagick, _reflection) {
566 
567 	zephir_fcall_cache_entry *_5 = NULL, *_7 = NULL, *_11 = NULL, *_13 = NULL, *_14 = NULL, *_16 = NULL, *_21 = NULL, *_24 = NULL, *_27 = NULL, *_29 = NULL, *_35 = NULL, *_38 = NULL, *_41 = NULL, *_44 = NULL, *_48 = NULL, *_56 = NULL;
568 	zend_bool fadeIn, _57$$13;
569 	zval *height_param = NULL, *opacity_param = NULL, *fadeIn_param = NULL, *reflection = NULL, *fade = NULL, *pseudo = NULL, *image = NULL, *pixel = NULL, *ret = NULL, *_0, *_4 = NULL, *_17 = NULL, *_18 = NULL, *_30, *_31 = NULL, *_32, *_59, *_60, *_61, *_62 = NULL, *_63, *_64 = NULL, *_1$$3, *_2$$4, *_3$$4 = NULL, *_6$$5 = NULL, *_8$$5 = NULL, *_9$$5 = NULL, *_10$$5 = NULL, *_12$$5 = NULL, *_15$$5 = NULL, _19$$7 = zval_used_for_init, *_20$$7 = NULL, *_22$$7 = NULL, *_23$$7 = NULL, *_25$$7 = NULL, *_26$$7 = NULL, *_28$$7 = NULL, *_33$$10, *_34$$10 = NULL, _36$$10 = zval_used_for_init, *_37$$10 = NULL, *_39$$10, *_40$$10 = NULL, *_42$$10, *_43$$10 = NULL, *_45$$10, *_46$$10 = NULL, *_47$$10 = NULL, *_49$$10, *_50$$10 = NULL, _51$$13 = zval_used_for_init, *_52$$13 = NULL, *_53$$13, *_54$$13 = NULL, *_55$$13 = NULL, *_58$$13 = NULL;
570 	zend_long height, opacity, ZEPHIR_LAST_CALL_STATUS;
571 
572 	ZEPHIR_MM_GROW();
573 	zephir_fetch_params(1, 3, 0, &height_param, &opacity_param, &fadeIn_param);
574 
575 	height = zephir_get_intval(height_param);
576 	opacity = zephir_get_intval(opacity_param);
577 	fadeIn = zephir_get_boolval(fadeIn_param);
578 
579 
580 	_0 = zephir_fetch_static_property_ce(phalcon_image_adapter_imagick_ce, SL("_version") TSRMLS_CC);
581 	ZEPHIR_INIT_VAR(reflection);
582 	if (ZEPHIR_GE_LONG(_0, 30100)) {
583 		_1$$3 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
584 		if (zephir_clone(reflection, _1$$3 TSRMLS_CC) == FAILURE) {
585 			RETURN_MM();
586 		}
587 	} else {
588 		_2$$4 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
589 		ZEPHIR_CALL_METHOD(&_3$$4, _2$$4, "clone", NULL, 0);
590 		zephir_check_call_status();
591 		if (zephir_clone(reflection, _3$$4 TSRMLS_CC) == FAILURE) {
592 			RETURN_MM();
593 		}
594 	}
595 	ZEPHIR_INIT_VAR(_4);
596 	ZVAL_LONG(_4, 0);
597 	ZEPHIR_CALL_METHOD(NULL, reflection, "setiteratorindex", NULL, 0, _4);
598 	zephir_check_call_status();
599 	while (1) {
600 		ZEPHIR_CALL_METHOD(NULL, reflection, "flipimage", &_5, 0);
601 		zephir_check_call_status();
602 		ZEPHIR_CALL_METHOD(&_6$$5, reflection, "getimagewidth", &_7, 0);
603 		zephir_check_call_status();
604 		ZEPHIR_INIT_NVAR(_8$$5);
605 		ZVAL_LONG(_8$$5, height);
606 		ZEPHIR_INIT_NVAR(_9$$5);
607 		ZVAL_LONG(_9$$5, 0);
608 		ZEPHIR_INIT_NVAR(_10$$5);
609 		ZVAL_LONG(_10$$5, 0);
610 		ZEPHIR_CALL_METHOD(NULL, reflection, "cropimage", &_11, 0, _6$$5, _8$$5, _9$$5, _10$$5);
611 		zephir_check_call_status();
612 		ZEPHIR_CALL_METHOD(&_12$$5, reflection, "getimagewidth", &_13, 0);
613 		zephir_check_call_status();
614 		ZEPHIR_INIT_NVAR(_8$$5);
615 		ZVAL_LONG(_8$$5, height);
616 		ZEPHIR_INIT_NVAR(_9$$5);
617 		ZVAL_LONG(_9$$5, 0);
618 		ZEPHIR_INIT_NVAR(_10$$5);
619 		ZVAL_LONG(_10$$5, 0);
620 		ZEPHIR_CALL_METHOD(NULL, reflection, "setimagepage", &_14, 0, _12$$5, _8$$5, _9$$5, _10$$5);
621 		zephir_check_call_status();
622 		ZEPHIR_CALL_METHOD(&_15$$5, reflection, "nextimage", &_16, 0);
623 		zephir_check_call_status();
624 		if (ZEPHIR_IS_FALSE_IDENTICAL(_15$$5)) {
625 			break;
626 		}
627 	}
628 	if (fadeIn) {
629 		ZEPHIR_INIT_VAR(pseudo);
630 		ZVAL_STRING(pseudo, "gradient:black-transparent", 1);
631 	} else {
632 		ZEPHIR_INIT_NVAR(pseudo);
633 		ZVAL_STRING(pseudo, "gradient:transparent-black", 1);
634 	}
635 	ZEPHIR_INIT_VAR(fade);
636 	object_init_ex(fade, zephir_get_internal_ce(SS("imagick") TSRMLS_CC));
637 	ZEPHIR_CALL_METHOD(NULL, fade, "__construct", NULL, 0);
638 	zephir_check_call_status();
639 	ZEPHIR_CALL_METHOD(&_17, reflection, "getimagewidth", NULL, 0);
640 	zephir_check_call_status();
641 	ZEPHIR_CALL_METHOD(&_18, reflection, "getimageheight", NULL, 0);
642 	zephir_check_call_status();
643 	ZEPHIR_CALL_METHOD(NULL, fade, "newpseudoimage", NULL, 0, _17, _18, pseudo);
644 	zephir_check_call_status();
645 	opacity /= 100;
646 	ZEPHIR_INIT_NVAR(_4);
647 	ZVAL_LONG(_4, 0);
648 	ZEPHIR_CALL_METHOD(NULL, reflection, "setiteratorindex", NULL, 0, _4);
649 	zephir_check_call_status();
650 	while (1) {
651 		ZEPHIR_SINIT_NVAR(_19$$7);
652 		ZVAL_STRING(&_19$$7, "Imagick::COMPOSITE_DSTOUT", 0);
653 		ZEPHIR_CALL_FUNCTION(&_20$$7, "constant", &_21, 38, &_19$$7);
654 		zephir_check_call_status();
655 		ZEPHIR_INIT_NVAR(_22$$7);
656 		ZVAL_LONG(_22$$7, 0);
657 		ZEPHIR_INIT_NVAR(_23$$7);
658 		ZVAL_LONG(_23$$7, 0);
659 		ZEPHIR_CALL_METHOD(&ret, reflection, "compositeimage", &_24, 0, fade, _20$$7, _22$$7, _23$$7);
660 		zephir_check_call_status();
661 		if (!ZEPHIR_IS_TRUE_IDENTICAL(ret)) {
662 			ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_image_exception_ce, "Imagick::compositeImage failed", "phalcon/image/adapter/imagick.zep", 292);
663 			return;
664 		}
665 		ZEPHIR_SINIT_NVAR(_19$$7);
666 		ZVAL_STRING(&_19$$7, "Imagick::EVALUATE_MULTIPLY", 0);
667 		ZEPHIR_CALL_FUNCTION(&_25$$7, "constant", &_21, 38, &_19$$7);
668 		zephir_check_call_status();
669 		ZEPHIR_SINIT_NVAR(_19$$7);
670 		ZVAL_STRING(&_19$$7, "Imagick::CHANNEL_ALPHA", 0);
671 		ZEPHIR_CALL_FUNCTION(&_26$$7, "constant", &_21, 38, &_19$$7);
672 		zephir_check_call_status();
673 		ZEPHIR_INIT_NVAR(_22$$7);
674 		ZVAL_LONG(_22$$7, opacity);
675 		ZEPHIR_CALL_METHOD(NULL, reflection, "evaluateimage", &_27, 0, _25$$7, _22$$7, _26$$7);
676 		zephir_check_call_status();
677 		ZEPHIR_CALL_METHOD(&_28$$7, reflection, "nextimage", &_29, 0);
678 		zephir_check_call_status();
679 		if (ZEPHIR_IS_FALSE_IDENTICAL(_28$$7)) {
680 			break;
681 		}
682 	}
683 	ZEPHIR_CALL_METHOD(NULL, fade, "destroy", NULL, 0);
684 	zephir_check_call_status();
685 	ZEPHIR_INIT_VAR(image);
686 	object_init_ex(image, zephir_get_internal_ce(SS("imagick") TSRMLS_CC));
687 	ZEPHIR_CALL_METHOD(NULL, image, "__construct", NULL, 0);
688 	zephir_check_call_status();
689 	ZEPHIR_INIT_VAR(pixel);
690 	object_init_ex(pixel, zephir_get_internal_ce(SS("imagickpixel") TSRMLS_CC));
691 	ZEPHIR_CALL_METHOD(NULL, pixel, "__construct", NULL, 0);
692 	zephir_check_call_status();
693 	_30 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
694 	ZEPHIR_CALL_METHOD(&_31, _30, "getimageheight", NULL, 0);
695 	zephir_check_call_status();
696 	height = (zephir_get_numberval(_31) + height);
697 	_32 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
698 	ZEPHIR_INIT_NVAR(_4);
699 	ZVAL_LONG(_4, 0);
700 	ZEPHIR_CALL_METHOD(NULL, _32, "setiteratorindex", NULL, 0, _4);
701 	zephir_check_call_status();
702 	while (1) {
703 		_33$$10 = zephir_fetch_nproperty_this(this_ptr, SL("_width"), PH_NOISY_CC);
704 		ZEPHIR_INIT_NVAR(_34$$10);
705 		ZVAL_LONG(_34$$10, height);
706 		ZEPHIR_CALL_METHOD(NULL, image, "newimage", &_35, 0, _33$$10, _34$$10, pixel);
707 		zephir_check_call_status();
708 		ZEPHIR_SINIT_NVAR(_36$$10);
709 		ZVAL_STRING(&_36$$10, "Imagick::ALPHACHANNEL_SET", 0);
710 		ZEPHIR_CALL_FUNCTION(&_37$$10, "constant", &_21, 38, &_36$$10);
711 		zephir_check_call_status();
712 		ZEPHIR_CALL_METHOD(NULL, image, "setimagealphachannel", &_38, 0, _37$$10);
713 		zephir_check_call_status();
714 		_39$$10 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
715 		ZEPHIR_CALL_METHOD(&_40$$10, _39$$10, "getcolorspace", NULL, 0);
716 		zephir_check_call_status();
717 		ZEPHIR_CALL_METHOD(NULL, image, "setcolorspace", &_41, 0, _40$$10);
718 		zephir_check_call_status();
719 		_42$$10 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
720 		ZEPHIR_CALL_METHOD(&_43$$10, _42$$10, "getimagedelay", NULL, 0);
721 		zephir_check_call_status();
722 		ZEPHIR_CALL_METHOD(NULL, image, "setimagedelay", &_44, 0, _43$$10);
723 		zephir_check_call_status();
724 		_45$$10 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
725 		ZEPHIR_SINIT_NVAR(_36$$10);
726 		ZVAL_STRING(&_36$$10, "Imagick::COMPOSITE_SRC", 0);
727 		ZEPHIR_CALL_FUNCTION(&_46$$10, "constant", &_21, 38, &_36$$10);
728 		zephir_check_call_status();
729 		ZEPHIR_INIT_NVAR(_34$$10);
730 		ZVAL_LONG(_34$$10, 0);
731 		ZEPHIR_INIT_NVAR(_47$$10);
732 		ZVAL_LONG(_47$$10, 0);
733 		ZEPHIR_CALL_METHOD(&ret, image, "compositeimage", &_48, 0, _45$$10, _46$$10, _34$$10, _47$$10);
734 		zephir_check_call_status();
735 		if (!ZEPHIR_IS_TRUE_IDENTICAL(ret)) {
736 			ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_image_exception_ce, "Imagick::compositeImage failed", "phalcon/image/adapter/imagick.zep", 317);
737 			return;
738 		}
739 		_49$$10 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
740 		ZEPHIR_CALL_METHOD(&_50$$10, _49$$10, "nextimage", NULL, 0);
741 		zephir_check_call_status();
742 		if (ZEPHIR_IS_FALSE_IDENTICAL(_50$$10)) {
743 			break;
744 		}
745 	}
746 	ZEPHIR_INIT_NVAR(_4);
747 	ZVAL_LONG(_4, 0);
748 	ZEPHIR_CALL_METHOD(NULL, image, "setiteratorindex", NULL, 0, _4);
749 	zephir_check_call_status();
750 	ZEPHIR_INIT_NVAR(_4);
751 	ZVAL_LONG(_4, 0);
752 	ZEPHIR_CALL_METHOD(NULL, reflection, "setiteratorindex", NULL, 0, _4);
753 	zephir_check_call_status();
754 	while (1) {
755 		ZEPHIR_SINIT_NVAR(_51$$13);
756 		ZVAL_STRING(&_51$$13, "Imagick::COMPOSITE_OVER", 0);
757 		ZEPHIR_CALL_FUNCTION(&_52$$13, "constant", &_21, 38, &_51$$13);
758 		zephir_check_call_status();
759 		_53$$13 = zephir_fetch_nproperty_this(this_ptr, SL("_height"), PH_NOISY_CC);
760 		ZEPHIR_INIT_NVAR(_54$$13);
761 		ZVAL_LONG(_54$$13, 0);
762 		ZEPHIR_CALL_METHOD(&ret, image, "compositeimage", &_48, 0, reflection, _52$$13, _54$$13, _53$$13);
763 		zephir_check_call_status();
764 		if (!ZEPHIR_IS_TRUE_IDENTICAL(ret)) {
765 			ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_image_exception_ce, "Imagick::compositeImage failed", "phalcon/image/adapter/imagick.zep", 332);
766 			return;
767 		}
768 		ZEPHIR_CALL_METHOD(&_55$$13, image, "nextimage", &_56, 0);
769 		zephir_check_call_status();
770 		_57$$13 = ZEPHIR_IS_FALSE_IDENTICAL(_55$$13);
771 		if (!(_57$$13)) {
772 			ZEPHIR_CALL_METHOD(&_58$$13, reflection, "nextimage", NULL, 0);
773 			zephir_check_call_status();
774 			_57$$13 = ZEPHIR_IS_FALSE_IDENTICAL(_58$$13);
775 		}
776 		if (_57$$13) {
777 			break;
778 		}
779 	}
780 	ZEPHIR_CALL_METHOD(NULL, reflection, "destroy", NULL, 0);
781 	zephir_check_call_status();
782 	_59 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
783 	ZEPHIR_CALL_METHOD(NULL, _59, "clear", NULL, 0);
784 	zephir_check_call_status();
785 	_60 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
786 	ZEPHIR_CALL_METHOD(NULL, _60, "destroy", NULL, 0);
787 	zephir_check_call_status();
788 	zephir_update_property_this(getThis(), SL("_image"), image TSRMLS_CC);
789 	_61 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
790 	ZEPHIR_CALL_METHOD(&_62, _61, "getimagewidth", NULL, 0);
791 	zephir_check_call_status();
792 	zephir_update_property_this(getThis(), SL("_width"), _62 TSRMLS_CC);
793 	_63 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
794 	ZEPHIR_CALL_METHOD(&_64, _63, "getimageheight", NULL, 0);
795 	zephir_check_call_status();
796 	zephir_update_property_this(getThis(), SL("_height"), _64 TSRMLS_CC);
797 	ZEPHIR_MM_RESTORE();
798 
799 }
800 
801 /**
802  * Execute a watermarking.
803  */
PHP_METHOD(Phalcon_Image_Adapter_Imagick,_watermark)804 PHP_METHOD(Phalcon_Image_Adapter_Imagick, _watermark) {
805 
806 	zephir_fcall_cache_entry *_7 = NULL;
807 	zend_long offsetX, offsetY, opacity, ZEPHIR_LAST_CALL_STATUS;
808 	zval *image, *offsetX_param = NULL, *offsetY_param = NULL, *opacity_param = NULL, *watermark = NULL, *ret = NULL, *version = NULL, *method = NULL, *_1 = NULL, *_2 = NULL, *_3, *_0$$3, *_4$$5, _5$$5 = zval_used_for_init, *_6$$5 = NULL, *_8$$5 = NULL, *_9$$5 = NULL, *_10$$5, *_11$$5 = NULL;
809 
810 	ZEPHIR_MM_GROW();
811 	zephir_fetch_params(1, 4, 0, &image, &offsetX_param, &offsetY_param, &opacity_param);
812 
813 	offsetX = zephir_get_intval(offsetX_param);
814 	offsetY = zephir_get_intval(offsetY_param);
815 	opacity = zephir_get_intval(opacity_param);
816 
817 
818 	opacity = (long) (zephir_safe_div_long_long(opacity, 100 TSRMLS_CC));
819 	ZEPHIR_INIT_VAR(watermark);
820 	object_init_ex(watermark, zephir_get_internal_ce(SS("imagick") TSRMLS_CC));
821 	ZEPHIR_CALL_METHOD(NULL, watermark, "__construct", NULL, 0);
822 	zephir_check_call_status();
823 	ZEPHIR_INIT_VAR(method);
824 	ZVAL_STRING(method, "setImageOpacity", 1);
825 	if (EXPECTED((zephir_method_exists_ex(watermark, SS("getversion") TSRMLS_CC) == SUCCESS))) {
826 		ZEPHIR_CALL_METHOD(&version, watermark, "getversion", NULL, 0);
827 		zephir_check_call_status();
828 		zephir_array_fetch_string(&_0$$3, version, SL("versionNumber"), PH_NOISY | PH_READONLY, "phalcon/image/adapter/imagick.zep", 365 TSRMLS_CC);
829 		if (ZEPHIR_GE_LONG(_0$$3, 0x700)) {
830 			ZEPHIR_INIT_NVAR(method);
831 			ZVAL_STRING(method, "setImageAlpha", 1);
832 		}
833 	}
834 	ZEPHIR_CALL_METHOD(&_1, image, "render", NULL, 0);
835 	zephir_check_call_status();
836 	ZEPHIR_CALL_METHOD(NULL, watermark, "readimageblob", NULL, 0, _1);
837 	zephir_check_call_status();
838 	ZEPHIR_INIT_VAR(_2);
839 	ZVAL_LONG(_2, opacity);
840 	ZEPHIR_CALL_METHOD_ZVAL(NULL, watermark, method, NULL, 0, _2);
841 	zephir_check_call_status();
842 	_3 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
843 	ZEPHIR_INIT_NVAR(_2);
844 	ZVAL_LONG(_2, 0);
845 	ZEPHIR_CALL_METHOD(NULL, _3, "setiteratorindex", NULL, 0, _2);
846 	zephir_check_call_status();
847 	while (1) {
848 		_4$$5 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
849 		ZEPHIR_SINIT_NVAR(_5$$5);
850 		ZVAL_STRING(&_5$$5, "Imagick::COMPOSITE_OVER", 0);
851 		ZEPHIR_CALL_FUNCTION(&_6$$5, "constant", &_7, 38, &_5$$5);
852 		zephir_check_call_status();
853 		ZEPHIR_INIT_NVAR(_8$$5);
854 		ZVAL_LONG(_8$$5, offsetX);
855 		ZEPHIR_INIT_NVAR(_9$$5);
856 		ZVAL_LONG(_9$$5, offsetY);
857 		ZEPHIR_CALL_METHOD(&ret, _4$$5, "compositeimage", NULL, 0, watermark, _6$$5, _8$$5, _9$$5);
858 		zephir_check_call_status();
859 		if (!ZEPHIR_IS_TRUE_IDENTICAL(ret)) {
860 			ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_image_exception_ce, "Imagick::compositeImage failed", "phalcon/image/adapter/imagick.zep", 379);
861 			return;
862 		}
863 		_10$$5 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
864 		ZEPHIR_CALL_METHOD(&_11$$5, _10$$5, "nextimage", NULL, 0);
865 		zephir_check_call_status();
866 		if (ZEPHIR_IS_FALSE_IDENTICAL(_11$$5)) {
867 			break;
868 		}
869 	}
870 	ZEPHIR_CALL_METHOD(NULL, watermark, "clear", NULL, 0);
871 	zephir_check_call_status();
872 	ZEPHIR_CALL_METHOD(NULL, watermark, "destroy", NULL, 0);
873 	zephir_check_call_status();
874 	ZEPHIR_MM_RESTORE();
875 
876 }
877 
878 /**
879  * Execute a text
880  */
PHP_METHOD(Phalcon_Image_Adapter_Imagick,_text)881 PHP_METHOD(Phalcon_Image_Adapter_Imagick, _text) {
882 
883 	zend_bool _7$$7;
884 	zend_long opacity, r, g, b, size, ZEPHIR_LAST_CALL_STATUS, x = 0, y = 0;
885 	zval *text_param = NULL, *offsetX = NULL, *offsetY = NULL, *opacity_param = NULL, *r_param = NULL, *g_param = NULL, *b_param = NULL, *size_param = NULL, *fontfile_param = NULL, *draw = NULL, *color = NULL, *gravity = NULL, _0, _1, _2, _3, *_4, *_24, *_25, *_5$$4, *_6$$5, _8$$8, _9$$10, _10$$12, _11$$13, _12$$17, _13$$18, _14$$20, _15$$21, _16$$27, _17$$28, _18$$30, _19$$31, _20$$35, _21$$36, _22$$38, _23$$39, *_26$$40, *_27$$40 = NULL, *_28$$40, *_29$$40 = NULL;
886 	zval *text = NULL, *fontfile = NULL;
887 
888 	ZEPHIR_MM_GROW();
889 	zephir_fetch_params(1, 9, 0, &text_param, &offsetX, &offsetY, &opacity_param, &r_param, &g_param, &b_param, &size_param, &fontfile_param);
890 
891 	zephir_get_strval(text, text_param);
892 	ZEPHIR_SEPARATE_PARAM(offsetX);
893 	ZEPHIR_SEPARATE_PARAM(offsetY);
894 	opacity = zephir_get_intval(opacity_param);
895 	r = zephir_get_intval(r_param);
896 	g = zephir_get_intval(g_param);
897 	b = zephir_get_intval(b_param);
898 	size = zephir_get_intval(size_param);
899 	zephir_get_strval(fontfile, fontfile_param);
900 
901 
902 	opacity = (long) (zephir_safe_div_long_long(opacity, 100 TSRMLS_CC));
903 	ZEPHIR_INIT_VAR(draw);
904 	object_init_ex(draw, zephir_get_internal_ce(SS("imagickdraw") TSRMLS_CC));
905 	ZEPHIR_CALL_METHOD(NULL, draw, "__construct", NULL, 0);
906 	zephir_check_call_status();
907 	ZEPHIR_SINIT_VAR(_0);
908 	ZVAL_STRING(&_0, "rgb(%d, %d, %d)", 0);
909 	ZEPHIR_SINIT_VAR(_1);
910 	ZVAL_LONG(&_1, r);
911 	ZEPHIR_SINIT_VAR(_2);
912 	ZVAL_LONG(&_2, g);
913 	ZEPHIR_SINIT_VAR(_3);
914 	ZVAL_LONG(&_3, b);
915 	ZEPHIR_CALL_FUNCTION(&color, "sprintf", NULL, 164, &_0, &_1, &_2, &_3);
916 	zephir_check_call_status();
917 	ZEPHIR_INIT_VAR(_4);
918 	object_init_ex(_4, zephir_get_internal_ce(SS("imagickpixel") TSRMLS_CC));
919 	ZEPHIR_CALL_METHOD(NULL, _4, "__construct", NULL, 0, color);
920 	zephir_check_call_status();
921 	ZEPHIR_CALL_METHOD(NULL, draw, "setfillcolor", NULL, 0, _4);
922 	zephir_check_call_status();
923 	if (!(!fontfile) && Z_STRLEN_P(fontfile)) {
924 		ZEPHIR_CALL_METHOD(NULL, draw, "setfont", NULL, 0, fontfile);
925 		zephir_check_call_status();
926 	}
927 	if (size) {
928 		ZEPHIR_INIT_VAR(_5$$4);
929 		ZVAL_LONG(_5$$4, size);
930 		ZEPHIR_CALL_METHOD(NULL, draw, "setfontsize", NULL, 0, _5$$4);
931 		zephir_check_call_status();
932 	}
933 	if (opacity) {
934 		ZEPHIR_INIT_VAR(_6$$5);
935 		ZVAL_LONG(_6$$5, opacity);
936 		ZEPHIR_CALL_METHOD(NULL, draw, "setfillopacity", NULL, 0, _6$$5);
937 		zephir_check_call_status();
938 	}
939 	ZEPHIR_INIT_VAR(gravity);
940 	ZVAL_NULL(gravity);
941 	if (Z_TYPE_P(offsetX) == IS_BOOL) {
942 		if (Z_TYPE_P(offsetY) == IS_BOOL) {
943 			ZEPHIR_INIT_NVAR(offsetX);
944 			ZVAL_LONG(offsetX, 0);
945 			ZEPHIR_INIT_NVAR(offsetY);
946 			ZVAL_LONG(offsetY, 0);
947 			_7$$7 = zephir_is_true(offsetX);
948 			if (_7$$7) {
949 				_7$$7 = zephir_is_true(offsetY);
950 			}
951 			if (_7$$7) {
952 				ZEPHIR_SINIT_VAR(_8$$8);
953 				ZVAL_STRING(&_8$$8, "Imagick::GRAVITY_SOUTHEAST", 0);
954 				ZEPHIR_CALL_FUNCTION(&gravity, "constant", NULL, 38, &_8$$8);
955 				zephir_check_call_status();
956 			} else {
957 				if (zephir_is_true(offsetX)) {
958 					ZEPHIR_SINIT_VAR(_9$$10);
959 					ZVAL_STRING(&_9$$10, "Imagick::GRAVITY_EAST", 0);
960 					ZEPHIR_CALL_FUNCTION(&gravity, "constant", NULL, 38, &_9$$10);
961 					zephir_check_call_status();
962 				} else {
963 					if (zephir_is_true(offsetY)) {
964 						ZEPHIR_SINIT_VAR(_10$$12);
965 						ZVAL_STRING(&_10$$12, "Imagick::GRAVITY_SOUTH", 0);
966 						ZEPHIR_CALL_FUNCTION(&gravity, "constant", NULL, 38, &_10$$12);
967 						zephir_check_call_status();
968 					} else {
969 						ZEPHIR_SINIT_VAR(_11$$13);
970 						ZVAL_STRING(&_11$$13, "Imagick::GRAVITY_CENTER", 0);
971 						ZEPHIR_CALL_FUNCTION(&gravity, "constant", NULL, 38, &_11$$13);
972 						zephir_check_call_status();
973 					}
974 				}
975 			}
976 		} else {
977 			if (Z_TYPE_P(offsetY) == IS_LONG) {
978 				y = zephir_get_intval(offsetY);
979 				if (zephir_is_true(offsetX)) {
980 					ZEPHIR_INIT_NVAR(offsetX);
981 					if (y < 0) {
982 						ZVAL_LONG(offsetX, 0);
983 						ZEPHIR_INIT_NVAR(offsetY);
984 						ZVAL_LONG(offsetY, (y * -1));
985 						ZEPHIR_SINIT_VAR(_12$$17);
986 						ZVAL_STRING(&_12$$17, "Imagick::GRAVITY_SOUTHEAST", 0);
987 						ZEPHIR_CALL_FUNCTION(&gravity, "constant", NULL, 38, &_12$$17);
988 						zephir_check_call_status();
989 					} else {
990 						ZVAL_LONG(offsetX, 0);
991 						ZEPHIR_SINIT_VAR(_13$$18);
992 						ZVAL_STRING(&_13$$18, "Imagick::GRAVITY_NORTHEAST", 0);
993 						ZEPHIR_CALL_FUNCTION(&gravity, "constant", NULL, 38, &_13$$18);
994 						zephir_check_call_status();
995 					}
996 				} else {
997 					ZEPHIR_INIT_NVAR(offsetX);
998 					if (y < 0) {
999 						ZVAL_LONG(offsetX, 0);
1000 						ZEPHIR_INIT_NVAR(offsetY);
1001 						ZVAL_LONG(offsetY, (y * -1));
1002 						ZEPHIR_SINIT_VAR(_14$$20);
1003 						ZVAL_STRING(&_14$$20, "Imagick::GRAVITY_SOUTH", 0);
1004 						ZEPHIR_CALL_FUNCTION(&gravity, "constant", NULL, 38, &_14$$20);
1005 						zephir_check_call_status();
1006 					} else {
1007 						ZVAL_LONG(offsetX, 0);
1008 						ZEPHIR_SINIT_VAR(_15$$21);
1009 						ZVAL_STRING(&_15$$21, "Imagick::GRAVITY_NORTH", 0);
1010 						ZEPHIR_CALL_FUNCTION(&gravity, "constant", NULL, 38, &_15$$21);
1011 						zephir_check_call_status();
1012 					}
1013 				}
1014 			}
1015 		}
1016 	} else {
1017 		if (Z_TYPE_P(offsetX) == IS_LONG) {
1018 			x = zephir_get_intval(offsetX);
1019 			if (zephir_is_true(offsetX)) {
1020 				if (Z_TYPE_P(offsetY) == IS_BOOL) {
1021 					if (zephir_is_true(offsetY)) {
1022 						ZEPHIR_INIT_NVAR(offsetY);
1023 						if (x < 0) {
1024 							ZEPHIR_INIT_NVAR(offsetX);
1025 							ZVAL_LONG(offsetX, (x * -1));
1026 							ZVAL_LONG(offsetY, 0);
1027 							ZEPHIR_SINIT_VAR(_16$$27);
1028 							ZVAL_STRING(&_16$$27, "Imagick::GRAVITY_SOUTHEAST", 0);
1029 							ZEPHIR_CALL_FUNCTION(&gravity, "constant", NULL, 38, &_16$$27);
1030 							zephir_check_call_status();
1031 						} else {
1032 							ZVAL_LONG(offsetY, 0);
1033 							ZEPHIR_SINIT_VAR(_17$$28);
1034 							ZVAL_STRING(&_17$$28, "Imagick::GRAVITY_SOUTH", 0);
1035 							ZEPHIR_CALL_FUNCTION(&gravity, "constant", NULL, 38, &_17$$28);
1036 							zephir_check_call_status();
1037 						}
1038 					} else {
1039 						ZEPHIR_INIT_NVAR(offsetY);
1040 						if (x < 0) {
1041 							ZEPHIR_INIT_NVAR(offsetX);
1042 							ZVAL_LONG(offsetX, (x * -1));
1043 							ZVAL_LONG(offsetY, 0);
1044 							ZEPHIR_SINIT_VAR(_18$$30);
1045 							ZVAL_STRING(&_18$$30, "Imagick::GRAVITY_EAST", 0);
1046 							ZEPHIR_CALL_FUNCTION(&gravity, "constant", NULL, 38, &_18$$30);
1047 							zephir_check_call_status();
1048 						} else {
1049 							ZVAL_LONG(offsetY, 0);
1050 							ZEPHIR_SINIT_VAR(_19$$31);
1051 							ZVAL_STRING(&_19$$31, "Imagick::GRAVITY_WEST", 0);
1052 							ZEPHIR_CALL_FUNCTION(&gravity, "constant", NULL, 38, &_19$$31);
1053 							zephir_check_call_status();
1054 						}
1055 					}
1056 				} else {
1057 					if (Z_TYPE_P(offsetY) == IS_LONG) {
1058 						x = zephir_get_intval(offsetX);
1059 						y = zephir_get_intval(offsetY);
1060 						if (x < 0) {
1061 							ZEPHIR_INIT_NVAR(offsetX);
1062 							if (y < 0) {
1063 								ZVAL_LONG(offsetX, (x * -1));
1064 								ZEPHIR_INIT_NVAR(offsetY);
1065 								ZVAL_LONG(offsetY, (y * -1));
1066 								ZEPHIR_SINIT_VAR(_20$$35);
1067 								ZVAL_STRING(&_20$$35, "Imagick::GRAVITY_SOUTHEAST", 0);
1068 								ZEPHIR_CALL_FUNCTION(&gravity, "constant", NULL, 38, &_20$$35);
1069 								zephir_check_call_status();
1070 							} else {
1071 								ZVAL_LONG(offsetX, (x * -1));
1072 								ZEPHIR_SINIT_VAR(_21$$36);
1073 								ZVAL_STRING(&_21$$36, "Imagick::GRAVITY_NORTHEAST", 0);
1074 								ZEPHIR_CALL_FUNCTION(&gravity, "constant", NULL, 38, &_21$$36);
1075 								zephir_check_call_status();
1076 							}
1077 						} else {
1078 							ZEPHIR_INIT_NVAR(offsetX);
1079 							if (y < 0) {
1080 								ZVAL_LONG(offsetX, 0);
1081 								ZEPHIR_INIT_NVAR(offsetY);
1082 								ZVAL_LONG(offsetY, (y * -1));
1083 								ZEPHIR_SINIT_VAR(_22$$38);
1084 								ZVAL_STRING(&_22$$38, "Imagick::GRAVITY_SOUTHWEST", 0);
1085 								ZEPHIR_CALL_FUNCTION(&gravity, "constant", NULL, 38, &_22$$38);
1086 								zephir_check_call_status();
1087 							} else {
1088 								ZVAL_LONG(offsetX, 0);
1089 								ZEPHIR_SINIT_VAR(_23$$39);
1090 								ZVAL_STRING(&_23$$39, "Imagick::GRAVITY_NORTHWEST", 0);
1091 								ZEPHIR_CALL_FUNCTION(&gravity, "constant", NULL, 38, &_23$$39);
1092 								zephir_check_call_status();
1093 							}
1094 						}
1095 					}
1096 				}
1097 			}
1098 		}
1099 	}
1100 	ZEPHIR_CALL_METHOD(NULL, draw, "setgravity", NULL, 0, gravity);
1101 	zephir_check_call_status();
1102 	_24 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
1103 	ZEPHIR_INIT_VAR(_25);
1104 	ZVAL_LONG(_25, 0);
1105 	ZEPHIR_CALL_METHOD(NULL, _24, "setiteratorindex", NULL, 0, _25);
1106 	zephir_check_call_status();
1107 	while (1) {
1108 		_26$$40 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
1109 		ZEPHIR_INIT_NVAR(_27$$40);
1110 		ZVAL_LONG(_27$$40, 0);
1111 		ZEPHIR_CALL_METHOD(NULL, _26$$40, "annotateimage", NULL, 0, draw, offsetX, offsetY, _27$$40, text);
1112 		zephir_check_call_status();
1113 		_28$$40 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
1114 		ZEPHIR_CALL_METHOD(&_29$$40, _28$$40, "nextimage", NULL, 0);
1115 		zephir_check_call_status();
1116 		if (ZEPHIR_IS_FALSE_IDENTICAL(_29$$40)) {
1117 			break;
1118 		}
1119 	}
1120 	ZEPHIR_CALL_METHOD(NULL, draw, "destroy", NULL, 0);
1121 	zephir_check_call_status();
1122 	ZEPHIR_MM_RESTORE();
1123 
1124 }
1125 
1126 /**
1127  * Composite one image onto another
1128  */
PHP_METHOD(Phalcon_Image_Adapter_Imagick,_mask)1129 PHP_METHOD(Phalcon_Image_Adapter_Imagick, _mask) {
1130 
1131 	zephir_fcall_cache_entry *_8 = NULL;
1132 	zend_long ZEPHIR_LAST_CALL_STATUS;
1133 	zval *image, *mask = NULL, *ret = NULL, *_0 = NULL, *_1, *_2, *_3$$3, *_4$$3 = NULL, *_5$$3, _6$$3 = zval_used_for_init, *_7$$3 = NULL, *_9$$3 = NULL, *_10$$3, *_11$$3 = NULL;
1134 
1135 	ZEPHIR_MM_GROW();
1136 	zephir_fetch_params(1, 1, 0, &image);
1137 
1138 
1139 
1140 	ZEPHIR_INIT_VAR(mask);
1141 	object_init_ex(mask, zephir_get_internal_ce(SS("imagick") TSRMLS_CC));
1142 	ZEPHIR_CALL_METHOD(NULL, mask, "__construct", NULL, 0);
1143 	zephir_check_call_status();
1144 	ZEPHIR_CALL_METHOD(&_0, image, "render", NULL, 0);
1145 	zephir_check_call_status();
1146 	ZEPHIR_CALL_METHOD(NULL, mask, "readimageblob", NULL, 0, _0);
1147 	zephir_check_call_status();
1148 	_1 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
1149 	ZEPHIR_INIT_VAR(_2);
1150 	ZVAL_LONG(_2, 0);
1151 	ZEPHIR_CALL_METHOD(NULL, _1, "setiteratorindex", NULL, 0, _2);
1152 	zephir_check_call_status();
1153 	while (1) {
1154 		_3$$3 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
1155 		ZEPHIR_INIT_NVAR(_4$$3);
1156 		ZVAL_LONG(_4$$3, 1);
1157 		ZEPHIR_CALL_METHOD(NULL, _3$$3, "setimagematte", NULL, 0, _4$$3);
1158 		zephir_check_call_status();
1159 		_5$$3 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
1160 		ZEPHIR_SINIT_NVAR(_6$$3);
1161 		ZVAL_STRING(&_6$$3, "Imagick::COMPOSITE_DSTIN", 0);
1162 		ZEPHIR_CALL_FUNCTION(&_7$$3, "constant", &_8, 38, &_6$$3);
1163 		zephir_check_call_status();
1164 		ZEPHIR_INIT_NVAR(_4$$3);
1165 		ZVAL_LONG(_4$$3, 0);
1166 		ZEPHIR_INIT_NVAR(_9$$3);
1167 		ZVAL_LONG(_9$$3, 0);
1168 		ZEPHIR_CALL_METHOD(&ret, _5$$3, "compositeimage", NULL, 0, mask, _7$$3, _4$$3, _9$$3);
1169 		zephir_check_call_status();
1170 		if (!ZEPHIR_IS_TRUE_IDENTICAL(ret)) {
1171 			ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_image_exception_ce, "Imagick::compositeImage failed", "phalcon/image/adapter/imagick.zep", 544);
1172 			return;
1173 		}
1174 		_10$$3 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
1175 		ZEPHIR_CALL_METHOD(&_11$$3, _10$$3, "nextimage", NULL, 0);
1176 		zephir_check_call_status();
1177 		if (ZEPHIR_IS_FALSE_IDENTICAL(_11$$3)) {
1178 			break;
1179 		}
1180 	}
1181 	ZEPHIR_CALL_METHOD(NULL, mask, "clear", NULL, 0);
1182 	zephir_check_call_status();
1183 	ZEPHIR_CALL_METHOD(NULL, mask, "destroy", NULL, 0);
1184 	zephir_check_call_status();
1185 	ZEPHIR_MM_RESTORE();
1186 
1187 }
1188 
1189 /**
1190  * Execute a background.
1191  */
PHP_METHOD(Phalcon_Image_Adapter_Imagick,_background)1192 PHP_METHOD(Phalcon_Image_Adapter_Imagick, _background) {
1193 
1194 	zephir_fcall_cache_entry *_8 = NULL, *_10 = NULL, *_13 = NULL, *_14 = NULL, *_15 = NULL, *_20 = NULL, *_23 = NULL, *_27 = NULL;
1195 	zval *r_param = NULL, *g_param = NULL, *b_param = NULL, *opacity_param = NULL, *background = NULL, *color = NULL, *pixel1 = NULL, *pixel2 = NULL, *ret = NULL, _0, _1, _2, _3, *_4 = NULL, *_5, *_30, *_31, *_6$$3, *_7$$3, *_9$$3 = NULL, _16$$3 = zval_used_for_init, *_17$$3 = NULL, *_18$$3 = NULL, *_19$$3 = NULL, *_21$$3, *_22$$3 = NULL, *_24$$3, *_25$$3 = NULL, *_26$$3 = NULL, *_28$$3, *_29$$3 = NULL, _11$$4 = zval_used_for_init, *_12$$4 = NULL;
1196 	zend_long r, g, b, opacity, ZEPHIR_LAST_CALL_STATUS;
1197 
1198 	ZEPHIR_MM_GROW();
1199 	zephir_fetch_params(1, 4, 0, &r_param, &g_param, &b_param, &opacity_param);
1200 
1201 	r = zephir_get_intval(r_param);
1202 	g = zephir_get_intval(g_param);
1203 	b = zephir_get_intval(b_param);
1204 	opacity = zephir_get_intval(opacity_param);
1205 
1206 
1207 	ZEPHIR_SINIT_VAR(_0);
1208 	ZVAL_STRING(&_0, "rgb(%d, %d, %d)", 0);
1209 	ZEPHIR_SINIT_VAR(_1);
1210 	ZVAL_LONG(&_1, r);
1211 	ZEPHIR_SINIT_VAR(_2);
1212 	ZVAL_LONG(&_2, g);
1213 	ZEPHIR_SINIT_VAR(_3);
1214 	ZVAL_LONG(&_3, b);
1215 	ZEPHIR_CALL_FUNCTION(&color, "sprintf", NULL, 164, &_0, &_1, &_2, &_3);
1216 	zephir_check_call_status();
1217 	ZEPHIR_INIT_VAR(pixel1);
1218 	object_init_ex(pixel1, zephir_get_internal_ce(SS("imagickpixel") TSRMLS_CC));
1219 	ZEPHIR_CALL_METHOD(NULL, pixel1, "__construct", NULL, 0, color);
1220 	zephir_check_call_status();
1221 	opacity = (long) (zephir_safe_div_long_long(opacity, 100 TSRMLS_CC));
1222 	ZEPHIR_INIT_VAR(pixel2);
1223 	object_init_ex(pixel2, zephir_get_internal_ce(SS("imagickpixel") TSRMLS_CC));
1224 	ZEPHIR_INIT_VAR(_4);
1225 	ZVAL_STRING(_4, "transparent", ZEPHIR_TEMP_PARAM_COPY);
1226 	ZEPHIR_CALL_METHOD(NULL, pixel2, "__construct", NULL, 0, _4);
1227 	zephir_check_temp_parameter(_4);
1228 	zephir_check_call_status();
1229 	ZEPHIR_INIT_VAR(background);
1230 	object_init_ex(background, zephir_get_internal_ce(SS("imagick") TSRMLS_CC));
1231 	ZEPHIR_CALL_METHOD(NULL, background, "__construct", NULL, 0);
1232 	zephir_check_call_status();
1233 	_5 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
1234 	ZEPHIR_INIT_NVAR(_4);
1235 	ZVAL_LONG(_4, 0);
1236 	ZEPHIR_CALL_METHOD(NULL, _5, "setiteratorindex", NULL, 0, _4);
1237 	zephir_check_call_status();
1238 	while (1) {
1239 		_6$$3 = zephir_fetch_nproperty_this(this_ptr, SL("_width"), PH_NOISY_CC);
1240 		_7$$3 = zephir_fetch_nproperty_this(this_ptr, SL("_height"), PH_NOISY_CC);
1241 		ZEPHIR_CALL_METHOD(NULL, background, "newimage", &_8, 0, _6$$3, _7$$3, pixel1);
1242 		zephir_check_call_status();
1243 		ZEPHIR_CALL_METHOD(&_9$$3, background, "getimagealphachannel", &_10, 0);
1244 		zephir_check_call_status();
1245 		if (!(zephir_is_true(_9$$3))) {
1246 			ZEPHIR_SINIT_NVAR(_11$$4);
1247 			ZVAL_STRING(&_11$$4, "Imagick::ALPHACHANNEL_SET", 0);
1248 			ZEPHIR_CALL_FUNCTION(&_12$$4, "constant", &_13, 38, &_11$$4);
1249 			zephir_check_call_status();
1250 			ZEPHIR_CALL_METHOD(NULL, background, "setimagealphachannel", &_14, 0, _12$$4);
1251 			zephir_check_call_status();
1252 		}
1253 		ZEPHIR_CALL_METHOD(NULL, background, "setimagebackgroundcolor", &_15, 0, pixel2);
1254 		zephir_check_call_status();
1255 		ZEPHIR_SINIT_NVAR(_16$$3);
1256 		ZVAL_STRING(&_16$$3, "Imagick::EVALUATE_MULTIPLY", 0);
1257 		ZEPHIR_CALL_FUNCTION(&_17$$3, "constant", &_13, 38, &_16$$3);
1258 		zephir_check_call_status();
1259 		ZEPHIR_SINIT_NVAR(_16$$3);
1260 		ZVAL_STRING(&_16$$3, "Imagick::CHANNEL_ALPHA", 0);
1261 		ZEPHIR_CALL_FUNCTION(&_18$$3, "constant", &_13, 38, &_16$$3);
1262 		zephir_check_call_status();
1263 		ZEPHIR_INIT_NVAR(_19$$3);
1264 		ZVAL_LONG(_19$$3, opacity);
1265 		ZEPHIR_CALL_METHOD(NULL, background, "evaluateimage", &_20, 0, _17$$3, _19$$3, _18$$3);
1266 		zephir_check_call_status();
1267 		_21$$3 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
1268 		ZEPHIR_CALL_METHOD(&_22$$3, _21$$3, "getcolorspace", NULL, 0);
1269 		zephir_check_call_status();
1270 		ZEPHIR_CALL_METHOD(NULL, background, "setcolorspace", &_23, 0, _22$$3);
1271 		zephir_check_call_status();
1272 		_24$$3 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
1273 		ZEPHIR_SINIT_NVAR(_16$$3);
1274 		ZVAL_STRING(&_16$$3, "Imagick::COMPOSITE_DISSOLVE", 0);
1275 		ZEPHIR_CALL_FUNCTION(&_25$$3, "constant", &_13, 38, &_16$$3);
1276 		zephir_check_call_status();
1277 		ZEPHIR_INIT_NVAR(_19$$3);
1278 		ZVAL_LONG(_19$$3, 0);
1279 		ZEPHIR_INIT_NVAR(_26$$3);
1280 		ZVAL_LONG(_26$$3, 0);
1281 		ZEPHIR_CALL_METHOD(&ret, background, "compositeimage", &_27, 0, _24$$3, _25$$3, _19$$3, _26$$3);
1282 		zephir_check_call_status();
1283 		if (!ZEPHIR_IS_TRUE_IDENTICAL(ret)) {
1284 			ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_image_exception_ce, "Imagick::compositeImage failed", "phalcon/image/adapter/imagick.zep", 583);
1285 			return;
1286 		}
1287 		_28$$3 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
1288 		ZEPHIR_CALL_METHOD(&_29$$3, _28$$3, "nextimage", NULL, 0);
1289 		zephir_check_call_status();
1290 		if (ZEPHIR_IS_FALSE_IDENTICAL(_29$$3)) {
1291 			break;
1292 		}
1293 	}
1294 	_30 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
1295 	ZEPHIR_CALL_METHOD(NULL, _30, "clear", NULL, 0);
1296 	zephir_check_call_status();
1297 	_31 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
1298 	ZEPHIR_CALL_METHOD(NULL, _31, "destroy", NULL, 0);
1299 	zephir_check_call_status();
1300 	zephir_update_property_this(getThis(), SL("_image"), background TSRMLS_CC);
1301 	ZEPHIR_MM_RESTORE();
1302 
1303 }
1304 
1305 /**
1306  * Blur image
1307  *
1308  * @param int $radius Blur radius
1309  */
PHP_METHOD(Phalcon_Image_Adapter_Imagick,_blur)1310 PHP_METHOD(Phalcon_Image_Adapter_Imagick, _blur) {
1311 
1312 	zval *radius_param = NULL, *_0, *_1, *_2$$3, *_3$$3 = NULL, *_4$$3 = NULL, *_5$$3, *_6$$3 = NULL;
1313 	zend_long radius, ZEPHIR_LAST_CALL_STATUS;
1314 
1315 	ZEPHIR_MM_GROW();
1316 	zephir_fetch_params(1, 1, 0, &radius_param);
1317 
1318 	radius = zephir_get_intval(radius_param);
1319 
1320 
1321 	_0 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
1322 	ZEPHIR_INIT_VAR(_1);
1323 	ZVAL_LONG(_1, 0);
1324 	ZEPHIR_CALL_METHOD(NULL, _0, "setiteratorindex", NULL, 0, _1);
1325 	zephir_check_call_status();
1326 	while (1) {
1327 		_2$$3 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
1328 		ZEPHIR_INIT_NVAR(_3$$3);
1329 		ZVAL_LONG(_3$$3, radius);
1330 		ZEPHIR_INIT_NVAR(_4$$3);
1331 		ZVAL_LONG(_4$$3, 100);
1332 		ZEPHIR_CALL_METHOD(NULL, _2$$3, "blurimage", NULL, 0, _3$$3, _4$$3);
1333 		zephir_check_call_status();
1334 		_5$$3 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
1335 		ZEPHIR_CALL_METHOD(&_6$$3, _5$$3, "nextimage", NULL, 0);
1336 		zephir_check_call_status();
1337 		if (ZEPHIR_IS_FALSE_IDENTICAL(_6$$3)) {
1338 			break;
1339 		}
1340 	}
1341 	ZEPHIR_MM_RESTORE();
1342 
1343 }
1344 
1345 /**
1346  * Pixelate image
1347  *
1348  * @param int $amount amount to pixelate
1349  */
PHP_METHOD(Phalcon_Image_Adapter_Imagick,_pixelate)1350 PHP_METHOD(Phalcon_Image_Adapter_Imagick, _pixelate) {
1351 
1352 	zval *amount_param = NULL, *_0, *_1, *_2, *_3, *_4$$3, *_5$$3 = NULL, *_6$$3 = NULL, *_7$$3, *_8$$3, *_9$$3, *_10$$3, *_11$$3 = NULL;
1353 	zend_long amount, ZEPHIR_LAST_CALL_STATUS, width = 0, height = 0;
1354 
1355 	ZEPHIR_MM_GROW();
1356 	zephir_fetch_params(1, 1, 0, &amount_param);
1357 
1358 	amount = zephir_get_intval(amount_param);
1359 
1360 
1361 	_0 = zephir_fetch_nproperty_this(this_ptr, SL("_width"), PH_NOISY_CC);
1362 	width = (long) (zephir_safe_div_zval_long(_0, amount TSRMLS_CC));
1363 	_1 = zephir_fetch_nproperty_this(this_ptr, SL("_height"), PH_NOISY_CC);
1364 	height = (long) (zephir_safe_div_zval_long(_1, amount TSRMLS_CC));
1365 	_2 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
1366 	ZEPHIR_INIT_VAR(_3);
1367 	ZVAL_LONG(_3, 0);
1368 	ZEPHIR_CALL_METHOD(NULL, _2, "setiteratorindex", NULL, 0, _3);
1369 	zephir_check_call_status();
1370 	while (1) {
1371 		_4$$3 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
1372 		ZEPHIR_INIT_NVAR(_5$$3);
1373 		ZVAL_LONG(_5$$3, width);
1374 		ZEPHIR_INIT_NVAR(_6$$3);
1375 		ZVAL_LONG(_6$$3, height);
1376 		ZEPHIR_CALL_METHOD(NULL, _4$$3, "scaleimage", NULL, 0, _5$$3, _6$$3);
1377 		zephir_check_call_status();
1378 		_7$$3 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
1379 		_8$$3 = zephir_fetch_nproperty_this(this_ptr, SL("_width"), PH_NOISY_CC);
1380 		_9$$3 = zephir_fetch_nproperty_this(this_ptr, SL("_height"), PH_NOISY_CC);
1381 		ZEPHIR_CALL_METHOD(NULL, _7$$3, "scaleimage", NULL, 0, _8$$3, _9$$3);
1382 		zephir_check_call_status();
1383 		_10$$3 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
1384 		ZEPHIR_CALL_METHOD(&_11$$3, _10$$3, "nextimage", NULL, 0);
1385 		zephir_check_call_status();
1386 		if (ZEPHIR_IS_FALSE_IDENTICAL(_11$$3)) {
1387 			break;
1388 		}
1389 	}
1390 	ZEPHIR_MM_RESTORE();
1391 
1392 }
1393 
1394 /**
1395  * Execute a save.
1396  */
PHP_METHOD(Phalcon_Image_Adapter_Imagick,_save)1397 PHP_METHOD(Phalcon_Image_Adapter_Imagick, _save) {
1398 
1399 	zend_bool _14$$4;
1400 	zend_long quality, ZEPHIR_LAST_CALL_STATUS;
1401 	zval *file_param = NULL, *quality_param = NULL, *ext = NULL, *fp = NULL, _0 = zval_used_for_init, *_1, *_2, *_3, *_4 = NULL, *_5, *_6 = NULL, *_7, *_8 = NULL, *_9$$3, _10$$3, *_11$$3, _12$$4 = zval_used_for_init, *_13$$4 = NULL, *_15$$4 = NULL, *_21$$4, *_16$$5, _17$$5, *_18$$5 = NULL, *_19$$6, *_20$$6;
1402 	zval *file = NULL;
1403 
1404 	ZEPHIR_MM_GROW();
1405 	zephir_fetch_params(1, 2, 0, &file_param, &quality_param);
1406 
1407 	zephir_get_strval(file, file_param);
1408 	quality = zephir_get_intval(quality_param);
1409 
1410 
1411 	ZEPHIR_SINIT_VAR(_0);
1412 	ZVAL_LONG(&_0, 4);
1413 	ZEPHIR_CALL_FUNCTION(&ext, "pathinfo", NULL, 78, file, &_0);
1414 	zephir_check_call_status();
1415 	_1 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
1416 	ZEPHIR_CALL_METHOD(NULL, _1, "setformat", NULL, 0, ext);
1417 	zephir_check_call_status();
1418 	_2 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
1419 	ZEPHIR_CALL_METHOD(NULL, _2, "setimageformat", NULL, 0, ext);
1420 	zephir_check_call_status();
1421 	_3 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
1422 	ZEPHIR_CALL_METHOD(&_4, _3, "getimagetype", NULL, 0);
1423 	zephir_check_call_status();
1424 	zephir_update_property_this(getThis(), SL("_type"), _4 TSRMLS_CC);
1425 	_5 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
1426 	ZEPHIR_CALL_METHOD(&_6, _5, "getimageformat", NULL, 0);
1427 	zephir_check_call_status();
1428 	ZEPHIR_INIT_VAR(_7);
1429 	ZEPHIR_CONCAT_SV(_7, "image/", _6);
1430 	zephir_update_property_this(getThis(), SL("_mime"), _7 TSRMLS_CC);
1431 	ZEPHIR_SINIT_NVAR(_0);
1432 	ZVAL_STRING(&_0, "gif", 0);
1433 	ZEPHIR_CALL_FUNCTION(&_8, "strcasecmp", NULL, 16, ext, &_0);
1434 	zephir_check_call_status();
1435 	if (ZEPHIR_IS_LONG(_8, 0)) {
1436 		_9$$3 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
1437 		ZEPHIR_CALL_METHOD(NULL, _9$$3, "optimizeimagelayers", NULL, 0);
1438 		zephir_check_call_status();
1439 		ZEPHIR_SINIT_VAR(_10$$3);
1440 		ZVAL_STRING(&_10$$3, "w", 0);
1441 		ZEPHIR_CALL_FUNCTION(&fp, "fopen", NULL, 308, file, &_10$$3);
1442 		zephir_check_call_status();
1443 		_11$$3 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
1444 		ZEPHIR_CALL_METHOD(NULL, _11$$3, "writeimagesfile", NULL, 0, fp);
1445 		zephir_check_call_status();
1446 		zephir_fclose(fp TSRMLS_CC);
1447 		RETURN_MM_NULL();
1448 	} else {
1449 		ZEPHIR_SINIT_VAR(_12$$4);
1450 		ZVAL_STRING(&_12$$4, "jpg", 0);
1451 		ZEPHIR_CALL_FUNCTION(&_13$$4, "strcasecmp", NULL, 16, ext, &_12$$4);
1452 		zephir_check_call_status();
1453 		_14$$4 = ZEPHIR_IS_LONG(_13$$4, 0);
1454 		if (!(_14$$4)) {
1455 			ZEPHIR_SINIT_NVAR(_12$$4);
1456 			ZVAL_STRING(&_12$$4, "jpeg", 0);
1457 			ZEPHIR_CALL_FUNCTION(&_15$$4, "strcasecmp", NULL, 16, ext, &_12$$4);
1458 			zephir_check_call_status();
1459 			_14$$4 = ZEPHIR_IS_LONG(_15$$4, 0);
1460 		}
1461 		if (_14$$4) {
1462 			_16$$5 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
1463 			ZEPHIR_SINIT_VAR(_17$$5);
1464 			ZVAL_STRING(&_17$$5, "Imagick::COMPRESSION_JPEG", 0);
1465 			ZEPHIR_CALL_FUNCTION(&_18$$5, "constant", NULL, 38, &_17$$5);
1466 			zephir_check_call_status();
1467 			ZEPHIR_CALL_METHOD(NULL, _16$$5, "setimagecompression", NULL, 0, _18$$5);
1468 			zephir_check_call_status();
1469 		}
1470 		if (quality >= 0) {
1471 			if (quality < 1) {
1472 				quality = 1;
1473 			} else if (quality > 100) {
1474 				quality = 100;
1475 			}
1476 			_19$$6 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
1477 			ZEPHIR_INIT_VAR(_20$$6);
1478 			ZVAL_LONG(_20$$6, quality);
1479 			ZEPHIR_CALL_METHOD(NULL, _19$$6, "setimagecompressionquality", NULL, 0, _20$$6);
1480 			zephir_check_call_status();
1481 		}
1482 		_21$$4 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
1483 		ZEPHIR_CALL_METHOD(NULL, _21$$4, "writeimage", NULL, 0, file);
1484 		zephir_check_call_status();
1485 	}
1486 	ZEPHIR_MM_RESTORE();
1487 
1488 }
1489 
1490 /**
1491  * Execute a render.
1492  */
PHP_METHOD(Phalcon_Image_Adapter_Imagick,_render)1493 PHP_METHOD(Phalcon_Image_Adapter_Imagick, _render) {
1494 
1495 	zend_bool _7$$4;
1496 	zend_long quality, ZEPHIR_LAST_CALL_STATUS;
1497 	zval *extension_param = NULL, *quality_param = NULL, *image = NULL, *_0 = NULL, *_1 = NULL, *_2, _3, *_4 = NULL, _5$$4 = zval_used_for_init, *_6$$4 = NULL, *_8$$4 = NULL, *_11$$4, _9$$5, *_10$$5 = NULL;
1498 	zval *extension = NULL;
1499 
1500 	ZEPHIR_MM_GROW();
1501 	zephir_fetch_params(1, 2, 0, &extension_param, &quality_param);
1502 
1503 	zephir_get_strval(extension, extension_param);
1504 	quality = zephir_get_intval(quality_param);
1505 
1506 
1507 	ZEPHIR_OBS_VAR(image);
1508 	zephir_read_property_this(&image, this_ptr, SL("_image"), PH_NOISY_CC);
1509 	ZEPHIR_CALL_METHOD(NULL, image, "setformat", NULL, 0, extension);
1510 	zephir_check_call_status();
1511 	ZEPHIR_CALL_METHOD(NULL, image, "setimageformat", NULL, 0, extension);
1512 	zephir_check_call_status();
1513 	ZEPHIR_CALL_METHOD(NULL, image, "stripimage", NULL, 0);
1514 	zephir_check_call_status();
1515 	ZEPHIR_CALL_METHOD(&_0, image, "getimagetype", NULL, 0);
1516 	zephir_check_call_status();
1517 	zephir_update_property_this(getThis(), SL("_type"), _0 TSRMLS_CC);
1518 	ZEPHIR_CALL_METHOD(&_1, image, "getimageformat", NULL, 0);
1519 	zephir_check_call_status();
1520 	ZEPHIR_INIT_VAR(_2);
1521 	ZEPHIR_CONCAT_SV(_2, "image/", _1);
1522 	zephir_update_property_this(getThis(), SL("_mime"), _2 TSRMLS_CC);
1523 	ZEPHIR_SINIT_VAR(_3);
1524 	ZVAL_STRING(&_3, "gif", 0);
1525 	ZEPHIR_CALL_FUNCTION(&_4, "strcasecmp", NULL, 16, extension, &_3);
1526 	zephir_check_call_status();
1527 	if (ZEPHIR_IS_LONG_IDENTICAL(_4, 0)) {
1528 		ZEPHIR_CALL_METHOD(NULL, image, "optimizeimagelayers", NULL, 0);
1529 		zephir_check_call_status();
1530 	} else {
1531 		ZEPHIR_SINIT_VAR(_5$$4);
1532 		ZVAL_STRING(&_5$$4, "jpg", 0);
1533 		ZEPHIR_CALL_FUNCTION(&_6$$4, "strcasecmp", NULL, 16, extension, &_5$$4);
1534 		zephir_check_call_status();
1535 		_7$$4 = ZEPHIR_IS_LONG_IDENTICAL(_6$$4, 0);
1536 		if (!(_7$$4)) {
1537 			ZEPHIR_SINIT_NVAR(_5$$4);
1538 			ZVAL_STRING(&_5$$4, "jpeg", 0);
1539 			ZEPHIR_CALL_FUNCTION(&_8$$4, "strcasecmp", NULL, 16, extension, &_5$$4);
1540 			zephir_check_call_status();
1541 			_7$$4 = ZEPHIR_IS_LONG_IDENTICAL(_8$$4, 0);
1542 		}
1543 		if (_7$$4) {
1544 			ZEPHIR_SINIT_VAR(_9$$5);
1545 			ZVAL_STRING(&_9$$5, "Imagick::COMPRESSION_JPEG", 0);
1546 			ZEPHIR_CALL_FUNCTION(&_10$$5, "constant", NULL, 38, &_9$$5);
1547 			zephir_check_call_status();
1548 			ZEPHIR_CALL_METHOD(NULL, image, "setimagecompression", NULL, 0, _10$$5);
1549 			zephir_check_call_status();
1550 		}
1551 		ZEPHIR_INIT_VAR(_11$$4);
1552 		ZVAL_LONG(_11$$4, quality);
1553 		ZEPHIR_CALL_METHOD(NULL, image, "setimagecompressionquality", NULL, 0, _11$$4);
1554 		zephir_check_call_status();
1555 	}
1556 	ZEPHIR_RETURN_CALL_METHOD(image, "getimageblob", NULL, 0);
1557 	zephir_check_call_status();
1558 	RETURN_MM();
1559 
1560 }
1561 
1562 /**
1563  * Destroys the loaded image to free up resources.
1564  */
PHP_METHOD(Phalcon_Image_Adapter_Imagick,__destruct)1565 PHP_METHOD(Phalcon_Image_Adapter_Imagick, __destruct) {
1566 
1567 	zval *_0, *_1$$3, *_2$$3;
1568 	zend_long ZEPHIR_LAST_CALL_STATUS;
1569 
1570 	ZEPHIR_MM_GROW();
1571 
1572 	ZEPHIR_OBS_VAR(_0);
1573 	zephir_read_property_this(&_0, this_ptr, SL("_image"), PH_NOISY_CC);
1574 	if (zephir_instance_of_ev(_0, zephir_get_internal_ce(SS("imagick") TSRMLS_CC) TSRMLS_CC)) {
1575 		_1$$3 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
1576 		ZEPHIR_CALL_METHOD(NULL, _1$$3, "clear", NULL, 0);
1577 		zephir_check_call_status();
1578 		_2$$3 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
1579 		ZEPHIR_CALL_METHOD(NULL, _2$$3, "destroy", NULL, 0);
1580 		zephir_check_call_status();
1581 	}
1582 	ZEPHIR_MM_RESTORE();
1583 
1584 }
1585 
1586 /**
1587  * Get instance
1588  */
PHP_METHOD(Phalcon_Image_Adapter_Imagick,getInternalImInstance)1589 PHP_METHOD(Phalcon_Image_Adapter_Imagick, getInternalImInstance) {
1590 
1591 
1592 
1593 	RETURN_MEMBER(getThis(), "_image");
1594 
1595 }
1596 
1597 /**
1598  * Sets the limit for a particular resource in megabytes
1599  *
1600  * @link http://php.net/manual/ru/imagick.constants.php#imagick.constants.resourcetypes
1601  */
PHP_METHOD(Phalcon_Image_Adapter_Imagick,setResourceLimit)1602 PHP_METHOD(Phalcon_Image_Adapter_Imagick, setResourceLimit) {
1603 
1604 	zval *type_param = NULL, *limit_param = NULL, *_0, *_1, *_2;
1605 	zend_long type, limit, ZEPHIR_LAST_CALL_STATUS;
1606 
1607 	ZEPHIR_MM_GROW();
1608 	zephir_fetch_params(1, 2, 0, &type_param, &limit_param);
1609 
1610 	type = zephir_get_intval(type_param);
1611 	limit = zephir_get_intval(limit_param);
1612 
1613 
1614 	_0 = zephir_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC);
1615 	ZEPHIR_INIT_VAR(_1);
1616 	ZVAL_LONG(_1, type);
1617 	ZEPHIR_INIT_VAR(_2);
1618 	ZVAL_LONG(_2, limit);
1619 	ZEPHIR_CALL_METHOD(NULL, _0, "setresourcelimit", NULL, 0, _1, _2);
1620 	zephir_check_call_status();
1621 	ZEPHIR_MM_RESTORE();
1622 
1623 }
1624 
1625