@@ -105,13 +105,15 @@ PHP_METHOD(Phalcon_Image_Adapter_Imagick, check){
105
105
*/
106
106
PHP_METHOD (Phalcon_Image_Adapter_Imagick , __construct ){
107
107
108
- zval * file ;
109
- zval * checked = NULL , * realpath , * type , * im , * ret , * mode ;
110
- zend_class_entry * ce0 ;
108
+ zval * file , * width = NULL , * height = NULL , * exception_message ;
109
+ zval * checked = NULL , * realpath , * format , * type = NULL , * mime = NULL , * im , * ret = NULL , * mode , * imagickpixel , * color ;
110
+ zend_class_entry * ce0 , * ce1 ;
111
111
112
112
PHALCON_MM_GROW ();
113
113
114
- phalcon_fetch_params (1 , 1 , 0 , & file );
114
+ phalcon_fetch_params (1 , 1 , 2 , & file , & width , & height );
115
+
116
+ ce0 = zend_fetch_class (SL ("Imagick" ), ZEND_FETCH_CLASS_AUTO TSRMLS_CC );
115
117
116
118
PHALCON_OBS_VAR (checked );
117
119
phalcon_read_static_property (& checked , SL ("phalcon\\image\\adapter\\imagick" ), SL ("_checked" ) TSRMLS_CC );
@@ -120,43 +122,84 @@ PHP_METHOD(Phalcon_Image_Adapter_Imagick, __construct){
120
122
phalcon_call_static_noret ("phalcon\\image\\adapter\\imagick" , "check" );
121
123
}
122
124
123
- phalcon_call_parent_p1_noret (this_ptr , phalcon_image_adapter_imagick_ce , "__construct" , file );
124
-
125
- PHALCON_OBS_VAR (realpath );
126
- phalcon_read_property_this (& realpath , this_ptr , SL ("_realpath" ), PH_NOISY_CC );
127
-
128
- PHALCON_OBS_VAR (type );
129
- phalcon_read_property_this (& type , this_ptr , SL ("_type" ), PH_NOISY_CC );
130
-
131
- ce0 = zend_fetch_class (SL ("Imagick" ), ZEND_FETCH_CLASS_AUTO TSRMLS_CC );
132
-
133
125
PHALCON_INIT_VAR (im );
134
126
object_init_ex (im , ce0 );
135
127
if (phalcon_has_constructor (im TSRMLS_CC )) {
136
128
phalcon_call_method_noret (im , "__construct" );
137
129
}
138
130
139
- phalcon_call_method_p1_noret (im , "readImage" , realpath );
131
+ if (phalcon_file_exists (file TSRMLS_CC ) != FAILURE ) {
132
+ phalcon_call_parent_p1_noret (this_ptr , phalcon_image_adapter_imagick_ce , "__construct" , file );
140
133
141
- PHALCON_INIT_VAR ( ret );
142
- phalcon_call_method ( ret , im , "getImageAlphaChannel" );
134
+ PHALCON_OBS_VAR ( realpath );
135
+ phalcon_read_property_this ( & realpath , this_ptr , SL ( "_realpath" ), PH_NOISY_CC );
143
136
144
- if (!zend_is_true (ret )) {
145
- PHALCON_INIT_VAR (mode );
146
- phalcon_get_class_constant (mode , ce0 , SS ("ALPHACHANNEL_SET" ) TSRMLS_CC );
147
- phalcon_call_method_p1_noret (im , "setImageAlphaChannel" , mode );
148
- }
137
+ PHALCON_OBS_VAR (type );
138
+ phalcon_read_property_this (& type , this_ptr , SL ("_type" ), PH_NOISY_CC );
139
+ phalcon_call_method_p1_noret (im , "readImage" , realpath );
140
+
141
+ PHALCON_INIT_VAR (ret );
142
+ phalcon_call_method (ret , im , "getImageAlphaChannel" );
143
+
144
+ if (!zend_is_true (ret )) {
145
+ PHALCON_INIT_VAR (mode );
146
+ phalcon_get_class_constant (mode , ce0 , SS ("ALPHACHANNEL_SET" ) TSRMLS_CC );
147
+ phalcon_call_method_p1_noret (im , "setImageAlphaChannel" , mode );
148
+ }
149
+
150
+ if (phalcon_get_intval (type ) == 1 ) {
151
+ PHALCON_INIT_NVAR (ret );
152
+ phalcon_call_method (ret , im , "coalesceImages" );
153
+
154
+ phalcon_call_method_noret (im , "clear" );
155
+ phalcon_call_method_noret (im , "destroy" );
156
+
157
+ phalcon_update_property_this (this_ptr , SL ("_image" ), ret TSRMLS_CC );
158
+ } else {
159
+ phalcon_update_property_this (this_ptr , SL ("_image" ), im TSRMLS_CC );
160
+ }
161
+ } else if (width && height ) {
162
+ ce1 = zend_fetch_class (SL ("ImagickPixel" ), ZEND_FETCH_CLASS_AUTO TSRMLS_CC );
163
+
164
+ PHALCON_INIT_VAR (imagickpixel );
165
+ object_init_ex (imagickpixel , ce1 );
166
+
167
+ if (phalcon_has_constructor (imagickpixel TSRMLS_CC )) {
168
+ PHALCON_INIT_VAR (color );
169
+ ZVAL_STRING (color , "transparent" , 1 );
170
+
171
+ phalcon_call_method_p1_noret (imagickpixel , "__construct" , color );
172
+ }
173
+
174
+ phalcon_call_method_p3_noret (im , "newImage" , width , height , imagickpixel );
175
+
176
+ PHALCON_INIT_VAR (format );
177
+ ZVAL_STRING (format , "png" , 1 );
149
178
150
- if (phalcon_get_intval (type ) == 1 ) {
151
179
PHALCON_INIT_NVAR (ret );
152
- phalcon_call_method (ret , im , "coalesceImages" );
180
+ phalcon_call_method_p1 (ret , im , "setFormat" , format );
181
+ phalcon_call_method_p1 (ret , im , "setImageFormat" , format );
153
182
154
- phalcon_call_method_noret (im , "clear" );
155
- phalcon_call_method_noret (im , "destroy" );
183
+ phalcon_update_property_this (this_ptr , SL ("_image" ), im TSRMLS_CC );
184
+
185
+ phalcon_update_property_this (this_ptr , SL ("_realpath" ), file TSRMLS_CC );
186
+ phalcon_update_property_this (this_ptr , SL ("_width" ), width TSRMLS_CC );
187
+ phalcon_update_property_this (this_ptr , SL ("_height" ), height TSRMLS_CC );
156
188
157
- phalcon_update_property_this (this_ptr , SL ("_image" ), ret TSRMLS_CC );
189
+ PHALCON_INIT_VAR (type );
190
+ ZVAL_LONG (type , 3 );
191
+
192
+ phalcon_update_property_this (this_ptr , SL ("_type" ), type TSRMLS_CC );
193
+
194
+ PHALCON_INIT_VAR (mime );
195
+ ZVAL_STRING (mime , "image/png" , 1 );
196
+
197
+ phalcon_update_property_this (this_ptr , SL ("_mime" ), mime TSRMLS_CC );
158
198
} else {
159
- phalcon_update_property_this (this_ptr , SL ("_image" ), im TSRMLS_CC );
199
+ PHALCON_INIT_VAR (exception_message );
200
+ PHALCON_CONCAT_SVS (exception_message , "Create image from file '" , file , "' failure " );
201
+ PHALCON_THROW_EXCEPTION_ZVAL (phalcon_image_exception_ce , exception_message );
202
+ return ;
160
203
}
161
204
162
205
PHALCON_MM_RESTORE ();
@@ -1157,6 +1200,7 @@ PHP_METHOD(Phalcon_Image_Adapter_Imagick, _save) {
1157
1200
phalcon_read_property_this (& im , this_ptr , SL ("_image" ), PH_NOISY_CC );
1158
1201
1159
1202
phalcon_call_method_p1_noret (im , "setFormat" , format );
1203
+ phalcon_call_method_p1_noret (im , "setImageFormat" , format );
1160
1204
phalcon_call_method_noret (im , "stripImage" );
1161
1205
1162
1206
if (phalcon_get_intval (type ) == 1 ) {
@@ -1248,6 +1292,7 @@ PHP_METHOD(Phalcon_Image_Adapter_Imagick, _render) {
1248
1292
phalcon_read_property_this (& im , this_ptr , SL ("_image" ), PH_NOISY_CC );
1249
1293
1250
1294
phalcon_call_method_p1_noret (im , "setFormat" , format );
1295
+ phalcon_call_method_p1_noret (im , "setImageFormat" , format );
1251
1296
phalcon_call_method_noret (im , "stripImage" );
1252
1297
1253
1298
phalcon_update_property_this (this_ptr , SL ("_type" ), type TSRMLS_CC );
0 commit comments