1 : /*
2 : +----------------------------------------------------------------------+
3 : | PHP Version 5 |
4 : +----------------------------------------------------------------------+
5 : | Copyright (c) 1997-2009 The PHP Group |
6 : +----------------------------------------------------------------------+
7 : | This source file is subject to version 3.01 of the PHP license, |
8 : | that is bundled with this package in the file LICENSE, and is |
9 : | available through the world-wide-web at the following url: |
10 : | http://www.php.net/license/3_01.txt |
11 : | If you did not receive a copy of the PHP license and are unable to |
12 : | obtain it through the world-wide-web, please send a note to |
13 : | license@php.net so we can mail you a copy immediately. |
14 : +----------------------------------------------------------------------+
15 : | Authors: Rasmus Lerdorf <rasmus@php.net> |
16 : | Stig Bakken <ssb@php.net> |
17 : | Jim Winstead <jimw@php.net> |
18 : +----------------------------------------------------------------------+
19 : */
20 :
21 : /* $Id: gd.c 282456 2009-06-19 22:15:44Z kalle $ */
22 :
23 : /* gd 1.2 is copyright 1994, 1995, Quest Protein Database Center,
24 : Cold Spring Harbor Labs. */
25 :
26 : /* Note that there is no code from the gd package in this file */
27 :
28 : #ifdef HAVE_CONFIG_H
29 : #include "config.h"
30 : #endif
31 :
32 : #ifdef HAVE_GD_PNG
33 : /* needs to be first */
34 : #include <png.h>
35 : #endif
36 :
37 : #include "php.h"
38 : #include "php_ini.h"
39 : #include "ext/standard/head.h"
40 : #include <math.h>
41 : #include "SAPI.h"
42 : #include "php_gd.h"
43 : #include "ext/standard/info.h"
44 : #include "php_open_temporary_file.h"
45 :
46 : #if HAVE_SYS_WAIT_H
47 : # include <sys/wait.h>
48 : #endif
49 : #if HAVE_UNISTD_H
50 : # include <unistd.h>
51 : #endif
52 : #ifdef PHP_WIN32
53 : # include <io.h>
54 : # include <fcntl.h>
55 : #include <windows.h>
56 : #include <Winuser.h>
57 : #include <Wingdi.h>
58 : #endif
59 :
60 : #if HAVE_LIBGD
61 :
62 : static int le_gd, le_gd_font;
63 : #if HAVE_LIBT1
64 : #include <t1lib.h>
65 : static int le_ps_font, le_ps_enc;
66 : static void php_free_ps_font(zend_rsrc_list_entry *rsrc TSRMLS_DC);
67 : static void php_free_ps_enc(zend_rsrc_list_entry *rsrc TSRMLS_DC);
68 : #endif
69 :
70 : #include <gd.h>
71 : #include <gdfontt.h> /* 1 Tiny font */
72 : #include <gdfonts.h> /* 2 Small font */
73 : #include <gdfontmb.h> /* 3 Medium bold font */
74 : #include <gdfontl.h> /* 4 Large font */
75 : #include <gdfontg.h> /* 5 Giant font */
76 : #include "libgd/gdhelpers.h"
77 :
78 : #ifdef HAVE_GD_WBMP
79 : #include "libgd/wbmp.h"
80 : #endif
81 : #ifdef ENABLE_GD_TTF
82 : # ifdef HAVE_LIBFREETYPE
83 : # include <ft2build.h>
84 : # include FT_FREETYPE_H
85 : # else
86 : # ifdef HAVE_LIBTTF
87 : # include <freetype.h>
88 : # endif
89 : # endif
90 : # include "gdttf.h"
91 : #endif
92 :
93 : #ifndef M_PI
94 : #define M_PI 3.14159265358979323846
95 : #endif
96 :
97 : #ifdef ENABLE_GD_TTF
98 : static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int, int);
99 : #endif
100 :
101 : #if HAVE_LIBGD15
102 : /* it's >= 1.5, i.e. has IOCtx */
103 : #define USE_GD_IOCTX 1
104 : #else
105 : #undef USE_GD_IOCTX
106 : #endif
107 :
108 : #ifdef USE_GD_IOCTX
109 : #include "gd_ctx.c"
110 : #else
111 : #define gdImageCreateFromGdCtx NULL
112 : #define gdImageCreateFromGd2Ctx NULL
113 : #define gdImageCreateFromGd2partCtx NULL
114 : #define gdImageCreateFromGifCtx NULL
115 : #define gdImageCreateFromJpegCtx NULL
116 : #define gdImageCreateFromPngCtx NULL
117 : #define gdImageCreateFromWBMPCtx NULL
118 : typedef FILE gdIOCtx;
119 : #define CTX_PUTC(c, fp) fputc(c, fp)
120 : #endif
121 :
122 : #ifndef HAVE_GDIMAGECOLORRESOLVE
123 : extern int gdImageColorResolve(gdImagePtr, int, int, int);
124 : #endif
125 :
126 : #if HAVE_COLORCLOSESTHWB
127 : int gdImageColorClosestHWB(gdImagePtr im, int r, int g, int b);
128 : #endif
129 :
130 : #ifndef HAVE_GD_DYNAMIC_CTX_EX
131 : #define gdNewDynamicCtxEx(len, data, val) gdNewDynamicCtx(len, data)
132 : #endif
133 :
134 : /* Section Filters Declarations */
135 : /* IMPORTANT NOTE FOR NEW FILTER
136 : * Do not forget to update:
137 : * IMAGE_FILTER_MAX: define the last filter index
138 : * IMAGE_FILTER_MAX_ARGS: define the biggest amout of arguments
139 : * image_filter array in PHP_FUNCTION(imagefilter)
140 : * */
141 : #if HAVE_GD_BUNDLED
142 : #define IMAGE_FILTER_NEGATE 0
143 : #define IMAGE_FILTER_GRAYSCALE 1
144 : #define IMAGE_FILTER_BRIGHTNESS 2
145 : #define IMAGE_FILTER_CONTRAST 3
146 : #define IMAGE_FILTER_COLORIZE 4
147 : #define IMAGE_FILTER_EDGEDETECT 5
148 : #define IMAGE_FILTER_EMBOSS 6
149 : #define IMAGE_FILTER_GAUSSIAN_BLUR 7
150 : #define IMAGE_FILTER_SELECTIVE_BLUR 8
151 : #define IMAGE_FILTER_MEAN_REMOVAL 9
152 : #define IMAGE_FILTER_SMOOTH 10
153 : #define IMAGE_FILTER_MAX 10
154 : #define IMAGE_FILTER_MAX_ARGS 5
155 : static void php_image_filter_negate(INTERNAL_FUNCTION_PARAMETERS);
156 : static void php_image_filter_grayscale(INTERNAL_FUNCTION_PARAMETERS);
157 : static void php_image_filter_brightness(INTERNAL_FUNCTION_PARAMETERS);
158 : static void php_image_filter_contrast(INTERNAL_FUNCTION_PARAMETERS);
159 : static void php_image_filter_colorize(INTERNAL_FUNCTION_PARAMETERS);
160 : static void php_image_filter_edgedetect(INTERNAL_FUNCTION_PARAMETERS);
161 : static void php_image_filter_emboss(INTERNAL_FUNCTION_PARAMETERS);
162 : static void php_image_filter_gaussian_blur(INTERNAL_FUNCTION_PARAMETERS);
163 : static void php_image_filter_selective_blur(INTERNAL_FUNCTION_PARAMETERS);
164 : static void php_image_filter_mean_removal(INTERNAL_FUNCTION_PARAMETERS);
165 : static void php_image_filter_smooth(INTERNAL_FUNCTION_PARAMETERS);
166 : #endif
167 : /* End Section filters declarations */
168 : static gdImagePtr _php_image_create_from_string (zval **Data, char *tn, gdImagePtr (*ioctx_func_p)() TSRMLS_DC);
169 : static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, gdImagePtr (*func_p)(), gdImagePtr (*ioctx_func_p)());
170 : static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, void (*func_p)());
171 : static int _php_image_type(char data[8]);
172 : static void _php_image_convert(INTERNAL_FUNCTION_PARAMETERS, int image_type);
173 : static void _php_image_bw_convert(gdImagePtr im_org, gdIOCtx *out, int threshold);
174 :
175 : /* {{{ arginfo */
176 : static
177 : ZEND_BEGIN_ARG_INFO(arginfo_gd_info, 0)
178 : ZEND_END_ARG_INFO()
179 :
180 : static
181 : ZEND_BEGIN_ARG_INFO(arginfo_imageloadfont, 0)
182 : ZEND_ARG_INFO(0, filename)
183 : ZEND_END_ARG_INFO()
184 :
185 : static
186 : ZEND_BEGIN_ARG_INFO(arginfo_imagesetstyle, 0)
187 : ZEND_ARG_INFO(0, im)
188 : ZEND_ARG_INFO(0, styles) /* ARRAY_INFO(0, styles, 0) */
189 : ZEND_END_ARG_INFO()
190 :
191 : #if HAVE_LIBGD20
192 : static
193 : ZEND_BEGIN_ARG_INFO(arginfo_imagecreatetruecolor, 0)
194 : ZEND_ARG_INFO(0, x_size)
195 : ZEND_ARG_INFO(0, y_size)
196 : ZEND_END_ARG_INFO()
197 :
198 : static
199 : ZEND_BEGIN_ARG_INFO(arginfo_imageistruecolor, 0)
200 : ZEND_ARG_INFO(0, im)
201 : ZEND_END_ARG_INFO()
202 :
203 : static
204 : ZEND_BEGIN_ARG_INFO(arginfo_imagetruecolortopalette, 0)
205 : ZEND_ARG_INFO(0, im)
206 : ZEND_ARG_INFO(0, ditherFlag)
207 : ZEND_ARG_INFO(0, colorsWanted)
208 : ZEND_END_ARG_INFO()
209 : #endif
210 :
211 : #if HAVE_GD_BUNDLED
212 : static
213 : ZEND_BEGIN_ARG_INFO(arginfo_imagecolormatch, 0)
214 : ZEND_ARG_INFO(0, im1)
215 : ZEND_ARG_INFO(0, im2)
216 : ZEND_END_ARG_INFO()
217 : #endif
218 :
219 : #if HAVE_LIBGD20
220 : static
221 : ZEND_BEGIN_ARG_INFO(arginfo_imagesetthickness, 0)
222 : ZEND_ARG_INFO(0, im)
223 : ZEND_ARG_INFO(0, thickness)
224 : ZEND_END_ARG_INFO()
225 :
226 : static
227 : ZEND_BEGIN_ARG_INFO(arginfo_imagefilledellipse, 0)
228 : ZEND_ARG_INFO(0, im)
229 : ZEND_ARG_INFO(0, cx)
230 : ZEND_ARG_INFO(0, cy)
231 : ZEND_ARG_INFO(0, w)
232 : ZEND_ARG_INFO(0, h)
233 : ZEND_ARG_INFO(0, color)
234 : ZEND_END_ARG_INFO()
235 :
236 : static
237 : ZEND_BEGIN_ARG_INFO(arginfo_imagefilledarc, 0)
238 : ZEND_ARG_INFO(0, im)
239 : ZEND_ARG_INFO(0, cx)
240 : ZEND_ARG_INFO(0, cy)
241 : ZEND_ARG_INFO(0, w)
242 : ZEND_ARG_INFO(0, h)
243 : ZEND_ARG_INFO(0, s)
244 : ZEND_ARG_INFO(0, e)
245 : ZEND_ARG_INFO(0, col)
246 : ZEND_ARG_INFO(0, style)
247 : ZEND_END_ARG_INFO()
248 :
249 : static
250 : ZEND_BEGIN_ARG_INFO(arginfo_imagealphablending, 0)
251 : ZEND_ARG_INFO(0, im)
252 : ZEND_ARG_INFO(0, blend)
253 : ZEND_END_ARG_INFO()
254 :
255 : static
256 : ZEND_BEGIN_ARG_INFO(arginfo_imagesavealpha, 0)
257 : ZEND_ARG_INFO(0, im)
258 : ZEND_ARG_INFO(0, save)
259 : ZEND_END_ARG_INFO()
260 : #endif
261 :
262 : #if HAVE_GD_BUNDLED
263 : static
264 : ZEND_BEGIN_ARG_INFO(arginfo_imagelayereffect, 0)
265 : ZEND_ARG_INFO(0, im)
266 : ZEND_ARG_INFO(0, effect)
267 : ZEND_END_ARG_INFO()
268 : #endif
269 :
270 : #if HAVE_LIBGD20
271 : static
272 : ZEND_BEGIN_ARG_INFO(arginfo_imagecolorallocatealpha, 0)
273 : ZEND_ARG_INFO(0, im)
274 : ZEND_ARG_INFO(0, red)
275 : ZEND_ARG_INFO(0, green)
276 : ZEND_ARG_INFO(0, blue)
277 : ZEND_ARG_INFO(0, alpha)
278 : ZEND_END_ARG_INFO()
279 :
280 : static
281 : ZEND_BEGIN_ARG_INFO(arginfo_imagecolorresolvealpha, 0)
282 : ZEND_ARG_INFO(0, im)
283 : ZEND_ARG_INFO(0, red)
284 : ZEND_ARG_INFO(0, green)
285 : ZEND_ARG_INFO(0, blue)
286 : ZEND_ARG_INFO(0, alpha)
287 : ZEND_END_ARG_INFO()
288 :
289 : static
290 : ZEND_BEGIN_ARG_INFO(arginfo_imagecolorclosestalpha, 0)
291 : ZEND_ARG_INFO(0, im)
292 : ZEND_ARG_INFO(0, red)
293 : ZEND_ARG_INFO(0, green)
294 : ZEND_ARG_INFO(0, blue)
295 : ZEND_ARG_INFO(0, alpha)
296 : ZEND_END_ARG_INFO()
297 :
298 : static
299 : ZEND_BEGIN_ARG_INFO(arginfo_imagecolorexactalpha, 0)
300 : ZEND_ARG_INFO(0, im)
301 : ZEND_ARG_INFO(0, red)
302 : ZEND_ARG_INFO(0, green)
303 : ZEND_ARG_INFO(0, blue)
304 : ZEND_ARG_INFO(0, alpha)
305 : ZEND_END_ARG_INFO()
306 :
307 : static
308 : ZEND_BEGIN_ARG_INFO(arginfo_imagecopyresampled, 0)
309 : ZEND_ARG_INFO(0, dst_im)
310 : ZEND_ARG_INFO(0, src_im)
311 : ZEND_ARG_INFO(0, dst_x)
312 : ZEND_ARG_INFO(0, dst_y)
313 : ZEND_ARG_INFO(0, src_x)
314 : ZEND_ARG_INFO(0, src_y)
315 : ZEND_ARG_INFO(0, dst_w)
316 : ZEND_ARG_INFO(0, dst_h)
317 : ZEND_ARG_INFO(0, src_w)
318 : ZEND_ARG_INFO(0, src_h)
319 : ZEND_END_ARG_INFO()
320 : #endif
321 :
322 : #ifdef PHP_WIN32
323 : static
324 : ZEND_BEGIN_ARG_INFO_EX(arginfo_imagegrabwindow, 0, 0, 1)
325 : ZEND_ARG_INFO(0, handle)
326 : ZEND_ARG_INFO(0, client_area)
327 : ZEND_END_ARG_INFO()
328 :
329 : static
330 : ZEND_BEGIN_ARG_INFO(arginfo_imagegrabscreen, 0)
331 : ZEND_END_ARG_INFO()
332 : #endif
333 :
334 : #ifdef HAVE_GD_BUNDLED
335 : static
336 : ZEND_BEGIN_ARG_INFO_EX(arginfo_imagerotate, 0, 0, 3)
337 : ZEND_ARG_INFO(0, im)
338 : ZEND_ARG_INFO(0, angle)
339 : ZEND_ARG_INFO(0, bgdcolor)
340 : ZEND_ARG_INFO(0, ignoretransparent)
341 : ZEND_END_ARG_INFO()
342 : #endif
343 :
344 : #if HAVE_GD_IMAGESETTILE
345 : static
346 : ZEND_BEGIN_ARG_INFO(arginfo_imagesettile, 0)
347 : ZEND_ARG_INFO(0, im)
348 : ZEND_ARG_INFO(0, tile)
349 : ZEND_END_ARG_INFO()
350 : #endif
351 :
352 : #if HAVE_GD_IMAGESETBRUSH
353 : static
354 : ZEND_BEGIN_ARG_INFO(arginfo_imagesetbrush, 0)
355 : ZEND_ARG_INFO(0, im)
356 : ZEND_ARG_INFO(0, brush)
357 : ZEND_END_ARG_INFO()
358 : #endif
359 :
360 : static
361 : ZEND_BEGIN_ARG_INFO(arginfo_imagecreate, 0)
362 : ZEND_ARG_INFO(0, x_size)
363 : ZEND_ARG_INFO(0, y_size)
364 : ZEND_END_ARG_INFO()
365 :
366 : static
367 : ZEND_BEGIN_ARG_INFO(arginfo_imagetypes, 0)
368 : ZEND_END_ARG_INFO()
369 :
370 : #if HAVE_LIBGD15
371 : static
372 : ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefromstring, 0)
373 : ZEND_ARG_INFO(0, image)
374 : ZEND_END_ARG_INFO()
375 : #endif
376 :
377 : #ifdef HAVE_GD_GIF_READ
378 : static
379 : ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefromgif, 0)
380 : ZEND_ARG_INFO(0, filename)
381 : ZEND_END_ARG_INFO()
382 : #endif
383 :
384 : #ifdef HAVE_GD_JPG
385 : static
386 : ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefromjpeg, 0)
387 : ZEND_ARG_INFO(0, filename)
388 : ZEND_END_ARG_INFO()
389 : #endif
390 :
391 : #ifdef HAVE_GD_PNG
392 : static
393 : ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefrompng, 0)
394 : ZEND_ARG_INFO(0, filename)
395 : ZEND_END_ARG_INFO()
396 : #endif
397 :
398 : #ifdef HAVE_GD_XBM
399 : static
400 : ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefromxbm, 0)
401 : ZEND_ARG_INFO(0, filename)
402 : ZEND_END_ARG_INFO()
403 : #endif
404 :
405 : #if defined(HAVE_GD_XPM) && defined(HAVE_GD_BUNDLED)
406 : static
407 : ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefromxpm, 0)
408 : ZEND_ARG_INFO(0, filename)
409 : ZEND_END_ARG_INFO()
410 : #endif
411 :
412 : #ifdef HAVE_GD_WBMP
413 : static
414 : ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefromwbmp, 0)
415 : ZEND_ARG_INFO(0, filename)
416 : ZEND_END_ARG_INFO()
417 : #endif
418 :
419 : static
420 : ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefromgd, 0)
421 : ZEND_ARG_INFO(0, filename)
422 : ZEND_END_ARG_INFO()
423 :
424 : #ifdef HAVE_GD_GD2
425 : static
426 : ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefromgd2, 0)
427 : ZEND_ARG_INFO(0, filename)
428 : ZEND_END_ARG_INFO()
429 :
430 : static
431 : ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefromgd2part, 0)
432 : ZEND_ARG_INFO(0, filename)
433 : ZEND_ARG_INFO(0, srcX)
434 : ZEND_ARG_INFO(0, srcY)
435 : ZEND_ARG_INFO(0, width)
436 : ZEND_ARG_INFO(0, height)
437 : ZEND_END_ARG_INFO()
438 : #endif
439 :
440 : #if HAVE_GD_BUNDLED
441 : static
442 : ZEND_BEGIN_ARG_INFO_EX(arginfo_imagexbm, 0, 0, 2)
443 : ZEND_ARG_INFO(0, im)
444 : ZEND_ARG_INFO(0, filename)
445 : ZEND_ARG_INFO(0, foreground)
446 : ZEND_END_ARG_INFO()
447 : #endif
448 :
449 : #ifdef HAVE_GD_GIF_CREATE
450 : static
451 : ZEND_BEGIN_ARG_INFO_EX(arginfo_imagegif, 0, 0, 1)
452 : ZEND_ARG_INFO(0, im)
453 : ZEND_ARG_INFO(0, filename)
454 : ZEND_END_ARG_INFO()
455 : #endif
456 :
457 : #ifdef HAVE_GD_PNG
458 : static
459 : ZEND_BEGIN_ARG_INFO_EX(arginfo_imagepng, 0, 0, 1)
460 : ZEND_ARG_INFO(0, im)
461 : ZEND_ARG_INFO(0, filename)
462 : ZEND_END_ARG_INFO()
463 : #endif
464 :
465 : #ifdef HAVE_GD_JPG
466 : static
467 : ZEND_BEGIN_ARG_INFO_EX(arginfo_imagejpeg, 0, 0, 1)
468 : ZEND_ARG_INFO(0, im)
469 : ZEND_ARG_INFO(0, filename)
470 : ZEND_ARG_INFO(0, quality)
471 : ZEND_END_ARG_INFO()
472 : #endif
473 :
474 : #ifdef HAVE_GD_WBMP
475 : static
476 : ZEND_BEGIN_ARG_INFO_EX(arginfo_imagewbmp, 0, 0, 1)
477 : ZEND_ARG_INFO(0, im)
478 : ZEND_ARG_INFO(0, filename)
479 : ZEND_ARG_INFO(0, foreground)
480 : ZEND_END_ARG_INFO()
481 : #endif
482 :
483 : static
484 : ZEND_BEGIN_ARG_INFO_EX(arginfo_imagegd, 0, 0, 1)
485 : ZEND_ARG_INFO(0, im)
486 : ZEND_ARG_INFO(0, filename)
487 : ZEND_END_ARG_INFO()
488 :
489 : #ifdef HAVE_GD_GD2
490 : static
491 : ZEND_BEGIN_ARG_INFO_EX(arginfo_imagegd2, 0, 0, 1)
492 : ZEND_ARG_INFO(0, im)
493 : ZEND_ARG_INFO(0, filename)
494 : ZEND_ARG_INFO(0, chunk_size)
495 : ZEND_ARG_INFO(0, type)
496 : ZEND_END_ARG_INFO()
497 : #endif
498 :
499 : static
500 : ZEND_BEGIN_ARG_INFO(arginfo_imagedestroy, 0)
501 : ZEND_ARG_INFO(0, im)
502 : ZEND_END_ARG_INFO()
503 :
504 : static
505 : ZEND_BEGIN_ARG_INFO(arginfo_imagecolorallocate, 0)
506 : ZEND_ARG_INFO(0, im)
507 : ZEND_ARG_INFO(0, red)
508 : ZEND_ARG_INFO(0, green)
509 : ZEND_ARG_INFO(0, blue)
510 : ZEND_END_ARG_INFO()
511 :
512 : #if HAVE_LIBGD15
513 : static
514 : ZEND_BEGIN_ARG_INFO(arginfo_imagepalettecopy, 0)
515 : ZEND_ARG_INFO(0, dst)
516 : ZEND_ARG_INFO(0, src)
517 : ZEND_END_ARG_INFO()
518 : #endif
519 :
520 : static
521 : ZEND_BEGIN_ARG_INFO(arginfo_imagecolorat, 0)
522 : ZEND_ARG_INFO(0, im)
523 : ZEND_ARG_INFO(0, x)
524 : ZEND_ARG_INFO(0, y)
525 : ZEND_END_ARG_INFO()
526 :
527 : static
528 : ZEND_BEGIN_ARG_INFO(arginfo_imagecolorclosest, 0)
529 : ZEND_ARG_INFO(0, im)
530 : ZEND_ARG_INFO(0, red)
531 : ZEND_ARG_INFO(0, green)
532 : ZEND_ARG_INFO(0, blue)
533 : ZEND_END_ARG_INFO()
534 :
535 : #if HAVE_COLORCLOSESTHWB
536 : static
537 : ZEND_BEGIN_ARG_INFO(arginfo_imagecolorclosesthwb, 0)
538 : ZEND_ARG_INFO(0, im)
539 : ZEND_ARG_INFO(0, red)
540 : ZEND_ARG_INFO(0, green)
541 : ZEND_ARG_INFO(0, blue)
542 : ZEND_END_ARG_INFO()
543 : #endif
544 :
545 : static
546 : ZEND_BEGIN_ARG_INFO(arginfo_imagecolordeallocate, 0)
547 : ZEND_ARG_INFO(0, im)
548 : ZEND_ARG_INFO(0, index)
549 : ZEND_END_ARG_INFO()
550 :
551 : static
552 : ZEND_BEGIN_ARG_INFO(arginfo_imagecolorresolve, 0)
553 : ZEND_ARG_INFO(0, im)
554 : ZEND_ARG_INFO(0, red)
555 : ZEND_ARG_INFO(0, green)
556 : ZEND_ARG_INFO(0, blue)
557 : ZEND_END_ARG_INFO()
558 :
559 : static
560 : ZEND_BEGIN_ARG_INFO(arginfo_imagecolorexact, 0)
561 : ZEND_ARG_INFO(0, im)
562 : ZEND_ARG_INFO(0, red)
563 : ZEND_ARG_INFO(0, green)
564 : ZEND_ARG_INFO(0, blue)
565 : ZEND_END_ARG_INFO()
566 :
567 : static
568 : ZEND_BEGIN_ARG_INFO(arginfo_imagecolorset, 0)
569 : ZEND_ARG_INFO(0, im)
570 : ZEND_ARG_INFO(0, color)
571 : ZEND_ARG_INFO(0, red)
572 : ZEND_ARG_INFO(0, green)
573 : ZEND_ARG_INFO(0, blue)
574 : ZEND_END_ARG_INFO()
575 :
576 : static
577 : ZEND_BEGIN_ARG_INFO(arginfo_imagecolorsforindex, 0)
578 : ZEND_ARG_INFO(0, im)
579 : ZEND_ARG_INFO(0, index)
580 : ZEND_END_ARG_INFO()
581 :
582 : static
583 : ZEND_BEGIN_ARG_INFO(arginfo_imagegammacorrect, 0)
584 : ZEND_ARG_INFO(0, im)
585 : ZEND_ARG_INFO(0, inputgamma)
586 : ZEND_ARG_INFO(0, outputgamma)
587 : ZEND_END_ARG_INFO()
588 :
589 : static
590 : ZEND_BEGIN_ARG_INFO(arginfo_imagesetpixel, 0)
591 : ZEND_ARG_INFO(0, im)
592 : ZEND_ARG_INFO(0, x)
593 : ZEND_ARG_INFO(0, y)
594 : ZEND_ARG_INFO(0, col)
595 : ZEND_END_ARG_INFO()
596 :
597 : static
598 : ZEND_BEGIN_ARG_INFO(arginfo_imageline, 0)
599 : ZEND_ARG_INFO(0, im)
600 : ZEND_ARG_INFO(0, x1)
601 : ZEND_ARG_INFO(0, y1)
602 : ZEND_ARG_INFO(0, x2)
603 : ZEND_ARG_INFO(0, y2)
604 : ZEND_ARG_INFO(0, col)
605 : ZEND_END_ARG_INFO()
606 :
607 : static
608 : ZEND_BEGIN_ARG_INFO(arginfo_imagedashedline, 0)
609 : ZEND_ARG_INFO(0, im)
610 : ZEND_ARG_INFO(0, x1)
611 : ZEND_ARG_INFO(0, y1)
612 : ZEND_ARG_INFO(0, x2)
613 : ZEND_ARG_INFO(0, y2)
614 : ZEND_ARG_INFO(0, col)
615 : ZEND_END_ARG_INFO()
616 :
617 : static
618 : ZEND_BEGIN_ARG_INFO(arginfo_imagerectangle, 0)
619 : ZEND_ARG_INFO(0, im)
620 : ZEND_ARG_INFO(0, x1)
621 : ZEND_ARG_INFO(0, y1)
622 : ZEND_ARG_INFO(0, x2)
623 : ZEND_ARG_INFO(0, y2)
624 : ZEND_ARG_INFO(0, col)
625 : ZEND_END_ARG_INFO()
626 :
627 : static
628 : ZEND_BEGIN_ARG_INFO(arginfo_imagefilledrectangle, 0)
629 : ZEND_ARG_INFO(0, im)
630 : ZEND_ARG_INFO(0, x1)
631 : ZEND_ARG_INFO(0, y1)
632 : ZEND_ARG_INFO(0, x2)
633 : ZEND_ARG_INFO(0, y2)
634 : ZEND_ARG_INFO(0, col)
635 : ZEND_END_ARG_INFO()
636 :
637 : static
638 : ZEND_BEGIN_ARG_INFO(arginfo_imagearc, 0)
639 : ZEND_ARG_INFO(0, im)
640 : ZEND_ARG_INFO(0, cx)
641 : ZEND_ARG_INFO(0, cy)
642 : ZEND_ARG_INFO(0, w)
643 : ZEND_ARG_INFO(0, h)
644 : ZEND_ARG_INFO(0, s)
645 : ZEND_ARG_INFO(0, e)
646 : ZEND_ARG_INFO(0, col)
647 : ZEND_END_ARG_INFO()
648 :
649 : static
650 : ZEND_BEGIN_ARG_INFO(arginfo_imageellipse, 0)
651 : ZEND_ARG_INFO(0, im)
652 : ZEND_ARG_INFO(0, cx)
653 : ZEND_ARG_INFO(0, cy)
654 : ZEND_ARG_INFO(0, w)
655 : ZEND_ARG_INFO(0, h)
656 : ZEND_ARG_INFO(0, color)
657 : ZEND_END_ARG_INFO()
658 :
659 : static
660 : ZEND_BEGIN_ARG_INFO(arginfo_imagefilltoborder, 0)
661 : ZEND_ARG_INFO(0, im)
662 : ZEND_ARG_INFO(0, x)
663 : ZEND_ARG_INFO(0, y)
664 : ZEND_ARG_INFO(0, border)
665 : ZEND_ARG_INFO(0, col)
666 : ZEND_END_ARG_INFO()
667 :
668 : static
669 : ZEND_BEGIN_ARG_INFO(arginfo_imagefill, 0)
670 : ZEND_ARG_INFO(0, im)
671 : ZEND_ARG_INFO(0, x)
672 : ZEND_ARG_INFO(0, y)
673 : ZEND_ARG_INFO(0, col)
674 : ZEND_END_ARG_INFO()
675 :
676 : static
677 : ZEND_BEGIN_ARG_INFO(arginfo_imagecolorstotal, 0)
678 : ZEND_ARG_INFO(0, im)
679 : ZEND_END_ARG_INFO()
680 :
681 : static
682 : ZEND_BEGIN_ARG_INFO_EX(arginfo_imagecolortransparent, 0, 0, 1)
683 : ZEND_ARG_INFO(0, im)
684 : ZEND_ARG_INFO(0, col)
685 : ZEND_END_ARG_INFO()
686 :
687 : static
688 : ZEND_BEGIN_ARG_INFO_EX(arginfo_imageinterlace, 0, 0, 1)
689 : ZEND_ARG_INFO(0, im)
690 : ZEND_ARG_INFO(0, interlace)
691 : ZEND_END_ARG_INFO()
692 :
693 : static
694 : ZEND_BEGIN_ARG_INFO(arginfo_imagepolygon, 0)
695 : ZEND_ARG_INFO(0, im)
696 : ZEND_ARG_INFO(0, points) /* ARRAY_INFO(0, points, 0) */
697 : ZEND_ARG_INFO(0, num_pos)
698 : ZEND_ARG_INFO(0, col)
699 : ZEND_END_ARG_INFO()
700 :
701 : static
702 : ZEND_BEGIN_ARG_INFO(arginfo_imagefilledpolygon, 0)
703 : ZEND_ARG_INFO(0, im)
704 : ZEND_ARG_INFO(0, points) /* ARRAY_INFO(0, points, 0) */
705 : ZEND_ARG_INFO(0, num_pos)
706 : ZEND_ARG_INFO(0, col)
707 : ZEND_END_ARG_INFO()
708 :
709 : static
710 : ZEND_BEGIN_ARG_INFO(arginfo_imagefontwidth, 0)
711 : ZEND_ARG_INFO(0, font)
712 : ZEND_END_ARG_INFO()
713 :
714 : static
715 : ZEND_BEGIN_ARG_INFO(arginfo_imagefontheight, 0)
716 : ZEND_ARG_INFO(0, font)
717 : ZEND_END_ARG_INFO()
718 :
719 : static
720 : ZEND_BEGIN_ARG_INFO(arginfo_imagechar, 0)
721 : ZEND_ARG_INFO(0, im)
722 : ZEND_ARG_INFO(0, font)
723 : ZEND_ARG_INFO(0, x)
724 : ZEND_ARG_INFO(0, y)
725 : ZEND_ARG_INFO(0, c)
726 : ZEND_ARG_INFO(0, col)
727 : ZEND_END_ARG_INFO()
728 :
729 : static
730 : ZEND_BEGIN_ARG_INFO(arginfo_imagecharup, 0)
731 : ZEND_ARG_INFO(0, im)
732 : ZEND_ARG_INFO(0, font)
733 : ZEND_ARG_INFO(0, x)
734 : ZEND_ARG_INFO(0, y)
735 : ZEND_ARG_INFO(0, c)
736 : ZEND_ARG_INFO(0, col)
737 : ZEND_END_ARG_INFO()
738 :
739 : static
740 : ZEND_BEGIN_ARG_INFO(arginfo_imagestring, 0)
741 : ZEND_ARG_INFO(0, im)
742 : ZEND_ARG_INFO(0, font)
743 : ZEND_ARG_INFO(0, x)
744 : ZEND_ARG_INFO(0, y)
745 : ZEND_ARG_INFO(0, str)
746 : ZEND_ARG_INFO(0, col)
747 : ZEND_END_ARG_INFO()
748 :
749 : static
750 : ZEND_BEGIN_ARG_INFO(arginfo_imagestringup, 0)
751 : ZEND_ARG_INFO(0, im)
752 : ZEND_ARG_INFO(0, font)
753 : ZEND_ARG_INFO(0, x)
754 : ZEND_ARG_INFO(0, y)
755 : ZEND_ARG_INFO(0, str)
756 : ZEND_ARG_INFO(0, col)
757 : ZEND_END_ARG_INFO()
758 :
759 : static
760 : ZEND_BEGIN_ARG_INFO(arginfo_imagecopy, 0)
761 : ZEND_ARG_INFO(0, dst_im)
762 : ZEND_ARG_INFO(0, src_im)
763 : ZEND_ARG_INFO(0, dst_x)
764 : ZEND_ARG_INFO(0, dst_y)
765 : ZEND_ARG_INFO(0, src_x)
766 : ZEND_ARG_INFO(0, src_y)
767 : ZEND_ARG_INFO(0, src_w)
768 : ZEND_ARG_INFO(0, src_h)
769 : ZEND_END_ARG_INFO()
770 :
771 : #if HAVE_LIBGD15
772 : static
773 : ZEND_BEGIN_ARG_INFO(arginfo_imagecopymerge, 0)
774 : ZEND_ARG_INFO(0, src_im)
775 : ZEND_ARG_INFO(0, dst_im)
776 : ZEND_ARG_INFO(0, dst_x)
777 : ZEND_ARG_INFO(0, dst_y)
778 : ZEND_ARG_INFO(0, src_x)
779 : ZEND_ARG_INFO(0, src_y)
780 : ZEND_ARG_INFO(0, src_w)
781 : ZEND_ARG_INFO(0, src_h)
782 : ZEND_ARG_INFO(0, pct)
783 : ZEND_END_ARG_INFO()
784 :
785 : static
786 : ZEND_BEGIN_ARG_INFO(arginfo_imagecopymergegray, 0)
787 : ZEND_ARG_INFO(0, src_im)
788 : ZEND_ARG_INFO(0, dst_im)
789 : ZEND_ARG_INFO(0, dst_x)
790 : ZEND_ARG_INFO(0, dst_y)
791 : ZEND_ARG_INFO(0, src_x)
792 : ZEND_ARG_INFO(0, src_y)
793 : ZEND_ARG_INFO(0, src_w)
794 : ZEND_ARG_INFO(0, src_h)
795 : ZEND_ARG_INFO(0, pct)
796 : ZEND_END_ARG_INFO()
797 : #endif
798 :
799 : static
800 : ZEND_BEGIN_ARG_INFO(arginfo_imagecopyresized, 0)
801 : ZEND_ARG_INFO(0, dst_im)
802 : ZEND_ARG_INFO(0, src_im)
803 : ZEND_ARG_INFO(0, dst_x)
804 : ZEND_ARG_INFO(0, dst_y)
805 : ZEND_ARG_INFO(0, src_x)
806 : ZEND_ARG_INFO(0, src_y)
807 : ZEND_ARG_INFO(0, dst_w)
808 : ZEND_ARG_INFO(0, dst_h)
809 : ZEND_ARG_INFO(0, src_w)
810 : ZEND_ARG_INFO(0, src_h)
811 : ZEND_END_ARG_INFO()
812 :
813 : static
814 : ZEND_BEGIN_ARG_INFO(arginfo_imagesx, 0)
815 : ZEND_ARG_INFO(0, im)
816 : ZEND_END_ARG_INFO()
817 :
818 : static
819 : ZEND_BEGIN_ARG_INFO(arginfo_imagesy, 0)
820 : ZEND_ARG_INFO(0, im)
821 : ZEND_END_ARG_INFO()
822 :
823 : #ifdef ENABLE_GD_TTF
824 : #if HAVE_LIBGD20 && HAVE_LIBFREETYPE && HAVE_GD_STRINGFTEX
825 : static
826 : ZEND_BEGIN_ARG_INFO_EX(arginfo_imageftbbox, 0, 0, 4)
827 : ZEND_ARG_INFO(0, size)
828 : ZEND_ARG_INFO(0, angle)
829 : ZEND_ARG_INFO(0, font_file)
830 : ZEND_ARG_INFO(0, text)
831 : ZEND_ARG_INFO(0, extrainfo) /* ARRAY_INFO(0, extrainfo, 0) */
832 : ZEND_END_ARG_INFO()
833 :
834 : static
835 : ZEND_BEGIN_ARG_INFO_EX(arginfo_imagefttext, 0, 0, 8)
836 : ZEND_ARG_INFO(0, im)
837 : ZEND_ARG_INFO(0, size)
838 : ZEND_ARG_INFO(0, angle)
839 : ZEND_ARG_INFO(0, x)
840 : ZEND_ARG_INFO(0, y)
841 : ZEND_ARG_INFO(0, col)
842 : ZEND_ARG_INFO(0, font_file)
843 : ZEND_ARG_INFO(0, text)
844 : ZEND_ARG_INFO(0, extrainfo) /* ARRAY_INFO(0, extrainfo, 0) */
845 : ZEND_END_ARG_INFO()
846 : #endif
847 :
848 : static
849 : ZEND_BEGIN_ARG_INFO(arginfo_imagettfbbox, 0)
850 : ZEND_ARG_INFO(0, size)
851 : ZEND_ARG_INFO(0, angle)
852 : ZEND_ARG_INFO(0, font_file)
853 : ZEND_ARG_INFO(0, text)
854 : ZEND_END_ARG_INFO()
855 :
856 : static
857 : ZEND_BEGIN_ARG_INFO(arginfo_imagettftext, 0)
858 : ZEND_ARG_INFO(0, im)
859 : ZEND_ARG_INFO(0, size)
860 : ZEND_ARG_INFO(0, angle)
861 : ZEND_ARG_INFO(0, x)
862 : ZEND_ARG_INFO(0, y)
863 : ZEND_ARG_INFO(0, col)
864 : ZEND_ARG_INFO(0, font_file)
865 : ZEND_ARG_INFO(0, text)
866 : ZEND_END_ARG_INFO()
867 : #endif
868 :
869 : #ifdef HAVE_LIBT1
870 : static
871 : ZEND_BEGIN_ARG_INFO(arginfo_imagepsloadfont, 0)
872 : ZEND_ARG_INFO(0, pathname)
873 : ZEND_END_ARG_INFO()
874 :
875 : /*
876 : static
877 : ZEND_BEGIN_ARG_INFO(arginfo_imagepscopyfont, 0)
878 : ZEND_ARG_INFO(0, font_index)
879 : ZEND_END_ARG_INFO()
880 : */
881 :
882 : static
883 : ZEND_BEGIN_ARG_INFO(arginfo_imagepsfreefont, 0)
884 : ZEND_ARG_INFO(0, font_index)
885 : ZEND_END_ARG_INFO()
886 :
887 : static
888 : ZEND_BEGIN_ARG_INFO(arginfo_imagepsencodefont, 0)
889 : ZEND_ARG_INFO(0, font_index)
890 : ZEND_ARG_INFO(0, filename)
891 : ZEND_END_ARG_INFO()
892 :
893 : static
894 : ZEND_BEGIN_ARG_INFO(arginfo_imagepsextendfont, 0)
895 : ZEND_ARG_INFO(0, font_index)
896 : ZEND_ARG_INFO(0, extend)
897 : ZEND_END_ARG_INFO()
898 :
899 : static
900 : ZEND_BEGIN_ARG_INFO(arginfo_imagepsslantfont, 0)
901 : ZEND_ARG_INFO(0, font_index)
902 : ZEND_ARG_INFO(0, slant)
903 : ZEND_END_ARG_INFO()
904 :
905 : static
906 : ZEND_BEGIN_ARG_INFO_EX(arginfo_imagepstext, 0, 0, 8)
907 : ZEND_ARG_INFO(0, im)
908 : ZEND_ARG_INFO(0, text)
909 : ZEND_ARG_INFO(0, font)
910 : ZEND_ARG_INFO(0, size)
911 : ZEND_ARG_INFO(0, foreground)
912 : ZEND_ARG_INFO(0, background)
913 : ZEND_ARG_INFO(0, xcoord)
914 : ZEND_ARG_INFO(0, ycoord)
915 : ZEND_ARG_INFO(0, space)
916 : ZEND_ARG_INFO(0, tightness)
917 : ZEND_ARG_INFO(0, angle)
918 : ZEND_ARG_INFO(0, antialias)
919 : ZEND_END_ARG_INFO()
920 :
921 : static
922 : ZEND_BEGIN_ARG_INFO_EX(arginfo_imagepsbbox, 0, 0, 3)
923 : ZEND_ARG_INFO(0, text)
924 : ZEND_ARG_INFO(0, font)
925 : ZEND_ARG_INFO(0, size)
926 : ZEND_ARG_INFO(0, space)
927 : ZEND_ARG_INFO(0, tightness)
928 : ZEND_ARG_INFO(0, angle)
929 : ZEND_END_ARG_INFO()
930 : #endif
931 :
932 : #ifdef HAVE_GD_WBMP
933 : static
934 : ZEND_BEGIN_ARG_INFO_EX(arginfo_image2wbmp, 0, 0, 1)
935 : ZEND_ARG_INFO(0, im)
936 : ZEND_ARG_INFO(0, filename)
937 : ZEND_ARG_INFO(0, threshold)
938 : ZEND_END_ARG_INFO()
939 : #endif
940 :
941 : #if defined(HAVE_GD_JPG) && defined(HAVE_GD_WBMP)
942 : static
943 : ZEND_BEGIN_ARG_INFO(arginfo_jpeg2wbmp, 0)
944 : ZEND_ARG_INFO(0, f_org)
945 : ZEND_ARG_INFO(0, f_dest)
946 : ZEND_ARG_INFO(0, d_height)
947 : ZEND_ARG_INFO(0, d_width)
948 : ZEND_ARG_INFO(0, d_threshold)
949 : ZEND_END_ARG_INFO()
950 : #endif
951 :
952 : #if defined(HAVE_GD_PNG) && defined(HAVE_GD_WBMP)
953 : static
954 : ZEND_BEGIN_ARG_INFO(arginfo_png2wbmp, 0)
955 : ZEND_ARG_INFO(0, f_org)
956 : ZEND_ARG_INFO(0, f_dest)
957 : ZEND_ARG_INFO(0, d_height)
958 : ZEND_ARG_INFO(0, d_width)
959 : ZEND_ARG_INFO(0, d_threshold)
960 : ZEND_END_ARG_INFO()
961 : #endif
962 :
963 : #ifdef HAVE_GD_BUNDLED
964 : static
965 : ZEND_BEGIN_ARG_INFO_EX(arginfo_imagefilter, 0, 0, 2)
966 : ZEND_ARG_INFO(0, im)
967 : ZEND_ARG_INFO(0, filtertype)
968 : ZEND_ARG_INFO(0, arg1)
969 : ZEND_ARG_INFO(0, arg2)
970 : ZEND_ARG_INFO(0, arg3)
971 : ZEND_ARG_INFO(0, arg4)
972 : ZEND_END_ARG_INFO()
973 :
974 : static
975 : ZEND_BEGIN_ARG_INFO(arginfo_imageconvolution, 0)
976 : ZEND_ARG_INFO(0, im)
977 : ZEND_ARG_INFO(0, matrix3x3) /* ARRAY_INFO(0, matrix3x3, 0) */
978 : ZEND_ARG_INFO(0, div)
979 : ZEND_ARG_INFO(0, offset)
980 : ZEND_END_ARG_INFO()
981 : #endif
982 :
983 : #ifdef HAVE_GD_BUNDLED
984 : static
985 : ZEND_BEGIN_ARG_INFO(arginfo_imageantialias, 0)
986 : ZEND_ARG_INFO(0, im)
987 : ZEND_ARG_INFO(0, on)
988 : ZEND_END_ARG_INFO()
989 : #endif
990 :
991 : /* }}} */
992 :
993 : /* {{{ gd_functions[]
994 : */
995 : zend_function_entry gd_functions[] = {
996 : PHP_FE(gd_info, arginfo_gd_info)
997 : PHP_FE(imagearc, arginfo_imagearc)
998 : PHP_FE(imageellipse, arginfo_imageellipse)
999 : PHP_FE(imagechar, arginfo_imagechar)
1000 : PHP_FE(imagecharup, arginfo_imagecharup)
1001 : PHP_FE(imagecolorat, arginfo_imagecolorat)
1002 : PHP_FE(imagecolorallocate, arginfo_imagecolorallocate)
1003 : #if HAVE_LIBGD15
1004 : PHP_FE(imagepalettecopy, arginfo_imagepalettecopy)
1005 : PHP_FE(imagecreatefromstring, arginfo_imagecreatefromstring)
1006 : #endif
1007 : PHP_FE(imagecolorclosest, arginfo_imagecolorclosest)
1008 : #if HAVE_COLORCLOSESTHWB
1009 : PHP_FE(imagecolorclosesthwb, arginfo_imagecolorclosesthwb)
1010 : #endif
1011 : PHP_FE(imagecolordeallocate, arginfo_imagecolordeallocate)
1012 : PHP_FE(imagecolorresolve, arginfo_imagecolorresolve)
1013 : PHP_FE(imagecolorexact, arginfo_imagecolorexact)
1014 : PHP_FE(imagecolorset, arginfo_imagecolorset)
1015 : PHP_FE(imagecolortransparent, arginfo_imagecolortransparent)
1016 : PHP_FE(imagecolorstotal, arginfo_imagecolorstotal)
1017 : PHP_FE(imagecolorsforindex, arginfo_imagecolorsforindex)
1018 : PHP_FE(imagecopy, arginfo_imagecopy)
1019 : #if HAVE_LIBGD15
1020 : PHP_FE(imagecopymerge, arginfo_imagecopymerge)
1021 : PHP_FE(imagecopymergegray, arginfo_imagecopymergegray)
1022 : #endif
1023 : PHP_FE(imagecopyresized, arginfo_imagecopyresized)
1024 : PHP_FE(imagecreate, arginfo_imagecreate)
1025 : #if HAVE_LIBGD20
1026 : PHP_FE(imagecreatetruecolor, arginfo_imagecreatetruecolor)
1027 : PHP_FE(imageistruecolor, arginfo_imageistruecolor)
1028 : PHP_FE(imagetruecolortopalette, arginfo_imagetruecolortopalette)
1029 : PHP_FE(imagesetthickness, arginfo_imagesetthickness)
1030 : PHP_FE(imagefilledarc, arginfo_imagefilledarc)
1031 : PHP_FE(imagefilledellipse, arginfo_imagefilledellipse)
1032 : PHP_FE(imagealphablending, arginfo_imagealphablending)
1033 : PHP_FE(imagesavealpha, arginfo_imagesavealpha)
1034 : PHP_FE(imagecolorallocatealpha, arginfo_imagecolorallocatealpha)
1035 : PHP_FE(imagecolorresolvealpha, arginfo_imagecolorresolvealpha)
1036 : PHP_FE(imagecolorclosestalpha, arginfo_imagecolorclosestalpha)
1037 : PHP_FE(imagecolorexactalpha, arginfo_imagecolorexactalpha)
1038 : PHP_FE(imagecopyresampled, arginfo_imagecopyresampled)
1039 : #endif
1040 :
1041 : #ifdef PHP_WIN32
1042 : PHP_FE(imagegrabwindow, arginfo_imagegrabwindow)
1043 : PHP_FE(imagegrabscreen, arginfo_imagegrabscreen)
1044 : #endif
1045 :
1046 : #ifdef HAVE_GD_BUNDLED
1047 : PHP_FE(imagerotate, arginfo_imagerotate)
1048 : PHP_FE(imageantialias, arginfo_imageantialias)
1049 : #endif
1050 :
1051 : #if HAVE_GD_IMAGESETTILE
1052 : PHP_FE(imagesettile, arginfo_imagesettile)
1053 : #endif
1054 :
1055 : #if HAVE_GD_IMAGESETBRUSH
1056 : PHP_FE(imagesetbrush, arginfo_imagesetbrush)
1057 : #endif
1058 :
1059 : PHP_FE(imagesetstyle, arginfo_imagesetstyle)
1060 :
1061 : #ifdef HAVE_GD_PNG
1062 : PHP_FE(imagecreatefrompng, arginfo_imagecreatefrompng)
1063 : #endif
1064 : #ifdef HAVE_GD_GIF_READ
1065 : PHP_FE(imagecreatefromgif, arginfo_imagecreatefromgif)
1066 : #endif
1067 : #ifdef HAVE_GD_JPG
1068 : PHP_FE(imagecreatefromjpeg, arginfo_imagecreatefromjpeg)
1069 : #endif
1070 : #ifdef HAVE_GD_WBMP
1071 : PHP_FE(imagecreatefromwbmp, arginfo_imagecreatefromwbmp)
1072 : #endif
1073 : #ifdef HAVE_GD_XBM
1074 : PHP_FE(imagecreatefromxbm, arginfo_imagecreatefromxbm)
1075 : #endif
1076 : #if defined(HAVE_GD_XPM) && defined(HAVE_GD_BUNDLED)
1077 : PHP_FE(imagecreatefromxpm, arginfo_imagecreatefromxpm)
1078 : #endif
1079 : PHP_FE(imagecreatefromgd, arginfo_imagecreatefromgd)
1080 : #ifdef HAVE_GD_GD2
1081 : PHP_FE(imagecreatefromgd2, arginfo_imagecreatefromgd2)
1082 : PHP_FE(imagecreatefromgd2part, arginfo_imagecreatefromgd2part)
1083 : #endif
1084 : #ifdef HAVE_GD_PNG
1085 : PHP_FE(imagepng, arginfo_imagepng)
1086 : #endif
1087 : #ifdef HAVE_GD_GIF_CREATE
1088 : PHP_FE(imagegif, arginfo_imagegif)
1089 : #endif
1090 : #ifdef HAVE_GD_JPG
1091 : PHP_FE(imagejpeg, arginfo_imagejpeg)
1092 : #endif
1093 : #ifdef HAVE_GD_WBMP
1094 : PHP_FE(imagewbmp, arginfo_imagewbmp)
1095 : #endif
1096 : PHP_FE(imagegd, arginfo_imagegd)
1097 : #ifdef HAVE_GD_GD2
1098 : PHP_FE(imagegd2, arginfo_imagegd2)
1099 : #endif
1100 :
1101 : PHP_FE(imagedestroy, arginfo_imagedestroy)
1102 : PHP_FE(imagegammacorrect, arginfo_imagegammacorrect)
1103 : PHP_FE(imagefill, arginfo_imagefill)
1104 : PHP_FE(imagefilledpolygon, arginfo_imagefilledpolygon)
1105 : PHP_FE(imagefilledrectangle, arginfo_imagefilledrectangle)
1106 : PHP_FE(imagefilltoborder, arginfo_imagefilltoborder)
1107 : PHP_FE(imagefontwidth, arginfo_imagefontwidth)
1108 : PHP_FE(imagefontheight, arginfo_imagefontheight)
1109 : PHP_FE(imageinterlace, arginfo_imageinterlace)
1110 : PHP_FE(imageline, arginfo_imageline)
1111 : PHP_FE(imageloadfont, arginfo_imageloadfont)
1112 : PHP_FE(imagepolygon, arginfo_imagepolygon)
1113 : PHP_FE(imagerectangle, arginfo_imagerectangle)
1114 : PHP_FE(imagesetpixel, arginfo_imagesetpixel)
1115 : PHP_FE(imagestring, arginfo_imagestring)
1116 : PHP_FE(imagestringup, arginfo_imagestringup)
1117 : PHP_FE(imagesx, arginfo_imagesx)
1118 : PHP_FE(imagesy, arginfo_imagesy)
1119 : PHP_FE(imagedashedline, arginfo_imagedashedline)
1120 :
1121 : #ifdef ENABLE_GD_TTF
1122 : PHP_FE(imagettfbbox, arginfo_imagettfbbox)
1123 : PHP_FE(imagettftext, arginfo_imagettftext)
1124 : #if HAVE_LIBGD20 && HAVE_LIBFREETYPE && HAVE_GD_STRINGFTEX
1125 : PHP_FE(imageftbbox, arginfo_imageftbbox)
1126 : PHP_FE(imagefttext, arginfo_imagefttext)
1127 : #endif
1128 : #endif
1129 :
1130 : #ifdef HAVE_LIBT1
1131 : PHP_FE(imagepsloadfont, arginfo_imagepsloadfont)
1132 : /*
1133 : PHP_FE(imagepscopyfont, arginfo_imagepscopyfont)
1134 : */
1135 : PHP_FE(imagepsfreefont, arginfo_imagepsfreefont)
1136 : PHP_FE(imagepsencodefont, arginfo_imagepsencodefont)
1137 : PHP_FE(imagepsextendfont, arginfo_imagepsextendfont)
1138 : PHP_FE(imagepsslantfont, arginfo_imagepsslantfont)
1139 : PHP_FE(imagepstext, arginfo_imagepstext)
1140 : PHP_FE(imagepsbbox, arginfo_imagepsbbox)
1141 : #endif
1142 : PHP_FE(imagetypes, arginfo_imagetypes)
1143 :
1144 : #if defined(HAVE_GD_JPG) && defined(HAVE_GD_WBMP)
1145 : PHP_FE(jpeg2wbmp, arginfo_jpeg2wbmp)
1146 : #endif
1147 : #if defined(HAVE_GD_PNG) && defined(HAVE_GD_WBMP)
1148 : PHP_FE(png2wbmp, arginfo_png2wbmp)
1149 : #endif
1150 : #ifdef HAVE_GD_WBMP
1151 : PHP_FE(image2wbmp, arginfo_image2wbmp)
1152 : #endif
1153 : #if HAVE_GD_BUNDLED
1154 : PHP_FE(imagelayereffect, arginfo_imagelayereffect)
1155 : PHP_FE(imagecolormatch, arginfo_imagecolormatch)
1156 : PHP_FE(imagexbm, arginfo_imagexbm)
1157 : #endif
1158 : /* gd filters */
1159 : #ifdef HAVE_GD_BUNDLED
1160 : PHP_FE(imagefilter, arginfo_imagefilter)
1161 : PHP_FE(imageconvolution, arginfo_imageconvolution)
1162 : #endif
1163 :
1164 : {NULL, NULL, NULL}
1165 : };
1166 : /* }}} */
1167 :
1168 : zend_module_entry gd_module_entry = {
1169 : STANDARD_MODULE_HEADER,
1170 : "gd",
1171 : gd_functions,
1172 : PHP_MINIT(gd),
1173 : #if HAVE_LIBT1 || HAVE_GD_FONTMUTEX
1174 : PHP_MSHUTDOWN(gd),
1175 : #else
1176 : NULL,
1177 : #endif
1178 : NULL,
1179 : #if HAVE_LIBGD20 && HAVE_GD_STRINGFT && (HAVE_LIBFREETYPE && (HAVE_GD_FONTCACHESHUTDOWN || HAVE_GD_FREEFONTCACHE))
1180 : PHP_RSHUTDOWN(gd),
1181 : #else
1182 : NULL,
1183 : #endif
1184 : PHP_MINFO(gd),
1185 : NO_VERSION_YET,
1186 : STANDARD_MODULE_PROPERTIES
1187 : };
1188 :
1189 : #ifdef COMPILE_DL_GD
1190 : ZEND_GET_MODULE(gd)
1191 : #endif
1192 :
1193 : /* {{{ PHP_INI_BEGIN */
1194 : PHP_INI_BEGIN()
1195 : PHP_INI_ENTRY("gd.jpeg_ignore_warning", "0", PHP_INI_ALL, NULL)
1196 : PHP_INI_END()
1197 : /* }}} */
1198 :
1199 : /* {{{ php_free_gd_image
1200 : */
1201 : static void php_free_gd_image(zend_rsrc_list_entry *rsrc TSRMLS_DC)
1202 249 : {
1203 249 : gdImageDestroy((gdImagePtr) rsrc->ptr);
1204 249 : }
1205 : /* }}} */
1206 :
1207 : /* {{{ php_free_gd_font
1208 : */
1209 : static void php_free_gd_font(zend_rsrc_list_entry *rsrc TSRMLS_DC)
1210 0 : {
1211 0 : gdFontPtr fp = (gdFontPtr) rsrc->ptr;
1212 :
1213 0 : if (fp->data) {
1214 0 : efree(fp->data);
1215 : }
1216 :
1217 0 : efree(fp);
1218 0 : }
1219 : /* }}} */
1220 :
1221 :
1222 : /* {{{ PHP_MSHUTDOWN_FUNCTION
1223 : */
1224 : #if HAVE_LIBT1 || HAVE_GD_FONTMUTEX
1225 : PHP_MSHUTDOWN_FUNCTION(gd)
1226 13597 : {
1227 : #if HAVE_LIBT1
1228 : T1_CloseLib();
1229 : #endif
1230 : #if HAVE_GD_FONTMUTEX && HAVE_LIBFREETYPE
1231 13597 : gdFontCacheMutexShutdown();
1232 : #endif
1233 13597 : return SUCCESS;
1234 : }
1235 : #endif
1236 : /* }}} */
1237 :
1238 :
1239 : /* {{{ PHP_MINIT_FUNCTION
1240 : */
1241 : PHP_MINIT_FUNCTION(gd)
1242 13565 : {
1243 13565 : le_gd = zend_register_list_destructors_ex(php_free_gd_image, NULL, "gd", module_number);
1244 13565 : le_gd_font = zend_register_list_destructors_ex(php_free_gd_font, NULL, "gd font", module_number);
1245 :
1246 : #if HAVE_GD_FONTMUTEX && HAVE_LIBFREETYPE
1247 13565 : gdFontCacheMutexSetup();
1248 : #endif
1249 : #if HAVE_LIBT1
1250 : T1_SetBitmapPad(8);
1251 : T1_InitLib(NO_LOGFILE | IGNORE_CONFIGFILE | IGNORE_FONTDATABASE);
1252 : T1_SetLogLevel(T1LOG_DEBUG);
1253 : le_ps_font = zend_register_list_destructors_ex(php_free_ps_font, NULL, "gd PS font", module_number);
1254 : le_ps_enc = zend_register_list_destructors_ex(php_free_ps_enc, NULL, "gd PS encoding", module_number);
1255 : #endif
1256 :
1257 13565 : REGISTER_INI_ENTRIES();
1258 :
1259 13565 : REGISTER_LONG_CONSTANT("IMG_GIF", 1, CONST_CS | CONST_PERSISTENT);
1260 13565 : REGISTER_LONG_CONSTANT("IMG_JPG", 2, CONST_CS | CONST_PERSISTENT);
1261 13565 : REGISTER_LONG_CONSTANT("IMG_JPEG", 2, CONST_CS | CONST_PERSISTENT);
1262 13565 : REGISTER_LONG_CONSTANT("IMG_PNG", 4, CONST_CS | CONST_PERSISTENT);
1263 13565 : REGISTER_LONG_CONSTANT("IMG_WBMP", 8, CONST_CS | CONST_PERSISTENT);
1264 13565 : REGISTER_LONG_CONSTANT("IMG_XPM", 16, CONST_CS | CONST_PERSISTENT);
1265 : #ifdef gdTiled
1266 : /* special colours for gd */
1267 13565 : REGISTER_LONG_CONSTANT("IMG_COLOR_TILED", gdTiled, CONST_CS | CONST_PERSISTENT);
1268 13565 : REGISTER_LONG_CONSTANT("IMG_COLOR_STYLED", gdStyled, CONST_CS | CONST_PERSISTENT);
1269 13565 : REGISTER_LONG_CONSTANT("IMG_COLOR_BRUSHED", gdBrushed, CONST_CS | CONST_PERSISTENT);
1270 13565 : REGISTER_LONG_CONSTANT("IMG_COLOR_STYLEDBRUSHED", gdStyledBrushed, CONST_CS | CONST_PERSISTENT);
1271 13565 : REGISTER_LONG_CONSTANT("IMG_COLOR_TRANSPARENT", gdTransparent, CONST_CS | CONST_PERSISTENT);
1272 : #endif
1273 : #if HAVE_LIBGD20
1274 : /* for imagefilledarc */
1275 13565 : REGISTER_LONG_CONSTANT("IMG_ARC_ROUNDED", gdArc, CONST_CS | CONST_PERSISTENT);
1276 13565 : REGISTER_LONG_CONSTANT("IMG_ARC_PIE", gdPie, CONST_CS | CONST_PERSISTENT);
1277 13565 : REGISTER_LONG_CONSTANT("IMG_ARC_CHORD", gdChord, CONST_CS | CONST_PERSISTENT);
1278 13565 : REGISTER_LONG_CONSTANT("IMG_ARC_NOFILL", gdNoFill, CONST_CS | CONST_PERSISTENT);
1279 13565 : REGISTER_LONG_CONSTANT("IMG_ARC_EDGED", gdEdged, CONST_CS | CONST_PERSISTENT);
1280 : #endif
1281 : /* GD2 image format types */
1282 : #ifdef GD2_FMT_RAW
1283 13565 : REGISTER_LONG_CONSTANT("IMG_GD2_RAW", GD2_FMT_RAW, CONST_CS | CONST_PERSISTENT);
1284 : #endif
1285 : #ifdef GD2_FMT_COMPRESSED
1286 13565 : REGISTER_LONG_CONSTANT("IMG_GD2_COMPRESSED", GD2_FMT_COMPRESSED, CONST_CS | CONST_PERSISTENT);
1287 : #endif
1288 : #if HAVE_GD_BUNDLED
1289 13565 : REGISTER_LONG_CONSTANT("IMG_EFFECT_REPLACE", gdEffectReplace, CONST_CS | CONST_PERSISTENT);
1290 13565 : REGISTER_LONG_CONSTANT("IMG_EFFECT_ALPHABLEND", gdEffectAlphaBlend, CONST_CS | CONST_PERSISTENT);
1291 13565 : REGISTER_LONG_CONSTANT("IMG_EFFECT_NORMAL", gdEffectNormal, CONST_CS | CONST_PERSISTENT);
1292 13565 : REGISTER_LONG_CONSTANT("IMG_EFFECT_OVERLAY", gdEffectOverlay, CONST_CS | CONST_PERSISTENT);
1293 13565 : REGISTER_LONG_CONSTANT("GD_BUNDLED", 1, CONST_CS | CONST_PERSISTENT);
1294 :
1295 : /* Section Filters */
1296 13565 : REGISTER_LONG_CONSTANT("IMG_FILTER_NEGATE", IMAGE_FILTER_NEGATE, CONST_CS | CONST_PERSISTENT);
1297 13565 : REGISTER_LONG_CONSTANT("IMG_FILTER_GRAYSCALE", IMAGE_FILTER_GRAYSCALE, CONST_CS | CONST_PERSISTENT);
1298 13565 : REGISTER_LONG_CONSTANT("IMG_FILTER_BRIGHTNESS", IMAGE_FILTER_BRIGHTNESS, CONST_CS | CONST_PERSISTENT);
1299 13565 : REGISTER_LONG_CONSTANT("IMG_FILTER_CONTRAST", IMAGE_FILTER_CONTRAST, CONST_CS | CONST_PERSISTENT);
1300 13565 : REGISTER_LONG_CONSTANT("IMG_FILTER_COLORIZE", IMAGE_FILTER_COLORIZE, CONST_CS | CONST_PERSISTENT);
1301 13565 : REGISTER_LONG_CONSTANT("IMG_FILTER_EDGEDETECT", IMAGE_FILTER_EDGEDETECT, CONST_CS | CONST_PERSISTENT);
1302 13565 : REGISTER_LONG_CONSTANT("IMG_FILTER_GAUSSIAN_BLUR", IMAGE_FILTER_GAUSSIAN_BLUR, CONST_CS | CONST_PERSISTENT);
1303 13565 : REGISTER_LONG_CONSTANT("IMG_FILTER_SELECTIVE_BLUR", IMAGE_FILTER_SELECTIVE_BLUR, CONST_CS | CONST_PERSISTENT);
1304 13565 : REGISTER_LONG_CONSTANT("IMG_FILTER_EMBOSS", IMAGE_FILTER_EMBOSS, CONST_CS | CONST_PERSISTENT);
1305 13565 : REGISTER_LONG_CONSTANT("IMG_FILTER_MEAN_REMOVAL", IMAGE_FILTER_MEAN_REMOVAL, CONST_CS | CONST_PERSISTENT);
1306 13565 : REGISTER_LONG_CONSTANT("IMG_FILTER_SMOOTH", IMAGE_FILTER_SMOOTH, CONST_CS | CONST_PERSISTENT);
1307 : /* End Section Filters */
1308 : #else
1309 : REGISTER_LONG_CONSTANT("GD_BUNDLED", 0, CONST_CS | CONST_PERSISTENT);
1310 : #endif
1311 :
1312 : #ifdef GD_VERSION_STRING
1313 13565 : REGISTER_STRING_CONSTANT("GD_VERSION", GD_VERSION_STRING, CONST_CS | CONST_PERSISTENT);
1314 : #endif
1315 :
1316 : #if defined(GD_MAJOR_VERSION) && defined(GD_MINOR_VERSION) && defined(GD_RELEASE_VERSION) && defined(GD_EXTRA_VERSION)
1317 13565 : REGISTER_LONG_CONSTANT("GD_MAJOR_VERSION", GD_MAJOR_VERSION, CONST_CS | CONST_PERSISTENT);
1318 13565 : REGISTER_LONG_CONSTANT("GD_MINOR_VERSION", GD_MINOR_VERSION, CONST_CS | CONST_PERSISTENT);
1319 13565 : REGISTER_LONG_CONSTANT("GD_RELEASE_VERSION", GD_RELEASE_VERSION, CONST_CS | CONST_PERSISTENT);
1320 13565 : REGISTER_STRING_CONSTANT("GD_EXTRA_VERSION", GD_EXTRA_VERSION, CONST_CS | CONST_PERSISTENT);
1321 : #endif
1322 :
1323 :
1324 : #ifdef HAVE_GD_PNG
1325 :
1326 : /*
1327 : * cannot include #include "png.h"
1328 : * /usr/include/pngconf.h:310:2: error: #error png.h already includes setjmp.h with some additional fixup.
1329 : * as error, use the values for now...
1330 : */
1331 13565 : REGISTER_LONG_CONSTANT("PNG_NO_FILTER", 0x00, CONST_CS | CONST_PERSISTENT);
1332 13565 : REGISTER_LONG_CONSTANT("PNG_FILTER_NONE", 0x08, CONST_CS | CONST_PERSISTENT);
1333 13565 : REGISTER_LONG_CONSTANT("PNG_FILTER_SUB", 0x10, CONST_CS | CONST_PERSISTENT);
1334 13565 : REGISTER_LONG_CONSTANT("PNG_FILTER_UP", 0x20, CONST_CS | CONST_PERSISTENT);
1335 13565 : REGISTER_LONG_CONSTANT("PNG_FILTER_AVG", 0x40, CONST_CS | CONST_PERSISTENT);
1336 13565 : REGISTER_LONG_CONSTANT("PNG_FILTER_PAETH", 0x80, CONST_CS | CONST_PERSISTENT);
1337 13565 : REGISTER_LONG_CONSTANT("PNG_ALL_FILTERS", 0x08 | 0x10 | 0x20 | 0x40 | 0x80, CONST_CS | CONST_PERSISTENT);
1338 : #endif
1339 13565 : return SUCCESS;
1340 : }
1341 : /* }}} */
1342 :
1343 : /* {{{ PHP_RSHUTDOWN_FUNCTION
1344 : */
1345 : #if HAVE_LIBGD20 && HAVE_GD_STRINGFT && (HAVE_LIBFREETYPE && (HAVE_GD_FONTCACHESHUTDOWN || HAVE_GD_FREEFONTCACHE))
1346 : PHP_RSHUTDOWN_FUNCTION(gd)
1347 13584 : {
1348 : #if HAVE_GD_FONTCACHESHUTDOWN
1349 13584 : gdFontCacheShutdown();
1350 : #else
1351 : gdFreeFontCache();
1352 : #endif
1353 13584 : return SUCCESS;
1354 : }
1355 : #endif
1356 : /* }}} */
1357 :
1358 : #if HAVE_GD_BUNDLED
1359 : #define PHP_GD_VERSION_STRING "bundled (2.0.34 compatible)"
1360 : #elif HAVE_LIBGD20
1361 : #define PHP_GD_VERSION_STRING "2.0 or higher"
1362 : #elif HAVE_GDIMAGECOLORRESOLVE
1363 : #define PHP_GD_VERSION_STRING "1.6.2 or higher"
1364 : #elif HAVE_LIBGD13
1365 : #define PHP_GD_VERSION_STRING "between 1.3 and 1.6.1"
1366 : #else
1367 : #define PHP_GD_VERSION_STRING "1.2"
1368 : #endif
1369 :
1370 : /* {{{ PHP_MINFO_FUNCTION
1371 : */
1372 : PHP_MINFO_FUNCTION(gd)
1373 6 : {
1374 6 : php_info_print_table_start();
1375 6 : php_info_print_table_row(2, "GD Support", "enabled");
1376 :
1377 : /* need to use a PHPAPI function here because it is external module in windows */
1378 :
1379 6 : php_info_print_table_row(2, "GD Version", PHP_GD_VERSION_STRING);
1380 :
1381 : #ifdef ENABLE_GD_TTF
1382 6 : php_info_print_table_row(2, "FreeType Support", "enabled");
1383 : #if HAVE_LIBFREETYPE
1384 6 : php_info_print_table_row(2, "FreeType Linkage", "with freetype");
1385 : {
1386 : char tmp[256];
1387 : #ifdef FREETYPE_PATCH
1388 6 : snprintf(tmp, sizeof(tmp), "%d.%d.%d", FREETYPE_MAJOR, FREETYPE_MINOR, FREETYPE_PATCH);
1389 : #elif defined(FREETYPE_MAJOR)
1390 : snprintf(tmp, sizeof(tmp), "%d.%d", FREETYPE_MAJOR, FREETYPE_MINOR);
1391 : #else
1392 : snprintf(tmp, sizeof(tmp), "1.x");
1393 : #endif
1394 6 : php_info_print_table_row(2, "FreeType Version", tmp);
1395 : }
1396 : #elif HAVE_LIBTTF
1397 : php_info_print_table_row(2, "FreeType Linkage", "with TTF library");
1398 : {
1399 : char tmp[256];
1400 : snprintf(tmp, sizeof(tmp), "%d.%d", TT_FREETYPE_MAJOR, TT_FREETYPE_MINOR);
1401 : php_info_print_table_row(2, "FreeType Version", tmp);
1402 : }
1403 : #else
1404 : php_info_print_table_row(2, "FreeType Linkage", "with unknown library");
1405 : #endif
1406 : #endif
1407 :
1408 : #ifdef HAVE_LIBT1
1409 : php_info_print_table_row(2, "T1Lib Support", "enabled");
1410 : #endif
1411 :
1412 : /* this next part is stupid ... if I knew better, I'd put them all on one row (cmv) */
1413 :
1414 : #ifdef HAVE_GD_GIF_READ
1415 6 : php_info_print_table_row(2, "GIF Read Support", "enabled");
1416 : #endif
1417 : #ifdef HAVE_GD_GIF_CREATE
1418 6 : php_info_print_table_row(2, "GIF Create Support", "enabled");
1419 : #endif
1420 : #ifdef HAVE_GD_JPG
1421 6 : php_info_print_table_row(2, "JPG Support", "enabled");
1422 : #endif
1423 : #ifdef HAVE_GD_PNG
1424 6 : php_info_print_table_row(2, "PNG Support", "enabled");
1425 : #endif
1426 : #ifdef HAVE_GD_WBMP
1427 6 : php_info_print_table_row(2, "WBMP Support", "enabled");
1428 : #endif
1429 : #if defined(HAVE_GD_XPM) && defined(HAVE_GD_BUNDLED)
1430 6 : php_info_print_table_row(2, "XPM Support", "enabled");
1431 : #endif
1432 : #ifdef HAVE_GD_XBM
1433 6 : php_info_print_table_row(2, "XBM Support", "enabled");
1434 : #endif
1435 : #if defined(USE_GD_JISX0208) && defined(HAVE_GD_BUNDLED)
1436 : php_info_print_table_row(2, "JIS-mapped Japanese Font Support", "enabled");
1437 : #endif
1438 6 : php_info_print_table_end();
1439 6 : }
1440 : /* }}} */
1441 :
1442 : /* {{{ proto array gd_info()
1443 : */
1444 : PHP_FUNCTION(gd_info)
1445 4 : {
1446 4 : if (ZEND_NUM_ARGS() != 0) {
1447 2 : ZEND_WRONG_PARAM_COUNT();
1448 : RETURN_FALSE;
1449 : }
1450 :
1451 2 : array_init(return_value);
1452 :
1453 2 : add_assoc_string(return_value, "GD Version", PHP_GD_VERSION_STRING, 1);
1454 :
1455 : #ifdef ENABLE_GD_TTF
1456 2 : add_assoc_bool(return_value, "FreeType Support", 1);
1457 : #if HAVE_LIBFREETYPE
1458 2 : add_assoc_string(return_value, "FreeType Linkage", "with freetype", 1);
1459 : #elif HAVE_LIBTTF
1460 : add_assoc_string(return_value, "FreeType Linkage", "with TTF library", 1);
1461 : #else
1462 : add_assoc_string(return_value, "FreeType Linkage", "with unknown library", 1);
1463 : #endif
1464 : #else
1465 : add_assoc_bool(return_value, "FreeType Support", 0);
1466 : #endif
1467 :
1468 : #ifdef HAVE_LIBT1
1469 : add_assoc_bool(return_value, "T1Lib Support", 1);
1470 : #else
1471 2 : add_assoc_bool(return_value, "T1Lib Support", 0);
1472 : #endif
1473 : #ifdef HAVE_GD_GIF_READ
1474 2 : add_assoc_bool(return_value, "GIF Read Support", 1);
1475 : #else
1476 : add_assoc_bool(return_value, "GIF Read Support", 0);
1477 : #endif
1478 : #ifdef HAVE_GD_GIF_CREATE
1479 2 : add_assoc_bool(return_value, "GIF Create Support", 1);
1480 : #else
1481 : add_assoc_bool(return_value, "GIF Create Support", 0);
1482 : #endif
1483 : #ifdef HAVE_GD_JPG
1484 2 : add_assoc_bool(return_value, "JPG Support", 1);
1485 : #else
1486 : add_assoc_bool(return_value, "JPG Support", 0);
1487 : #endif
1488 : #ifdef HAVE_GD_PNG
1489 2 : add_assoc_bool(return_value, "PNG Support", 1);
1490 : #else
1491 : add_assoc_bool(return_value, "PNG Support", 0);
1492 : #endif
1493 : #ifdef HAVE_GD_WBMP
1494 2 : add_assoc_bool(return_value, "WBMP Support", 1);
1495 : #else
1496 : add_assoc_bool(return_value, "WBMP Support", 0);
1497 : #endif
1498 : #if defined(HAVE_GD_XPM) && defined(HAVE_GD_BUNDLED)
1499 2 : add_assoc_bool(return_value, "XPM Support", 1);
1500 : #else
1501 : add_assoc_bool(return_value, "XPM Support", 0);
1502 : #endif
1503 : #ifdef HAVE_GD_XBM
1504 2 : add_assoc_bool(return_value, "XBM Support", 1);
1505 : #else
1506 : add_assoc_bool(return_value, "XBM Support", 0);
1507 : #endif
1508 : #if defined(USE_GD_JISX0208) && defined(HAVE_GD_BUNDLED)
1509 : add_assoc_bool(return_value, "JIS-mapped Japanese Font Support", 1);
1510 : #else
1511 2 : add_assoc_bool(return_value, "JIS-mapped Japanese Font Support", 0);
1512 : #endif
1513 : }
1514 : /* }}} */
1515 :
1516 : /* Need this for cpdf. See also comment in file.c php3i_get_le_fp() */
1517 : PHP_GD_API int phpi_get_le_gd(void)
1518 79 : {
1519 79 : return le_gd;
1520 : }
1521 : /* }}} */
1522 :
1523 : #ifndef HAVE_GDIMAGECOLORRESOLVE
1524 :
1525 : /* {{{ gdImageColorResolve
1526 : */
1527 : /********************************************************************/
1528 : /* gdImageColorResolve is a replacement for the old fragment: */
1529 : /* */
1530 : /* if ((color=gdImageColorExact(im,R,G,B)) < 0) */
1531 : /* if ((color=gdImageColorAllocate(im,R,G,B)) < 0) */
1532 : /* color=gdImageColorClosest(im,R,G,B); */
1533 : /* */
1534 : /* in a single function */
1535 :
1536 : int gdImageColorResolve(gdImagePtr im, int r, int g, int b)
1537 : {
1538 : int c;
1539 : int ct = -1;
1540 : int op = -1;
1541 : long rd, gd, bd, dist;
1542 : long mindist = 3*255*255; /* init to max poss dist */
1543 :
1544 : for (c = 0; c < im->colorsTotal; c++) {
1545 : if (im->open[c]) {
1546 : op = c; /* Save open slot */
1547 : continue; /* Color not in use */
1548 : }
1549 : rd = (long) (im->red [c] - r);
1550 : gd = (long) (im->green[c] - g);
1551 : bd = (long) (im->blue [c] - b);
1552 : dist = rd * rd + gd * gd + bd * bd;
1553 : if (dist < mindist) {
1554 : if (dist == 0) {
1555 : return c; /* Return exact match color */
1556 : }
1557 : mindist = dist;
1558 : ct = c;
1559 : }
1560 : }
1561 : /* no exact match. We now know closest, but first try to allocate exact */
1562 : if (op == -1) {
1563 : op = im->colorsTotal;
1564 : if (op == gdMaxColors) { /* No room for more colors */
1565 : return ct; /* Return closest available color */
1566 : }
1567 : im->colorsTotal++;
1568 : }
1569 : im->red [op] = r;
1570 : im->green[op] = g;
1571 : im->blue [op] = b;
1572 : im->open [op] = 0;
1573 : return op; /* Return newly allocated color */
1574 : }
1575 : /* }}} */
1576 :
1577 : #endif
1578 :
1579 : #define FLIPWORD(a) (((a & 0xff000000) >> 24) | ((a & 0x00ff0000) >> 8) | ((a & 0x0000ff00) << 8) | ((a & 0x000000ff) << 24))
1580 :
1581 : /* {{{ proto int imageloadfont(string filename)
1582 : Load a new font */
1583 : PHP_FUNCTION(imageloadfont)
1584 1 : {
1585 : zval **file;
1586 1 : int hdr_size = sizeof(gdFont) - sizeof(char *);
1587 1 : int ind, body_size, n = 0, b, i, body_size_check;
1588 : gdFontPtr font;
1589 : php_stream *stream;
1590 :
1591 1 : if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &file) == FAILURE) {
1592 0 : ZEND_WRONG_PARAM_COUNT();
1593 : }
1594 :
1595 1 : convert_to_string_ex(file);
1596 :
1597 1 : stream = php_stream_open_wrapper(Z_STRVAL_PP(file), "rb", ENFORCE_SAFE_MODE | IGNORE_PATH | IGNORE_URL_WIN | REPORT_ERRORS, NULL);
1598 1 : if (stream == NULL) {
1599 0 : RETURN_FALSE;
1600 : }
1601 :
1602 : /* Only supports a architecture-dependent binary dump format
1603 : * at the moment.
1604 : * The file format is like this on machines with 32-byte integers:
1605 : *
1606 : * byte 0-3: (int) number of characters in the font
1607 : * byte 4-7: (int) value of first character in the font (often 32, space)
1608 : * byte 8-11: (int) pixel width of each character
1609 : * byte 12-15: (int) pixel height of each character
1610 : * bytes 16-: (char) array with character data, one byte per pixel
1611 : * in each character, for a total of
1612 : * (nchars*width*height) bytes.
1613 : */
1614 1 : font = (gdFontPtr) emalloc(sizeof(gdFont));
1615 1 : b = 0;
1616 3 : while (b < hdr_size && (n = php_stream_read(stream, (char*)&font[b], hdr_size - b))) {
1617 1 : b += n;
1618 : }
1619 :
1620 1 : if (!n) {
1621 0 : efree(font);
1622 0 : if (php_stream_eof(stream)) {
1623 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "End of file while reading header");
1624 : } else {
1625 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error while reading header");
1626 : }
1627 0 : php_stream_close(stream);
1628 0 : RETURN_FALSE;
1629 : }
1630 1 : i = php_stream_tell(stream);
1631 1 : php_stream_seek(stream, 0, SEEK_END);
1632 1 : body_size_check = php_stream_tell(stream) - hdr_size;
1633 1 : php_stream_seek(stream, i, SEEK_SET);
1634 :
1635 1 : body_size = font->w * font->h * font->nchars;
1636 1 : if (body_size != body_size_check) {
1637 0 : font->w = FLIPWORD(font->w);
1638 0 : font->h = FLIPWORD(font->h);
1639 0 : font->nchars = FLIPWORD(font->nchars);
1640 0 : body_size = font->w * font->h * font->nchars;
1641 : }
1642 :
1643 1 : if (overflow2(font->nchars, font->h)) {
1644 1 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error reading font, invalid font header");
1645 1 : efree(font);
1646 1 : php_stream_close(stream);
1647 1 : RETURN_FALSE;
1648 : }
1649 0 : if (overflow2(font->nchars * font->h, font->w )) {
1650 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error reading font, invalid font header");
1651 0 : efree(font);
1652 0 : php_stream_close(stream);
1653 0 : RETURN_FALSE;
1654 : }
1655 :
1656 :
1657 :
1658 :
1659 0 : if (body_size != body_size_check) {
1660 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error reading font");
1661 0 : efree(font);
1662 0 : php_stream_close(stream);
1663 0 : RETURN_FALSE;
1664 : }
1665 :
1666 0 : font->data = emalloc(body_size);
1667 0 : b = 0;
1668 0 : while (b < body_size && (n = php_stream_read(stream, &font->data[b], body_size - b))) {
1669 0 : b += n;
1670 : }
1671 :
1672 0 : if (!n) {
1673 0 : efree(font->data);
1674 0 : efree(font);
1675 0 : if (php_stream_eof(stream)) {
1676 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "End of file while reading body");
1677 : } else {
1678 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error while reading body");
1679 : }
1680 0 : php_stream_close(stream);
1681 0 : RETURN_FALSE;
1682 : }
1683 0 : php_stream_close(stream);
1684 :
1685 : /* Adding 5 to the font index so we will never have font indices
1686 : * that overlap with the old fonts (with indices 1-5). The first
1687 : * list index given out is always 1.
1688 : */
1689 0 : ind = 5 + zend_list_insert(font, le_gd_font);
1690 :
1691 0 : RETURN_LONG(ind);
1692 : }
1693 : /* }}} */
1694 :
1695 : /* {{{ proto bool imagesetstyle(resource im, array styles)
1696 : Set the line drawing styles for use with imageline and IMG_COLOR_STYLED. */
1697 : PHP_FUNCTION(imagesetstyle)
1698 3 : {
1699 : zval **IM, **styles;
1700 : gdImagePtr im;
1701 : int * stylearr;
1702 : int index;
1703 : HashPosition pos;
1704 :
1705 3 : if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &IM, &styles) == FAILURE) {
1706 0 : ZEND_WRONG_PARAM_COUNT();
1707 : }
1708 :
1709 3 : ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
1710 :
1711 3 : convert_to_array_ex(styles);
1712 :
1713 : /* copy the style values in the stylearr */
1714 3 : stylearr = safe_emalloc(sizeof(int), zend_hash_num_elements(HASH_OF(*styles)), 0);
1715 :
1716 3 : zend_hash_internal_pointer_reset_ex(HASH_OF(*styles), &pos);
1717 :
1718 9 : for (index = 0;; zend_hash_move_forward_ex(HASH_OF(*styles), &pos)) {
1719 : zval ** item;
1720 :
1721 9 : if (zend_hash_get_current_data_ex(HASH_OF(*styles), (void **) &item, &pos) == FAILURE) {
1722 3 : break;
1723 : }
1724 :
1725 6 : convert_to_long_ex(item);
1726 :
1727 6 : stylearr[index++] = Z_LVAL_PP(item);
1728 6 : }
1729 :
1730 3 : gdImageSetStyle(im, stylearr, index);
1731 :
1732 3 : efree(stylearr);
1733 :
1734 3 : RETURN_TRUE;
1735 : }
1736 : /* }}} */
1737 :
1738 : #if HAVE_LIBGD20
1739 : /* {{{ proto resource imagecreatetruecolor(int x_size, int y_size)
1740 : Create a new true color image */
1741 : PHP_FUNCTION(imagecreatetruecolor)
1742 136 : {
1743 : zval **x_size, **y_size;
1744 : gdImagePtr im;
1745 :
1746 136 : if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &x_size, &y_size) == FAILURE) {
1747 3 : ZEND_WRONG_PARAM_COUNT();
1748 : }
1749 :
1750 133 : convert_to_long_ex(x_size);
1751 133 : convert_to_long_ex(y_size);
1752 :
1753 133 : if (Z_LVAL_PP(x_size) <= 0 || Z_LVAL_PP(y_size) <= 0 ||
1754 : Z_LVAL_PP(x_size) >= INT_MAX || Z_LVAL_PP(y_size) >= INT_MAX
1755 : ) {
1756 6 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid image dimensions");
1757 6 : RETURN_FALSE;
1758 : }
1759 :
1760 127 : im = gdImageCreateTrueColor(Z_LVAL_PP(x_size), Z_LVAL_PP(y_size));
1761 :
1762 127 : if (!im) {
1763 0 : RETURN_FALSE;
1764 : }
1765 :
1766 127 : ZEND_REGISTER_RESOURCE(return_value, im, le_gd);
1767 : }
1768 : /* }}} */
1769 :
1770 : /* {{{ proto bool imageistruecolor(resource im)
1771 : return true if the image uses truecolor */
1772 : PHP_FUNCTION(imageistruecolor)
1773 8668 : {
1774 : zval **IM;
1775 : gdImagePtr im;
1776 :
1777 8668 : if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &IM) == FAILURE) {
1778 0 : ZEND_WRONG_PARAM_COUNT();
1779 : }
1780 :
1781 8668 : ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
1782 :
1783 8665 : RETURN_BOOL(im->trueColor);
1784 : }
1785 : /* }}} */
1786 :
1787 : /* {{{ proto void imagetruecolortopalette(resource im, bool ditherFlag, int colorsWanted)
1788 : Convert a true colour image to a palette based image with a number of colours, optionally using dithering. */
1789 : PHP_FUNCTION(imagetruecolortopalette)
1790 13 : {
1791 : zval **IM, **dither, **ncolors;
1792 : gdImagePtr im;
1793 :
1794 13 : if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &IM, &dither, &ncolors) == FAILURE) {
1795 0 : ZEND_WRONG_PARAM_COUNT();
1796 : }
1797 :
1798 13 : ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
1799 :
1800 9 : convert_to_boolean_ex(dither);
1801 9 : convert_to_long_ex(ncolors);
1802 :
1803 9 : if (Z_LVAL_PP(ncolors) <= 0) {
1804 5 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Number of colors has to be greater than zero");
1805 5 : RETURN_FALSE;
1806 : }
1807 4 : gdImageTrueColorToPalette(im, Z_LVAL_PP(dither), Z_LVAL_PP(ncolors));
1808 :
1809 4 : RETURN_TRUE;
1810 : }
1811 : /* }}} */
1812 :
1813 : #if HAVE_GD_BUNDLED
1814 : /* {{{ proto bool imagecolormatch(resource im1, resource im2)
1815 : Makes the colors of the palette version of an image more closely match the true color version */
1816 : PHP_FUNCTION(imagecolormatch)
1817 6 : {
1818 : zval **IM1, **IM2;
1819 : gdImagePtr im1, im2;
1820 : int result;
1821 :
1822 6 : if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &IM1, &IM2 ) == FAILURE) {
1823 1 : ZEND_WRONG_PARAM_COUNT();
1824 : }
1825 :
1826 5 : ZEND_FETCH_RESOURCE(im1, gdImagePtr, IM1, -1, "Image", le_gd);
1827 5 : ZEND_FETCH_RESOURCE(im2, gdImagePtr, IM2, -1, "Image", le_gd);
1828 :
1829 5 : result = gdImageColorMatch(im1, im2);
1830 5 : switch (result) {
1831 : case -1:
1832 1 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Image1 must be TrueColor" );
1833 1 : RETURN_FALSE;
1834 : break;
1835 : case -2:
1836 1 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Image2 must be Palette" );
1837 1 : RETURN_FALSE;
1838 : break;
1839 : case -3:
1840 1 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Image1 and Image2 must be the same size" );
1841 1 : RETURN_FALSE;
1842 : break;
1843 : case -4:
1844 1 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Image2 must have at least one color" );
1845 1 : RETURN_FALSE;
1846 : break;
1847 : }
1848 :
1849 1 : RETURN_TRUE;
1850 : }
1851 : /* }}} */
1852 : #endif
1853 :
1854 : /* {{{ proto bool imagesetthickness(resource im, int thickness)
1855 : Set line thickness for drawing lines, ellipses, rectangles, polygons etc. */
1856 : PHP_FUNCTION(imagesetthickness)
1857 9 : {
1858 : zval **IM, **thick;
1859 : gdImagePtr im;
1860 :
1861 9 : if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &IM, &thick) == FAILURE) {
1862 0 : ZEND_WRONG_PARAM_COUNT();
1863 : }
1864 :
1865 9 : ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
1866 6 : convert_to_long_ex(thick);
1867 :
1868 6 : gdImageSetThickness(im, Z_LVAL_PP(thick));
1869 :
1870 6 : RETURN_TRUE;
1871 : }
1872 : /* }}} */
1873 :
1874 : /* {{{ proto bool imagefilledellipse(resource im, int cx, int cy, int w, int h, int color)
1875 : Draw an ellipse */
1876 : PHP_FUNCTION(imagefilledellipse)
1877 1 : {
1878 : zval **IM, **cx, **cy, **w, **h, **color;
1879 : gdImagePtr im;
1880 :
1881 1 : if (ZEND_NUM_ARGS() != 6 || zend_get_parameters_ex(6, &IM, &cx, &cy, &w, &h, &color) == FAILURE) {
1882 0 : ZEND_WRONG_PARAM_COUNT();
1883 : }
1884 :
1885 1 : ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
1886 :
1887 1 : convert_to_long_ex(cx);
1888 1 : convert_to_long_ex(cy);
1889 1 : convert_to_long_ex(w);
1890 1 : convert_to_long_ex(h);
1891 1 : convert_to_long_ex(color);
1892 :
1893 1 : gdImageFilledEllipse(im, Z_LVAL_PP(cx), Z_LVAL_PP(cy), Z_LVAL_PP(w), Z_LVAL_PP(h), Z_LVAL_PP(color));
1894 :
1895 1 : RETURN_TRUE;
1896 : }
1897 : /* }}} */
1898 :
1899 : /* {{{ proto bool imagefilledarc(resource im, int cx, int cy, int w, int h, int s, int e, int col, int style)
1900 : Draw a filled partial ellipse */
1901 : PHP_FUNCTION(imagefilledarc)
1902 12 : {
1903 : zval **IM, **cx, **cy, **w, **h, **ST, **E, **col, **style;
1904 : gdImagePtr im;
1905 : int e, st;
1906 :
1907 12 : if (ZEND_NUM_ARGS() != 9 || zend_get_parameters_ex(9, &IM, &cx, &cy, &w, &h, &ST, &E, &col, &style) == FAILURE) {
1908 1 : ZEND_WRONG_PARAM_COUNT();
1909 : }
1910 :
1911 11 : ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
1912 :
1913 11 : convert_to_long_ex(cx);
1914 11 : convert_to_long_ex(cy);
1915 11 : convert_to_long_ex(w);
1916 11 : convert_to_long_ex(h);
1917 11 : convert_to_long_ex(ST);
1918 11 : convert_to_long_ex(E);
1919 11 : convert_to_long_ex(col);
1920 11 : convert_to_long_ex(style);
1921 :
1922 11 : e = Z_LVAL_PP(E);
1923 11 : if (e < 0) {
1924 4 : e %= 360;
1925 : }
1926 :
1927 11 : st = Z_LVAL_PP(ST);
1928 11 : if (st < 0) {
1929 1 : st %= 360;
1930 : }
1931 :
1932 11 : gdImageFilledArc(im, Z_LVAL_PP(cx), Z_LVAL_PP(cy), Z_LVAL_PP(w), Z_LVAL_PP(h), st, e, Z_LVAL_PP(col), Z_LVAL_PP(style));
1933 :
1934 11 : RETURN_TRUE;
1935 : }
1936 : /* }}} */
1937 :
1938 : /* {{{ proto bool imagealphablending(resource im, bool on)
1939 : Turn alpha blending mode on or off for the given image */
1940 : PHP_FUNCTION(imagealphablending)
1941 6 : {
1942 : zval **IM, **blend;
1943 : gdImagePtr im;
1944 :
1945 6 : if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &IM, &blend) == FAILURE) {
1946 0 : ZEND_WRONG_PARAM_COUNT();
1947 : }
1948 :
1949 6 : ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
1950 6 : convert_to_boolean_ex(blend);
1951 :
1952 6 : gdImageAlphaBlending(im, Z_LVAL_PP(blend));
1953 :
1954 6 : RETURN_TRUE;
1955 : }
1956 : /* }}} */
1957 :
1958 : #if HAVE_LIBGD20
1959 : /* {{{ proto bool imagesavealpha(resource im, bool on)
1960 : Include alpha channel to a saved image */
1961 : PHP_FUNCTION(imagesavealpha)
1962 3 : {
1963 : zval **IM, **save;
1964 : gdImagePtr im;
1965 :
1966 3 : if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &IM, &save) == FAILURE) {
1967 0 : ZEND_WRONG_PARAM_COUNT();
1968 : }
1969 :
1970 3 : ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
1971 3 : convert_to_boolean_ex(save);
1972 :
1973 3 : gdImageSaveAlpha(im, Z_LVAL_PP(save));
1974 :
1975 3 : RETURN_TRUE;
1976 : }
1977 : /* }}} */
1978 : #endif
1979 :
1980 : #if HAVE_GD_BUNDLED
1981 : /* {{{ proto bool imagelayereffect(resource im, int effect)
1982 : Set the alpha blending flag to use the bundled libgd layering effects */
1983 : PHP_FUNCTION(imagelayereffect)
1984 3 : {
1985 : zval **IM, **effect;
1986 : gdImagePtr im;
1987 :
1988 3 : if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &IM, &effect) == FAILURE) {
1989 0 : ZEND_WRONG_PARAM_COUNT();
1990 : }
1991 :
1992 3 : ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
1993 1 : convert_to_long_ex(effect);
1994 :
1995 1 : gdImageAlphaBlending(im, Z_LVAL_PP(effect) );
1996 :
1997 1 : RETURN_TRUE;
1998 : }
1999 : /* }}} */
2000 : #endif
2001 :
2002 : /* {{{ proto int imagecolorallocatealpha(resource im, int red, int green, int blue, int alpha)
2003 : Allocate a color with an alpha level. Works for true color and palette based images */
2004 : PHP_FUNCTION(imagecolorallocatealpha)
2005 281 : {
2006 : zval *IM;
2007 : long red, green, blue, alpha;
2008 : gdImagePtr im;
2009 281 : int ct = (-1);
2010 :
2011 281 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zllll", &IM, &red, &green, &blue, &alpha) == FAILURE) {
2012 12 : RETURN_FALSE;
2013 : }
2014 :
2015 269 : ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
2016 :
2017 265 : ct = gdImageColorAllocateAlpha(im, red, green, blue, alpha);
2018 265 : if (ct < 0) {
2019 0 : RETURN_FALSE;
2020 : }
2021 :
2022 265 : RETURN_LONG((long)ct);
2023 : }
2024 : /* }}} */
2025 :
2026 : /* {{{ proto int imagecolorresolvealpha(resource im, int red, int green, int blue, int alpha)
2027 : Resolve/Allocate a colour with an alpha level. Works for true colour and palette based images */
2028 : PHP_FUNCTION(imagecolorresolvealpha)
2029 770 : {
2030 : zval **IM, ** red, **green, **blue, **alpha;
2031 : gdImagePtr im;
2032 :
2033 770 : if (ZEND_NUM_ARGS() != 5 || zend_get_parameters_ex(5, &IM, &red, &green, &blue, &alpha) == FAILURE) {
2034 0 : ZEND_WRONG_PARAM_COUNT();
2035 : }
2036 :
2037 770 : ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
2038 :
2039 770 : convert_to_long_ex(red);
2040 770 : convert_to_long_ex(green);
2041 770 : convert_to_long_ex(blue);
2042 770 : convert_to_long_ex(alpha);
2043 :
2044 770 : RETURN_LONG(gdImageColorResolveAlpha(im, Z_LVAL_PP(red), Z_LVAL_PP(green), Z_LVAL_PP(blue), Z_LVAL_PP(alpha)));
2045 : }
2046 : /* }}} */
2047 :
2048 : /* {{{ proto int imagecolorclosestalpha(resource im, int red, int green, int blue, int alpha)
2049 : Find the closest matching colour with alpha transparency */
2050 : PHP_FUNCTION(imagecolorclosestalpha)
2051 5 : {
2052 : zval **IM, ** red, **green, **blue, **alpha;
2053 : gdImagePtr im;
2054 :
2055 5 : if (ZEND_NUM_ARGS() != 5 || zend_get_parameters_ex(5, &IM, &red, &green, &blue, &alpha) == FAILURE) {
2056 0 : ZEND_WRONG_PARAM_COUNT();
2057 : }
2058 :
2059 5 : ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
2060 :
2061 5 : convert_to_long_ex(red);
2062 5 : convert_to_long_ex(green);
2063 5 : convert_to_long_ex(blue);
2064 5 : convert_to_long_ex(alpha);
2065 :
2066 5 : RETURN_LONG(gdImageColorClosestAlpha(im, Z_LVAL_PP(red), Z_LVAL_PP(green), Z_LVAL_PP(blue), Z_LVAL_PP(alpha)));
2067 : }
2068 : /* }}} */
2069 :
2070 : /* {{{ proto int imagecolorexactalpha(resource im, int red, int green, int blue, int alpha)
2071 : Find exact match for colour with transparency */
2072 : PHP_FUNCTION(imagecolorexactalpha)
2073 2 : {
2074 : zval **IM, **red, **green, **blue, **alpha;
2075 : gdImagePtr im;
2076 :
2077 2 : if (ZEND_NUM_ARGS() != 5 || zend_get_parameters_ex(5, &IM, &red, &green, &blue, &alpha) == FAILURE) {
2078 0 : ZEND_WRONG_PARAM_COUNT();
2079 : }
2080 :
2081 2 : ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
2082 :
2083 2 : convert_to_long_ex(red);
2084 2 : convert_to_long_ex(green);
2085 2 : convert_to_long_ex(blue);
2086 2 : convert_to_long_ex(alpha);
2087 :
2088 2 : RETURN_LONG(gdImageColorExactAlpha(im, Z_LVAL_PP(red), Z_LVAL_PP(green), Z_LVAL_PP(blue), Z_LVAL_PP(alpha)));
2089 : }
2090 : /* }}} */
2091 :
2092 : /* {{{ proto bool imagecopyresampled(resource dst_im, resource src_im, int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h)
2093 : Copy and resize part of an image using resampling to help ensure clarity */
2094 : PHP_FUNCTION(imagecopyresampled)
2095 1 : {
2096 : zval **SIM, **DIM, **SX, **SY, **SW, **SH, **DX, **DY, **DW, **DH;
2097 : gdImagePtr im_dst, im_src;
2098 : int srcH, srcW, dstH, dstW, srcY, srcX, dstY, dstX;
2099 :
2100 1 : if (ZEND_NUM_ARGS() != 10 || zend_get_parameters_ex(10, &DIM, &SIM, &DX, &DY, &SX, &SY, &DW, &DH, &SW, &SH) == FAILURE) {
2101 0 : ZEND_WRONG_PARAM_COUNT();
2102 : }
2103 :
2104 1 : ZEND_FETCH_RESOURCE(im_dst, gdImagePtr, DIM, -1, "Image", le_gd);
2105 1 : ZEND_FETCH_RESOURCE(im_src, gdImagePtr, SIM, -1, "Image", le_gd);
2106 :
2107 1 : convert_to_long_ex(SX);
2108 1 : convert_to_long_ex(SY);
2109 1 : convert_to_long_ex(SW);
2110 1 : convert_to_long_ex(SH);
2111 1 : convert_to_long_ex(DX);
2112 1 : convert_to_long_ex(DY);
2113 1 : convert_to_long_ex(DW);
2114 1 : convert_to_long_ex(DH);
2115 :
2116 1 : srcX = Z_LVAL_PP(SX);
2117 1 : srcY = Z_LVAL_PP(SY);
2118 1 : srcH = Z_LVAL_PP(SH);
2119 1 : srcW = Z_LVAL_PP(SW);
2120 1 : dstX = Z_LVAL_PP(DX);
2121 1 : dstY = Z_LVAL_PP(DY);
2122 1 : dstH = Z_LVAL_PP(DH);
2123 1 : dstW = Z_LVAL_PP(DW);
2124 :
2125 1 : gdImageCopyResampled(im_dst, im_src, dstX, dstY, srcX, srcY, dstW, dstH, srcW, srcH);
2126 :
2127 1 : RETURN_TRUE;
2128 : }
2129 : /* }}} */
2130 : #endif
2131 :
2132 : #ifdef PHP_WIN32
2133 : /* {{{ proto resource imagegrabwindow(int window_handle [, int client_area])
2134 : Grab a window or its client area using a windows handle (HWND property in COM instance) */
2135 : PHP_FUNCTION(imagegrabwindow)
2136 : {
2137 : HWND window;
2138 : long client_area = 0;
2139 : RECT rc = {0};
2140 : RECT rc_win = {0};
2141 : int Width, Height;
2142 : HDC hdc;
2143 : HDC memDC;
2144 : HBITMAP memBM;
2145 : HBITMAP hOld;
2146 : HINSTANCE handle;
2147 : long lwindow_handle;
2148 : typedef BOOL (WINAPI *tPrintWindow)(HWND, HDC,UINT);
2149 : tPrintWindow pPrintWindow = 0;
2150 : gdImagePtr im;
2151 :
2152 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l", &lwindow_handle, &client_area) == FAILURE) {
2153 : RETURN_FALSE;
2154 : }
2155 :
2156 : window = (HWND) lwindow_handle;
2157 :
2158 : if (!IsWindow(window)) {
2159 : php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Invalid window handle");
2160 : RETURN_FALSE;
2161 : }
2162 :
2163 : hdc = GetDC(0);
2164 :
2165 : if (client_area) {
2166 : GetClientRect(window, &rc);
2167 : Width = rc.right;
2168 : Height = rc.bottom;
2169 : } else {
2170 : GetWindowRect(window, &rc);
2171 : Width = rc.right - rc.left;
2172 : Height = rc.bottom - rc.top;
2173 : }
2174 :
2175 : Width = (Width/4)*4;
2176 :
2177 : memDC = CreateCompatibleDC(hdc);
2178 : memBM = CreateCompatibleBitmap(hdc, Width, Height);
2179 : hOld = (HBITMAP) SelectObject (memDC, memBM);
2180 :
2181 :
2182 : handle = LoadLibrary("User32.dll");
2183 : if ( handle == 0 ) {
2184 : goto clean;
2185 : }
2186 : pPrintWindow = (tPrintWindow) GetProcAddress(handle, "PrintWindow");
2187 :
2188 : if ( pPrintWindow ) {
2189 : pPrintWindow(window, memDC, (UINT) client_area);
2190 : } else {
2191 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Windows API too old");
2192 : goto clean;
2193 : }
2194 :
2195 : FreeLibrary(handle);
2196 :
2197 : im = gdImageCreateTrueColor(Width, Height);
2198 : if (im) {
2199 : int x,y;
2200 : for (y=0; y <= Height; y++) {
2201 : for (x=0; x <= Width; x++) {
2202 : int c = GetPixel(memDC, x,y);
2203 : gdImageSetPixel(im, x, y, gdTrueColor(GetRValue(c), GetGValue(c), GetBValue(c)));
2204 : }
2205 : }
2206 : }
2207 :
2208 : clean:
2209 : SelectObject(memDC,hOld);
2210 : DeleteObject(memBM);
2211 : DeleteDC(memDC);
2212 : ReleaseDC( 0, hdc );
2213 :
2214 : if (!im) {
2215 : RETURN_FALSE;
2216 : } else {
2217 : ZEND_REGISTER_RESOURCE(return_value, im, le_gd);
2218 : }
2219 : }
2220 : /* }}} */
2221 :
2222 : /* {{{ proto resource imagegrabscreen()
2223 : Grab a screenshot */
2224 : PHP_FUNCTION(imagegrabscreen)
2225 : {
2226 : HWND window = GetDesktopWindow();
2227 : RECT rc = {0};
2228 : int Width, Height;
2229 : HDC hdc;
2230 : HDC memDC;
2231 : HBITMAP memBM;
2232 : HBITMAP hOld;
2233 : HINSTANCE handle;
2234 : long lwindow_handle;
2235 : typedef BOOL (WINAPI *tPrintWindow)(HWND, HDC,UINT);
2236 : tPrintWindow pPrintWindow = 0;
2237 : gdImagePtr im;
2238 : hdc = GetDC(0);
2239 :
2240 : if (!hdc) {
2241 : RETURN_FALSE;
2242 : }
2243 :
2244 : GetWindowRect(window, &rc);
2245 : Width = rc.right - rc.left;
2246 : Height = rc.bottom - rc.top;
2247 :
2248 : Width = (Width/4)*4;
2249 :
2250 : memDC = CreateCompatibleDC(hdc);
2251 : memBM = CreateCompatibleBitmap(hdc, Width, Height);
2252 : hOld = (HBITMAP) SelectObject (memDC, memBM);
2253 : BitBlt( memDC, 0, 0, Width, Height , hdc, rc.left, rc.top , SRCCOPY );
2254 :
2255 : im = gdImageCreateTrueColor(Width, Height);
2256 : if (im) {
2257 : int x,y;
2258 : for (y=0; y <= Height; y++) {
2259 : for (x=0; x <= Width; x++) {
2260 : int c = GetPixel(memDC, x,y);
2261 : gdImageSetPixel(im, x, y, gdTrueColor(GetRValue(c), GetGValue(c), GetBValue(c)));
2262 : }
2263 : }
2264 : }
2265 :
2266 : SelectObject(memDC,hOld);
2267 : DeleteObject(memBM);
2268 : DeleteDC(memDC);
2269 : ReleaseDC( 0, hdc );
2270 :
2271 : if (!im) {
2272 : RETURN_FALSE;
2273 : } else {
2274 : ZEND_REGISTER_RESOURCE(return_value, im, le_gd);
2275 : }
2276 : }
2277 : /* }}} */
2278 : #endif /* PHP_WIN32 */
2279 :
2280 : #ifdef HAVE_GD_BUNDLED
2281 : /* {{{ proto resource imagerotate(resource src_im, float angle, int bgdcolor [, int ignoretransparent])
2282 : Rotate an image using a custom angle */
2283 : PHP_FUNCTION(imagerotate)
2284 3 : {
2285 : zval *SIM;
2286 : gdImagePtr im_dst, im_src;
2287 : double degrees;
2288 : long color;
2289 3 : long ignoretransparent = 0;
2290 :
2291 3 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rdl|l", &SIM, °rees, &color, &ignoretransparent) == FAILURE) {
2292 0 : RETURN_FALSE;
2293 : }
2294 :
2295 3 : ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
2296 :
2297 3 : im_dst = gdImageRotate(im_src, degrees, color, ignoretransparent);
2298 :
2299 3 : if (im_dst != NULL) {
2300 2 : ZEND_REGISTER_RESOURCE(return_value, im_dst, le_gd);
2301 : } else {
2302 1 : RETURN_FALSE;
2303 : }
2304 : }
2305 : /* }}} */
2306 : #endif
2307 :
2308 : #if HAVE_GD_IMAGESETTILE
2309 : /* {{{ proto bool imagesettile(resource image, resource tile)
2310 : Set the tile image to $tile when filling $image with the "IMG_COLOR_TILED" color */
2311 : PHP_FUNCTION(imagesettile)
2312 2 : {
2313 : zval **IM, **TILE;
2314 : gdImagePtr im, tile;
2315 :
2316 2 : if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &IM, &TILE) == FAILURE) {
2317 0 : ZEND_WRONG_PARAM_COUNT();
2318 : }
2319 :
2320 2 : ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
2321 2 : ZEND_FETCH_RESOURCE(tile, gdImagePtr, TILE, -1, "Image", le_gd);
2322 :
2323 2 : gdImageSetTile(im, tile);
2324 :
2325 2 : RETURN_TRUE;
2326 : }
2327 : /* }}} */
2328 : #endif
2329 :
2330 : #if HAVE_GD_IMAGESETBRUSH
2331 : /* {{{ proto bool imagesetbrush(resource image, resource brush)
2332 : Set the brush image to $brush when filling $image with the "IMG_COLOR_BRUSHED" color */
2333 : PHP_FUNCTION(imagesetbrush)
2334 1 : {
2335 : zval **IM, **TILE;
2336 : gdImagePtr im, tile;
2337 :
2338 1 : if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &IM, &TILE) == FAILURE) {
2339 0 : ZEND_WRONG_PARAM_COUNT();
2340 : }
2341 :
2342 1 : ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
2343 1 : ZEND_FETCH_RESOURCE(tile, gdImagePtr, TILE, -1, "Image", le_gd);
2344 :
2345 1 : gdImageSetBrush(im, tile);
2346 :
2347 1 : RETURN_TRUE;
2348 : }
2349 : /* }}} */
2350 : #endif
2351 :
2352 : /* {{{ proto resource imagecreate(int x_size, int y_size)
2353 : Create a new image */
2354 : PHP_FUNCTION(imagecreate)
2355 63 : {
2356 : zval **x_size, **y_size;
2357 : gdImagePtr im;
2358 :
2359 63 : if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &x_size, &y_size) == FAILURE) {
2360 0 : ZEND_WRONG_PARAM_COUNT();
2361 : }
2362 :
2363 63 : convert_to_long_ex(x_size);
2364 63 : convert_to_long_ex(y_size);
2365 :
2366 63 : if (Z_LVAL_PP(x_size) <= 0 || Z_LVAL_PP(y_size) <= 0 ||
2367 : Z_LVAL_PP(x_size) >= INT_MAX || Z_LVAL_PP(y_size) >= INT_MAX
2368 : ) {
2369 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid image dimensions");
2370 0 : RETURN_FALSE;
2371 : }
2372 :
2373 63 : im = gdImageCreate(Z_LVAL_PP(x_size), Z_LVAL_PP(y_size));
2374 :
2375 63 : if (!im) {
2376 0 : RETURN_FALSE;
2377 : }
2378 :
2379 63 : ZEND_REGISTER_RESOURCE(return_value, im, le_gd);
2380 : }
2381 : /* }}} */
2382 :
2383 : /* {{{ proto int imagetypes(void)
2384 : Return the types of images supported in a bitfield - 1=GIF, 2=JPEG, 4=PNG, 8=WBMP, 16=XPM */
2385 : PHP_FUNCTION(imagetypes)
2386 1 : {
2387 1 : int ret=0;
2388 : #ifdef HAVE_GD_GIF_CREATE
2389 1 : ret = 1;
2390 : #endif
2391 : #ifdef HAVE_GD_JPG
2392 1 : ret |= 2;
2393 : #endif
2394 : #ifdef HAVE_GD_PNG
2395 1 : ret |= 4;
2396 : #endif
2397 : #ifdef HAVE_GD_WBMP
2398 1 : ret |= 8;
2399 : #endif
2400 : #if defined(HAVE_GD_XPM) && defined(HAVE_GD_BUNDLED)
2401 1 : ret |= 16;
2402 : #endif
2403 :
2404 1 : if (ZEND_NUM_ARGS() != 0) {
2405 0 : WRONG_PARAM_COUNT;
2406 : }
2407 :
2408 1 : RETURN_LONG(ret);
2409 : }
2410 : /* }}} */
2411 :
2412 : /* {{{ _php_image_type
2413 : */
2414 : static const char php_sig_gd2[3] = {'g', 'd', '2'};
2415 :
2416 : static int _php_image_type (char data[8])
2417 6 : {
2418 : #ifdef HAVE_LIBGD15
2419 : /* Based on ext/standard/image.c */
2420 :
2421 6 : if (data == NULL) {
2422 0 : return -1;
2423 : }
2424 :
2425 6 : if (!memcmp(data, php_sig_gd2, 3)) {
2426 3 : return PHP_GDIMG_TYPE_GD2;
2427 3 : } else if (!memcmp(data, php_sig_jpg, 3)) {
2428 0 : return PHP_GDIMG_TYPE_JPG;
2429 3 : } else if (!memcmp(data, php_sig_png, 3)) {
2430 2 : if (!memcmp(data, php_sig_png, 8)) {
2431 2 : return PHP_GDIMG_TYPE_PNG;
2432 : }
2433 1 : } else if (!memcmp(data, php_sig_gif, 3)) {
2434 0 : return PHP_GDIMG_TYPE_GIF;
2435 : }
2436 : #ifdef HAVE_GD_WBMP
2437 : else {
2438 : gdIOCtx *io_ctx;
2439 1 : io_ctx = gdNewDynamicCtxEx(8, data, 0);
2440 1 : if (io_ctx) {
2441 1 : if (getmbi((int(*)(void *)) gdGetC, io_ctx) == 0 && skipheader((int(*)(void *)) gdGetC, io_ctx) == 0 ) {
2442 : #if HAVE_LIBGD204
2443 0 : io_ctx->gd_free(io_ctx);
2444 : #else
2445 : io_ctx->free(io_ctx);
2446 : #endif
2447 0 : return PHP_GDIMG_TYPE_WBM;
2448 : } else {
2449 : #if HAVE_LIBGD204
2450 1 : io_ctx->gd_free(io_ctx);
2451 : #else
2452 : io_ctx->free(io_ctx);
2453 : #endif
2454 : }
2455 : }
2456 : }
2457 : #endif
2458 1 : return -1;
2459 : #endif
2460 : }
2461 : /* }}} */
2462 :
2463 : #ifdef HAVE_LIBGD15
2464 : /* {{{ _php_image_create_from_string
2465 : */
2466 : gdImagePtr _php_image_create_from_string(zval **data, char *tn, gdImagePtr (*ioctx_func_p)() TSRMLS_DC)
2467 5 : {
2468 : gdImagePtr im;
2469 : gdIOCtx *io_ctx;
2470 :
2471 5 : io_ctx = gdNewDynamicCtxEx(Z_STRLEN_PP(data), Z_STRVAL_PP(data), 0);
2472 :
2473 5 : if (!io_ctx) {
2474 0 : return NULL;
2475 : }
2476 :
2477 5 : im = (*ioctx_func_p)(io_ctx);
2478 5 : if (!im) {
2479 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Passed data is not in '%s' format", tn);
2480 : #if HAVE_LIBGD204
2481 0 : io_ctx->gd_free(io_ctx);
2482 : #else
2483 : io_ctx->free(io_ctx);
2484 : #endif
2485 0 : return NULL;
2486 : }
2487 :
2488 : #if HAVE_LIBGD204
2489 5 : io_ctx->gd_free(io_ctx);
2490 : #else
2491 : io_ctx->free(io_ctx);
2492 : #endif
2493 :
2494 5 : return im;
2495 : }
2496 : /* }}} */
2497 :
2498 : /* {{{ proto resource imagecreatefromstring(string image)
2499 : Create a new image from the image stream in the string */
2500 : PHP_FUNCTION(imagecreatefromstring)
2501 7 : {
2502 : zval **data;
2503 : gdImagePtr im;
2504 : int imtype;
2505 : char sig[8];
2506 :
2507 7 : if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &data) == FAILURE) {
2508 0 : ZEND_WRONG_PARAM_COUNT();
2509 : }
2510 :
2511 7 : convert_to_string_ex(data);
2512 7 : if (Z_STRLEN_PP(data) < 8) {
2513 1 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty string or invalid image");
2514 1 : RETURN_FALSE;
2515 : }
2516 :
2517 6 : memcpy(sig, Z_STRVAL_PP(data), 8);
2518 :
2519 6 : imtype = _php_image_type(sig);
2520 :
2521 6 : switch (imtype) {
2522 : case PHP_GDIMG_TYPE_JPG:
2523 : #ifdef HAVE_GD_JPG
2524 0 : im = _php_image_create_from_string(data, "JPEG", gdImageCreateFromJpegCtx TSRMLS_CC);
2525 : #else
2526 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "No JPEG support in this PHP build");
2527 : RETURN_FALSE;
2528 : #endif
2529 0 : break;
2530 :
2531 : case PHP_GDIMG_TYPE_PNG:
2532 : #ifdef HAVE_GD_PNG
2533 2 : im = _php_image_create_from_string(data, "PNG", gdImageCreateFromPngCtx TSRMLS_CC);
2534 : #else
2535 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "No PNG support in this PHP build");
2536 : RETURN_FALSE;
2537 : #endif
2538 2 : break;
2539 :
2540 : case PHP_GDIMG_TYPE_GIF:
2541 : #ifdef HAVE_GD_GIF_READ
2542 0 : im = _php_image_create_from_string(data, "GIF", gdImageCreateFromGifCtx TSRMLS_CC);
2543 : #else
2544 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "No GIF support in this PHP build");
2545 : RETURN_FALSE;
2546 : #endif
2547 0 : break;
2548 :
2549 : case PHP_GDIMG_TYPE_WBM:
2550 : #ifdef HAVE_GD_WBMP
2551 0 : im = _php_image_create_from_string(data, "WBMP", gdImageCreateFromWBMPCtx TSRMLS_CC);
2552 : #else
2553 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "No WBMP support in this PHP build");
2554 : RETURN_FALSE;
2555 : #endif
2556 0 : break;
2557 :
2558 : case PHP_GDIMG_TYPE_GD2:
2559 : #ifdef HAVE_GD_GD2
2560 3 : im = _php_image_create_from_string(data, "GD2", gdImageCreateFromGd2Ctx TSRMLS_CC);
2561 : #else
2562 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "No GD2 support in this PHP build");
2563 : RETURN_FALSE;
2564 : #endif
2565 3 : break;
2566 :
2567 : default:
2568 1 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Data is not in a recognized format");
2569 1 : RETURN_FALSE;
2570 : }
2571 :
2572 5 : if (!im) {
2573 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't create GD Image Stream out of Data");
2574 0 : RETURN_FALSE;
2575 : }
2576 :
2577 5 : ZEND_REGISTER_RESOURCE(return_value, im, le_gd);
2578 : }
2579 : /* }}} */
2580 : #endif
2581 :
2582 : /* {{{ _php_image_create_from
2583 : */
2584 : static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, gdImagePtr (*func_p)(), gdImagePtr (*ioctx_func_p)())
2585 65 : {
2586 : zval **file, **srcx, **srcy, **width, **height;
2587 65 : gdImagePtr im = NULL;
2588 65 : char *fn=NULL;
2589 : php_stream *stream;
2590 65 : FILE * fp = NULL;
2591 65 : int argc=ZEND_NUM_ARGS();
2592 : #ifdef HAVE_GD_JPG
2593 : long ignore_warning;
2594 : #endif
2595 :
2596 65 : if ((image_type == PHP_GDIMG_TYPE_GD2PART && argc != 5) ||
2597 : (image_type != PHP_GDIMG_TYPE_GD2PART && argc != 1) ||
2598 : zend_get_parameters_ex(argc, &file, &srcx, &srcy, &width, &height) == FAILURE) {
2599 0 : ZEND_WRONG_PARAM_COUNT();
2600 : }
2601 :
2602 65 : convert_to_string_ex(file);
2603 :
2604 65 : if (argc == 5 && image_type == PHP_GDIMG_TYPE_GD2PART) {
2605 3 : multi_convert_to_long_ex(4, srcx, srcy, width, height);
2606 3 : if (Z_LVAL_PP(width) < 1 || Z_LVAL_PP(height) < 1) {
2607 2 : php_error_docref(NULL TSRMLS_CC, E_WARNING,"Zero width or height not allowed");
2608 2 : RETURN_FALSE;
2609 : }
2610 : }
2611 :
2612 63 : fn = Z_STRVAL_PP(file);
2613 :
2614 63 : stream = php_stream_open_wrapper(fn, "rb", ENFORCE_SAFE_MODE|REPORT_ERRORS|IGNORE_PATH|IGNORE_URL_WIN, NULL);
2615 63 : if (stream == NULL) {
2616 1 : RETURN_FALSE;
2617 : }
2618 :
2619 : #ifndef USE_GD_IOCTX
2620 : ioctx_func_p = NULL; /* don't allow sockets without IOCtx */
2621 : #endif
2622 :
2623 : /* try and avoid allocating a FILE* if the stream is not naturally a FILE* */
2624 62 : if (php_stream_is(stream, PHP_STREAM_IS_STDIO)) {
2625 62 : if (FAILURE == php_stream_cast(stream, PHP_STREAM_AS_STDIO, (void**)&fp, REPORT_ERRORS)) {
2626 0 : goto out_err;
2627 : }
2628 0 : } else if (ioctx_func_p) {
2629 : #ifdef USE_GD_IOCTX
2630 : /* we can create an io context */
2631 : gdIOCtx* io_ctx;
2632 : size_t buff_size;
2633 : char *buff;
2634 :
2635 : /* needs to be malloc (persistent) - GD will free() it later */
2636 0 : buff_size = php_stream_copy_to_mem(stream, &buff, PHP_STREAM_COPY_ALL, 1);
2637 :
2638 0 : if (!buff_size) {
2639 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING,"Cannot read image data");
2640 0 : goto out_err;
2641 : }
2642 :
2643 0 : io_ctx = gdNewDynamicCtxEx(buff_size, buff, 0);
2644 0 : if (!io_ctx) {
2645 0 : pefree(buff, 1);
2646 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING,"Cannot allocate GD IO context");
2647 0 : goto out_err;
2648 : }
2649 :
2650 0 : if (image_type == PHP_GDIMG_TYPE_GD2PART) {
2651 0 : im = (*ioctx_func_p)(io_ctx, Z_LVAL_PP(srcx), Z_LVAL_PP(srcy), Z_LVAL_PP(width), Z_LVAL_PP(height));
2652 : } else {
2653 0 : im = (*ioctx_func_p)(io_ctx);
2654 : }
2655 : #if HAVE_LIBGD204
2656 0 : io_ctx->gd_free(io_ctx);
2657 : #else
2658 : io_ctx->free(io_ctx);
2659 : #endif
2660 0 : pefree(buff, 1);
2661 : #endif
2662 : }
2663 : else {
2664 : /* try and force the stream to be FILE* */
2665 0 : if (FAILURE == php_stream_cast(stream, PHP_STREAM_AS_STDIO | PHP_STREAM_CAST_TRY_HARD, (void **) &fp, REPORT_ERRORS)) {
2666 0 : goto out_err;
2667 : }
2668 : }
2669 :
2670 62 : if (!im && fp) {
2671 62 : switch (image_type) {
2672 : case PHP_GDIMG_TYPE_GD2PART:
2673 1 : im = (*func_p)(fp, Z_LVAL_PP(srcx), Z_LVAL_PP(srcy), Z_LVAL_PP(width), Z_LVAL_PP(height));
2674 1 : break;
2675 : #if defined(HAVE_GD_XPM) && defined(HAVE_GD_BUNDLED)
2676 : case PHP_GDIMG_TYPE_XPM:
2677 4 : im = gdImageCreateFromXpm(fn);
2678 4 : break;
2679 : #endif
2680 :
2681 : #ifdef HAVE_GD_JPG
2682 : case PHP_GDIMG_TYPE_JPG:
2683 5 : ignore_warning = INI_INT("gd.jpeg_ignore_warning");
2684 : #ifdef HAVE_GD_BUNDLED
2685 5 : im = gdImageCreateFromJpeg(fp, ignore_warning);
2686 : #else
2687 : im = gdImageCreateFromJpeg(fp);
2688 : #endif
2689 5 : break;
2690 : #endif
2691 :
2692 : default:
2693 52 : im = (*func_p)(fp);
2694 : break;
2695 : }
2696 :
2697 62 : fflush(fp);
2698 : }
2699 :
2700 62 : if (im) {
2701 52 : ZEND_REGISTER_RESOURCE(return_value, im, le_gd);
2702 52 : php_stream_close(stream);
2703 52 : return;
2704 : }
2705 :
2706 10 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "'%s' is not a valid %s file", fn, tn);
2707 10 : out_err:
2708 10 : php_stream_close(stream);
2709 10 : RETURN_FALSE;
2710 :
2711 : }
2712 : /* }}} */
2713 :
2714 : #ifdef HAVE_GD_GIF_READ
2715 : /* {{{ proto resource imagecreatefromgif(string filename)
2716 : Create a new image from GIF file or URL */
2717 : PHP_FUNCTION(imagecreatefromgif)
2718 18 : {
2719 18 : _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_GIF, "GIF", gdImageCreateFromGif, gdImageCreateFromGifCtx);
2720 18 : }
2721 : /* }}} */
2722 : #endif /* HAVE_GD_GIF_READ */
2723 :
2724 : #ifdef HAVE_GD_JPG
2725 : /* {{{ proto resource imagecreatefromjpeg(string filename)
2726 : Create a new image from JPEG file or URL */
2727 : PHP_FUNCTION(imagecreatefromjpeg)
2728 5 : {
2729 5 : _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_JPG, "JPEG", gdImageCreateFromJpeg, gdImageCreateFromJpegCtx);
2730 5 : }
2731 : /* }}} */
2732 : #endif /* HAVE_GD_JPG */
2733 :
2734 : #ifdef HAVE_GD_PNG
2735 : /* {{{ proto resource imagecreatefrompng(string filename)
2736 : Create a new image from PNG file or URL */
2737 : PHP_FUNCTION(imagecreatefrompng)
2738 23 : {
2739 23 : _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_PNG, "PNG", gdImageCreateFromPng, gdImageCreateFromPngCtx);
2740 23 : }
2741 : /* }}} */
2742 : #endif /* HAVE_GD_PNG */
2743 :
2744 : #ifdef HAVE_GD_XBM
2745 : /* {{{ proto resource imagecreatefromxbm(string filename)
2746 : Create a new image from XBM file or URL */
2747 : PHP_FUNCTION(imagecreatefromxbm)
2748 2 : {
2749 2 : _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_XBM, "XBM", gdImageCreateFromXbm, NULL);
2750 2 : }
2751 : /* }}} */
2752 : #endif /* HAVE_GD_XBM */
2753 :
2754 : #if defined(HAVE_GD_XPM) && defined(HAVE_GD_BUNDLED)
2755 : /* {{{ proto resource imagecreatefromxpm(string filename)
2756 : Create a new image from XPM file or URL */
2757 : PHP_FUNCTION(imagecreatefromxpm)
2758 4 : {
2759 4 : _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_XPM, "XPM", gdImageCreateFromXpm, NULL);
2760 4 : }
2761 : /* }}} */
2762 : #endif
2763 :
2764 : #ifdef HAVE_GD_WBMP
2765 : /* {{{ proto resource imagecreatefromwbmp(string filename)
2766 : Create a new image from WBMP file or URL */
2767 : PHP_FUNCTION(imagecreatefromwbmp)
2768 3 : {
2769 3 : _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_WBM, "WBMP", gdImageCreateFromWBMP, gdImageCreateFromWBMPCtx);
2770 3 : }
2771 : /* }}} */
2772 : #endif /* HAVE_GD_WBMP */
2773 :
2774 : /* {{{ proto resource imagecreatefromgd(string filename)
2775 : Create a new image from GD file or URL */
2776 : PHP_FUNCTION(imagecreatefromgd)
2777 4 : {
2778 4 : _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_GD, "GD", gdImageCreateFromGd, gdImageCreateFromGdCtx);
2779 4 : }
2780 : /* }}} */
2781 :
2782 : #ifdef HAVE_GD_GD2
2783 : /* {{{ proto resource imagecreatefromgd2(string filename)
2784 : Create a new image from GD2 file or URL */
2785 : PHP_FUNCTION(imagecreatefromgd2)
2786 3 : {
2787 3 : _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_GD2, "GD2", gdImageCreateFromGd2, gdImageCreateFromGd2Ctx);
2788 3 : }
2789 : /* }}} */
2790 :
2791 : /* {{{ proto resource imagecreatefromgd2part(string filename, int srcX, int srcY, int width, int height)
2792 : Create a new image from a given part of GD2 file or URL */
2793 : PHP_FUNCTION(imagecreatefromgd2part)
2794 3 : {
2795 3 : _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_GD2PART, "GD2", gdImageCreateFromGd2Part, gdImageCreateFromGd2PartCtx);
2796 3 : }
2797 : /* }}} */
2798 : #endif /* HAVE_GD_GD2 */
2799 :
2800 : /* {{{ _php_image_output
2801 : */
2802 : static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, void (*func_p)())
2803 11 : {
2804 : zval **imgind, **file, **quality, **type;
2805 : gdImagePtr im;
2806 11 : char *fn = NULL;
2807 : FILE *fp;
2808 11 : int argc = ZEND_NUM_ARGS();
2809 11 : int q = -1, i, t = 1;
2810 :
2811 : /* The quality parameter for Wbmp stands for the threshold when called from image2wbmp() */
2812 : /* When called from imagewbmp() the quality parameter stands for the foreground color. Default: black. */
2813 : /* The quality parameter for gd2 stands for chunk size */
2814 :
2815 11 : if (argc < 1 || argc > 4 || zend_get_parameters_ex(argc, &imgind, &file, &quality, &type) == FAILURE) {
2816 0 : ZEND_WRONG_PARAM_COUNT();
2817 : }
2818 :
2819 11 : ZEND_FETCH_RESOURCE(im, gdImagePtr, imgind, -1, "Image", le_gd);
2820 :
2821 11 : if (argc > 1) {
2822 10 : convert_to_string_ex(file);
2823 10 : fn = Z_STRVAL_PP(file);
2824 10 : if (argc == 3) {
2825 0 : convert_to_long_ex(quality);
2826 0 : q = Z_LVAL_PP(quality);
2827 : }
2828 10 : if (argc == 4) {
2829 0 : convert_to_long_ex(type);
2830 0 : t = Z_LVAL_PP(type);
2831 : }
2832 : }
2833 :
2834 21 : if (argc >= 2 && Z_STRLEN_PP(file)) {
2835 10 : PHP_GD_CHECK_OPEN_BASEDIR(fn, "Invalid filename");
2836 :
2837 10 : fp = VCWD_FOPEN(fn, "wb");
2838 10 : if (!fp) {
2839 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open '%s' for writing", fn);
2840 0 : RETURN_FALSE;
2841 : }
2842 :
2843 10 : switch (image_type) {
2844 : #ifdef HAVE_GD_WBMP
2845 : case PHP_GDIMG_CONVERT_WBM:
2846 0 : if (q == -1) {
2847 0 : q = 0;
2848 0 : } else if (q < 0 || q > 255) {
2849 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid threshold value '%d'. It must be between 0 and 255", q);
2850 0 : q = 0;
2851 : }
2852 0 : gdImageWBMP(im, q, fp);
2853 0 : break;
2854 : #endif
2855 : case PHP_GDIMG_TYPE_JPG:
2856 0 : (*func_p)(im, fp, q);
2857 0 : break;
2858 : case PHP_GDIMG_TYPE_WBM:
2859 0 : for (i = 0; i < gdImageColorsTotal(im); i++) {
2860 0 : if (gdImageRed(im, i) == 0) break;
2861 : }
2862 0 : (*func_p)(im, i, fp);
2863 0 : break;
2864 : #if HAVE_LIBGD20
2865 : case PHP_GDIMG_TYPE_GD:
2866 4 : if (im->trueColor){
2867 2 : gdImageTrueColorToPalette(im,1,256);
2868 : }
2869 4 : (*func_p)(im, fp);
2870 4 : break;
2871 : #endif
2872 : #ifdef HAVE_GD_GD2
2873 : case PHP_GDIMG_TYPE_GD2:
2874 6 : if (q == -1) {
2875 6 : q = 128;
2876 : }
2877 6 : (*func_p)(im, fp, q, t);
2878 6 : break;
2879 : #endif
2880 : default:
2881 0 : if (q == -1) {
2882 0 : q = 128;
2883 : }
2884 0 : (*func_p)(im, fp, q, t);
2885 : break;
2886 : }
2887 10 : fflush(fp);
2888 10 : fclose(fp);
2889 : } else {
2890 : int b;
2891 : FILE *tmp;
2892 : char buf[4096];
2893 : char *path;
2894 :
2895 1 : tmp = php_open_temporary_file(NULL, NULL, &path TSRMLS_CC);
2896 1 : if (tmp == NULL) {
2897 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open temporary file");
2898 0 : RETURN_FALSE;
2899 : }
2900 :
2901 1 : switch (image_type) {
2902 : #ifdef HAVE_GD_WBMP
2903 : case PHP_GDIMG_CONVERT_WBM:
2904 0 : if (q == -1) {
2905 0 : q = 0;
2906 0 : } else if (q < 0 || q > 255) {
2907 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid threshold value '%d'. It must be between 0 and 255", q);
2908 0 : q = 0;
2909 : }
2910 0 : gdImageWBMP(im, q, tmp);
2911 0 : break;
2912 : #endif
2913 : case PHP_GDIMG_TYPE_JPG:
2914 0 : (*func_p)(im, tmp, q);
2915 0 : break;
2916 : case PHP_GDIMG_TYPE_WBM:
2917 0 : for (i = 0; i < gdImageColorsTotal(im); i++) {
2918 0 : if (gdImageRed(im, i) == 0) {
2919 0 : break;
2920 : }
2921 : }
2922 0 : (*func_p)(im, q, tmp);
2923 0 : break;
2924 : #if HAVE_LIBGD20
2925 : case PHP_GDIMG_TYPE_GD:
2926 0 : if (im->trueColor) {
2927 0 : gdImageTrueColorToPalette(im,1,256);
2928 : }
2929 0 : (*func_p)(im, tmp);
2930 0 : break;
2931 : #endif
2932 : #ifdef HAVE_GD_GD2
2933 : case PHP_GDIMG_TYPE_GD2:
2934 1 : if (q == -1) {
2935 1 : q = 128;
2936 : }
2937 1 : (*func_p)(im, tmp, q, t);
2938 1 : break;
2939 : #endif
2940 : default:
2941 0 : (*func_p)(im, tmp);
2942 : break;
2943 : }
2944 :
2945 1 : fseek(tmp, 0, SEEK_SET);
2946 :
2947 : #if APACHE && defined(CHARSET_EBCDIC)
2948 : /* XXX this is unlikely to work any more thies@thieso.net */
2949 :
2950 : /* This is a binary file already: avoid EBCDIC->ASCII conversion */
2951 : ap_bsetflag(php3_rqst->connection->client, B_EBCDIC2ASCII, 0);
2952 : #endif
2953 3 : while ((b = fread(buf, 1, sizeof(buf), tmp)) > 0) {
2954 1 : php_write(buf, b TSRMLS_CC);
2955 : }
2956 :
2957 1 : fclose(tmp);
2958 1 : VCWD_UNLINK((const char *)path); /* make sure that the temporary file is removed */
2959 1 : efree(path);
2960 : }
2961 11 : RETURN_TRUE;
2962 : }
2963 : /* }}} */
2964 :
2965 : /* {{{ proto int imagexbm(int im, string filename [, int foreground])
2966 : Output XBM image to browser or file */
2967 : #if HAVE_GD_BUNDLED
2968 : PHP_FUNCTION(imagexbm)
2969 0 : {
2970 0 : _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_XBM, "XBM", gdImageXbmCtx);
2971 0 : }
2972 : #endif
2973 : /* }}} */
2974 :
2975 : #ifdef HAVE_GD_GIF_CREATE
2976 : /* {{{ proto bool imagegif(resource im [, string filename])
2977 : Output GIF image to browser or file */
2978 : PHP_FUNCTION(imagegif)
2979 11 : {
2980 : #ifdef HAVE_GD_GIF_CTX
2981 11 : _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_GIF, "GIF", gdImageGifCtx);
2982 : #else
2983 : _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_GIF, "GIF", gdImageGif);
2984 : #endif
2985 11 : }
2986 : /* }}} */
2987 : #endif /* HAVE_GD_GIF_CREATE */
2988 :
2989 : #ifdef HAVE_GD_PNG
2990 : /* {{{ proto bool imagepng(resource im [, string filename])
2991 : Output PNG image to browser or file */
2992 : PHP_FUNCTION(imagepng)
2993 59 : {
2994 : #ifdef USE_GD_IOCTX
2995 59 : _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_PNG, "PNG", gdImagePngCtxEx);
2996 : #else
2997 : _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_PNG, "PNG", gdImagePng);
2998 : #endif
2999 59 : }
3000 : /* }}} */
3001 : #endif /* HAVE_GD_PNG */
3002 :
3003 : #ifdef HAVE_GD_JPG
3004 : /* {{{ proto bool imagejpeg(resource im [, string filename [, int quality]])
3005 : Output JPEG image to browser or file */
3006 : PHP_FUNCTION(imagejpeg)
3007 8 : {
3008 : #ifdef USE_GD_IOCTX
3009 8 : _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_JPG, "JPEG", gdImageJpegCtx);
3010 : #else
3011 : _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_JPG, "JPEG", gdImageJpeg);
3012 : #endif
3013 8 : }
3014 : /* }}} */
3015 : #endif /* HAVE_GD_JPG */
3016 :
3017 : #ifdef HAVE_GD_WBMP
3018 : /* {{{ proto bool imagewbmp(resource im [, string filename, [, int foreground]])
3019 : Output WBMP image to browser or file */
3020 : PHP_FUNCTION(imagewbmp)
3021 1 : {
3022 : #ifdef USE_GD_IOCTX
3023 1 : _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_WBM, "WBMP", gdImageWBMPCtx);
3024 : #else
3025 : _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_WBM, "WBMP", gdImageWBMP);
3026 : #endif
3027 1 : }
3028 : /* }}} */
3029 : #endif /* HAVE_GD_WBMP */
3030 :
3031 : /* {{{ proto bool imagegd(resource im [, string filename])
3032 : Output GD image to browser or file */
3033 : PHP_FUNCTION(imagegd)
3034 4 : {
3035 4 : _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_GD, "GD", gdImageGd);
3036 4 : }
3037 : /* }}} */
3038 :
3039 : #ifdef HAVE_GD_GD2
3040 : /* {{{ proto bool imagegd2(resource im [, string filename, [, int chunk_size, [, int type]]])
3041 : Output GD2 image to browser or file */
3042 : PHP_FUNCTION(imagegd2)
3043 7 : {
3044 7 : _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_GD2, "GD2", gdImageGd2);
3045 7 : }
3046 : /* }}} */
3047 : #endif /* HAVE_GD_GD2 */
3048 :
3049 : /* {{{ proto bool imagedestroy(resource im)
3050 : Destroy an image */
3051 : PHP_FUNCTION(imagedestroy)
3052 45 : {
3053 : zval **IM;
3054 : gdImagePtr im;
3055 :
3056 45 : if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &IM) == FAILURE) {
3057 0 : ZEND_WRONG_PARAM_COUNT();
3058 : }
3059 :
3060 45 : ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
3061 :
3062 45 : zend_list_delete(Z_LVAL_PP(IM));
3063 :
3064 45 : RETURN_TRUE;
3065 : }
3066 : /* }}} */
3067 :
3068 :
3069 : /* {{{ proto int imagecolorallocate(resource im, int red, int green, int blue)
3070 : Allocate a color for an image */
3071 : PHP_FUNCTION(imagecolorallocate)
3072 1278 : {
3073 : zval **IM, **red, **green, **blue;
3074 : gdImagePtr im;
3075 1278 : int ct = (-1);
3076 :
3077 1278 : if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &IM, &red, &green, &blue) == FAILURE) {
3078 3 : ZEND_WRONG_PARAM_COUNT();
3079 : }
3080 :
3081 1275 : ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
3082 :
3083 1245 : convert_to_long_ex(red);
3084 1245 : convert_to_long_ex(green);
3085 1245 : convert_to_long_ex(blue);
3086 1245 : ct = gdImageColorAllocate(im, Z_LVAL_PP(red), Z_LVAL_PP(green), Z_LVAL_PP(blue));
3087 1245 : if (ct < 0) {
3088 5 : RETURN_FALSE;
3089 : }
3090 1240 : RETURN_LONG(ct);
3091 : }
3092 : /* }}} */
3093 :
3094 : #if HAVE_LIBGD15
3095 : /* {{{ proto void imagepalettecopy(resource dst, resource src)
3096 : Copy the palette from the src image onto the dst image */
3097 : PHP_FUNCTION(imagepalettecopy)
3098 2 : {
3099 : zval **dstim, **srcim;
3100 : gdImagePtr dst, src;
3101 :
3102 2 : if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &dstim, &srcim) == FAILURE) {
3103 0 : ZEND_WRONG_PARAM_COUNT();
3104 : }
3105 :
3106 2 : ZEND_FETCH_RESOURCE(dst, gdImagePtr, dstim, -1, "Image", le_gd);
3107 2 : ZEND_FETCH_RESOURCE(src, gdImagePtr, srcim, -1, "Image", le_gd);
3108 :
3109 2 : gdImagePaletteCopy(dst, src);
3110 : }
3111 : /* }}} */
3112 : #endif
3113 :
3114 : /* {{{ proto int imagecolorat(resource im, int x, int y)
3115 : Get the index of the color of a pixel */
3116 : PHP_FUNCTION(imagecolorat)
3117 139936 : {
3118 : zval **IM, **x, **y;
3119 : gdImagePtr im;
3120 :
3121 139936 : if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &IM, &x, &y) == FAILURE) {
3122 0 : ZEND_WRONG_PARAM_COUNT();
3123 : }
3124 :
3125 139936 : ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
3126 :
3127 139936 : convert_to_long_ex(x);
3128 139936 : convert_to_long_ex(y);
3129 :
3130 : #if HAVE_LIBGD20
3131 139936 : if (gdImageTrueColor(im)) {
3132 72898 : if (im->tpixels && gdImageBoundsSafe(im, Z_LVAL_PP(x), Z_LVAL_PP(y))) {
3133 72898 : RETURN_LONG(gdImageTrueColorPixel(im, Z_LVAL_PP(x), Z_LVAL_PP(y)));
3134 : } else {
3135 0 : php_error_docref(NULL TSRMLS_CC, E_NOTICE, "%ld,%ld is out of bounds", Z_LVAL_PP(x), Z_LVAL_PP(y));
3136 0 : RETURN_FALSE;
3137 : }
3138 : } else {
3139 : #endif
3140 67038 : if (im->pixels && gdImageBoundsSafe(im, Z_LVAL_PP(x), Z_LVAL_PP(y))) {
3141 : #if HAVE_LIBGD13
3142 67038 : RETURN_LONG(im->pixels[Z_LVAL_PP(y)][Z_LVAL_PP(x)]);
3143 : #else
3144 : RETURN_LONG(im->pixels[Z_LVAL_PP(x)][Z_LVAL_PP(y)]);
3145 : #endif
3146 : } else {
3147 0 : php_error_docref(NULL TSRMLS_CC, E_NOTICE, "%ld,%ld is out of bounds", Z_LVAL_PP(x), Z_LVAL_PP(y));
3148 0 : RETURN_FALSE;
3149 : }
3150 : #if HAVE_LIBGD20
3151 : }
3152 : #endif
3153 : }
3154 : /* }}} */
3155 :
3156 : /* {{{ proto int imagecolorclosest(resource im, int red, int green, int blue)
3157 : Get the index of the closest color to the specified color */
3158 : PHP_FUNCTION(imagecolorclosest)
3159 5 : {
3160 : zval **IM, **red, **green, **blue;
3161 : gdImagePtr im;
3162 :
3163 5 : if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &IM, &red, &green, &blue) == FAILURE) {
3164 0 : ZEND_WRONG_PARAM_COUNT();
3165 : }
3166 :
3167 5 : ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
3168 :
3169 5 : convert_to_long_ex(red);
3170 5 : convert_to_long_ex(green);
3171 5 : convert_to_long_ex(blue);
3172 :
3173 5 : RETURN_LONG(gdImageColorClosest(im, Z_LVAL_PP(red), Z_LVAL_PP(green), Z_LVAL_PP(blue)));
3174 : }
3175 : /* }}} */
3176 :
3177 : #if HAVE_COLORCLOSESTHWB
3178 : /* {{{ proto int imagecolorclosesthwb(resource im, int red, int green, int blue)
3179 : Get the index of the color which has the hue, white and blackness nearest to the given color */
3180 : PHP_FUNCTION(imagecolorclosesthwb)
3181 0 : {
3182 : zval **IM, **red, **green, **blue;
3183 : gdImagePtr im;
3184 :
3185 0 : if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &IM, &red, &green, &blue) == FAILURE) {
3186 0 : ZEND_WRONG_PARAM_COUNT();
3187 : }
3188 :
3189 0 : ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
3190 :
3191 0 : convert_to_long_ex(red);
3192 0 : convert_to_long_ex(green);
3193 0 : convert_to_long_ex(blue);
3194 :
3195 0 : RETURN_LONG(gdImageColorClosestHWB(im, Z_LVAL_PP(red), Z_LVAL_PP(green), Z_LVAL_PP(blue)));
3196 : }
3197 : /* }}} */
3198 : #endif
3199 :
3200 : /* {{{ proto bool imagecolordeallocate(resource im, int index)
3201 : De-allocate a color for an image */
3202 : PHP_FUNCTION(imagecolordeallocate)
3203 5 : {
3204 : zval **IM, **index;
3205 : int col;
3206 : gdImagePtr im;
3207 :
3208 5 : if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &IM, &index) == FAILURE) {
3209 0 : ZEND_WRONG_PARAM_COUNT();
3210 : }
3211 :
3212 5 : ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
3213 :
3214 : #if HAVE_LIBGD20
3215 : /* We can return right away for a truecolor image as deallocating colours is meaningless here */
3216 3 : if (gdImageTrueColor(im)) {
3217 1 : RETURN_TRUE;
3218 : }
3219 : #endif
3220 :
3221 2 : convert_to_long_ex(index);
3222 2 : col = Z_LVAL_PP(index);
3223 :
3224 2 : if (col >= 0 && col < gdImageColorsTotal(im)) {
3225 0 : gdImageColorDeallocate(im, col);
3226 0 : RETURN_TRUE;
3227 : } else {
3228 2 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Color index %d out of range", col);
3229 2 : RETURN_FALSE;
3230 : }
3231 : }
3232 : /* }}} */
3233 :
3234 : /* {{{ proto int imagecolorresolve(resource im, int red, int green, int blue)
3235 : Get the index of the specified color or its closest possible alternative */
3236 : PHP_FUNCTION(imagecolorresolve)
3237 770 : {
3238 : zval **IM, **red, **green, **blue;
3239 : gdImagePtr im;
3240 :
3241 770 : if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &IM, &red, &green, &blue) == FAILURE) {
3242 0 : ZEND_WRONG_PARAM_COUNT();
3243 : }
3244 :
3245 770 : ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
3246 :
3247 770 : convert_to_long_ex(red);
3248 770 : convert_to_long_ex(green);
3249 770 : convert_to_long_ex(blue);
3250 :
3251 770 : RETURN_LONG(gdImageColorResolve(im, Z_LVAL_PP(red), Z_LVAL_PP(green), Z_LVAL_PP(blue)));
3252 : }
3253 : /* }}} */
3254 :
3255 : /* {{{ proto int imagecolorexact(resource im, int red, int green, int blue)
3256 : Get the index of the specified color */
3257 : PHP_FUNCTION(imagecolorexact)
3258 4 : {
3259 : zval **IM, **red, **green, **blue;
3260 : gdImagePtr im;
3261 :
3262 4 : if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &IM, &red, &green, &blue) == FAILURE) {
3263 0 : ZEND_WRONG_PARAM_COUNT();
3264 : }
3265 :
3266 4 : ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
3267 :
3268 4 : convert_to_long_ex(red);
3269 4 : convert_to_long_ex(green);
3270 4 : convert_to_long_ex(blue);
3271 :
3272 4 : RETURN_LONG(gdImageColorExact(im, Z_LVAL_PP(red), Z_LVAL_PP(green), Z_LVAL_PP(blue)));
3273 : }
3274 : /* }}} */
3275 :
3276 : /* {{{ proto void imagecolorset(resource im, int col, int red, int green, int blue)
3277 : Set the color for the specified palette index */
3278 : PHP_FUNCTION(imagecolorset)
3279 1 : {
3280 : zval **IM, **color, **red, **green, **blue;
3281 : int col;
3282 : gdImagePtr im;
3283 :
3284 1 : if (ZEND_NUM_ARGS() != 5 || zend_get_parameters_ex(5, &IM, &color, &red, &green, &blue) == FAILURE) {
3285 0 : ZEND_WRONG_PARAM_COUNT();
3286 : }
3287 :
3288 1 : ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
3289 :
3290 1 : convert_to_long_ex(color);
3291 1 : convert_to_long_ex(red);
3292 1 : convert_to_long_ex(green);
3293 1 : convert_to_long_ex(blue);
3294 :
3295 1 : col = Z_LVAL_PP(color);
3296 :
3297 2 : if (col >= 0 && col < gdImageColorsTotal(im)) {
3298 1 : im->red[col] = Z_LVAL_PP(red);
3299 1 : im->green[col] = Z_LVAL_PP(green);
3300 1 : im->blue[col] = Z_LVAL_PP(blue);
3301 : } else {
3302 0 : RETURN_FALSE;
3303 : }
3304 : }
3305 : /* }}} */
3306 :
3307 : /* {{{ proto array imagecolorsforindex(resource im, int col)
3308 : Get the colors for an index */
3309 : PHP_FUNCTION(imagecolorsforindex)
3310 1741 : {
3311 : zval **IM, **index;
3312 : int col;
3313 : gdImagePtr im;
3314 :
3315 1741 : if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &IM, &index) == FAILURE) {
3316 0 : ZEND_WRONG_PARAM_COUNT();
3317 : }
3318 :
3319 1741 : ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
3320 :
3321 1741 : convert_to_long_ex(index);
3322 1741 : col = Z_LVAL_PP(index);
3323 : #if HAVE_LIBGD20
3324 3480 : if ((col >= 0 && gdImageTrueColor(im)) || (!gdImageTrueColor(im) && col >= 0 && col < gdImageColorsTotal(im))) {
3325 1739 : array_init(return_value);
3326 :
3327 1739 : add_assoc_long(return_value,"red", gdImageRed(im,col));
3328 1739 : add_assoc_long(return_value,"green", gdImageGreen(im,col));
3329 1739 : add_assoc_long(return_value,"blue", gdImageBlue(im,col));
3330 1739 : add_assoc_long(return_value,"alpha", gdImageAlpha(im,col));
3331 : }
3332 : #else
3333 : if (col >= 0 && col < gdImageColorsTotal(im)) {
3334 : array_init(return_value);
3335 :
3336 : add_assoc_long(return_value,"red", im->red[col]);
3337 : add_assoc_long(return_value,"green", im->green[col]);
3338 : add_assoc_long(return_value,"blue", im->blue[col]);
3339 : }
3340 : #endif
3341 : else {
3342 2 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Color index %d out of range", col);
3343 2 : RETURN_FALSE;
3344 : }
3345 : }
3346 : /* }}} */
3347 :
3348 : /* {{{ proto bool imagegammacorrect(resource im, float inputgamma, float outputgamma)
3349 : Apply a gamma correction to a GD image */
3350 : PHP_FUNCTION(imagegammacorrect)
3351 4 : {
3352 : zval **IM, **inputgamma, **outputgamma;
3353 : gdImagePtr im;
3354 : int i;
3355 : double input, output;
3356 :
3357 4 : if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &IM, &inputgamma, &outputgamma) == FAILURE) {
3358 0 : ZEND_WRONG_PARAM_COUNT();
3359 : }
3360 :
3361 4 : convert_to_double_ex(inputgamma);
3362 4 : convert_to_double_ex(outputgamma);
3363 :
3364 4 : input = Z_DVAL_PP(inputgamma);
3365 4 : output = Z_DVAL_PP(outputgamma);
3366 :
3367 4 : ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
3368 :
3369 : #if HAVE_LIBGD20
3370 2 : if (gdImageTrueColor(im)) {
3371 : int x, y, c;
3372 :
3373 151 : for (y = 0; y < gdImageSY(im); y++) {
3374 22650 : for (x = 0; x < gdImageSX(im); x++) {
3375 22500 : c = gdImageGetPixel(im, x, y);
3376 22500 : gdImageSetPixel(im, x, y,
3377 : gdTrueColor(
3378 : (int) ((pow((pow((gdTrueColorGetRed(c) / 255.0), input)), 1.0 / output) * 255) + .5),
3379 : (int) ((pow((pow((gdTrueColorGetGreen(c) / 255.0), input)), 1.0 / output) * 255) + .5),
3380 : (int) ((pow((pow((gdTrueColorGetBlue(c) / 255.0), input)), 1.0 / output) * 255) + .5)
3381 : )
3382 : );
3383 : }
3384 : }
3385 1 : RETURN_TRUE;
3386 : }
3387 : #endif
3388 3 : for (i = 0; i < gdImageColorsTotal(im); i++) {
3389 2 : im->red[i] = (int)((pow((pow((im->red[i] / 255.0), input)), 1.0 / output) * 255) + .5);
3390 2 : im->green[i] = (int)((pow((pow((im->green[i] / 255.0), input)), 1.0 / output) * 255) + .5);
3391 2 : im->blue[i] = (int)((pow((pow((im->blue[i] / 255.0), input)), 1.0 / output) * 255) + .5);
3392 : }
3393 :
3394 1 : RETURN_TRUE;
3395 : }
3396 : /* }}} */
3397 :
3398 : /* {{{ proto bool imagesetpixel(resource im, int x, int y, int col)
3399 : Set a single pixel */
3400 : PHP_FUNCTION(imagesetpixel)
3401 341 : {
3402 : zval **IM, **x, **y, **col;
3403 : gdImagePtr im;
3404 :
3405 341 : if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &IM, &x, &y, &col) == FAILURE) {
3406 0 : ZEND_WRONG_PARAM_COUNT();
3407 : }
3408 :
3409 341 : ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
3410 :
3411 341 : convert_to_long_ex(x);
3412 341 : convert_to_long_ex(y);
3413 341 : convert_to_long_ex(col);
3414 :
3415 341 : gdImageSetPixel(im, Z_LVAL_PP(x), Z_LVAL_PP(y), Z_LVAL_PP(col));
3416 :
3417 341 : RETURN_TRUE;
3418 : }
3419 : /* }}} */
3420 :
3421 : /* {{{ proto bool imageline(resource im, int x1, int y1, int x2, int y2, int col)
3422 : Draw a line */
3423 : PHP_FUNCTION(imageline)
3424 29 : {
3425 : zval **IM, **x1, **y1, **x2, **y2, **col;
3426 : gdImagePtr im;
3427 :
3428 29 : if (ZEND_NUM_ARGS() != 6 || zend_get_parameters_ex(6, &IM, &x1, &y1, &x2, &y2, &col) == FAILURE) {
3429 1 : ZEND_WRONG_PARAM_COUNT();
3430 : }
3431 :
3432 28 : ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
3433 :
3434 28 : convert_to_long_ex(x1);
3435 28 : convert_to_long_ex(y1);
3436 28 : convert_to_long_ex(x2);
3437 28 : convert_to_long_ex(y2);
3438 28 : convert_to_long_ex(col);
3439 :
3440 : #ifdef HAVE_GD_BUNDLED
3441 28 : if (im->antialias) {
3442 2 : gdImageAALine(im, Z_LVAL_PP(x1), Z_LVAL_PP(y1), Z_LVAL_PP(x2), Z_LVAL_PP(y2), Z_LVAL_PP(col));
3443 : } else
3444 : #endif
3445 : {
3446 26 : gdImageLine(im, Z_LVAL_PP(x1), Z_LVAL_PP(y1), Z_LVAL_PP(x2), Z_LVAL_PP(y2), Z_LVAL_PP(col));
3447 : }
3448 28 : RETURN_TRUE;
3449 : }
3450 : /* }}} */
3451 :
3452 : /* {{{ proto bool imagedashedline(resource im, int x1, int y1, int x2, int y2, int col)
3453 : Draw a dashed line */
3454 : PHP_FUNCTION(imagedashedline)
3455 2 : {
3456 : zval **IM, **x1, **y1, **x2, **y2, **col;
3457 : gdImagePtr im;
3458 :
3459 2 : if (ZEND_NUM_ARGS() != 6 || zend_get_parameters_ex(6, &IM, &x1, &y1, &x2, &y2, &col) == FAILURE) {
3460 0 : ZEND_WRONG_PARAM_COUNT();
3461 : }
3462 :
3463 2 : ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
3464 :
3465 2 : convert_to_long_ex(x1);
3466 2 : convert_to_long_ex(y1);
3467 2 : convert_to_long_ex(x2);
3468 2 : convert_to_long_ex(y2);
3469 2 : convert_to_long_ex(col);
3470 :
3471 2 : gdImageDashedLine(im, Z_LVAL_PP(x1), Z_LVAL_PP(y1), Z_LVAL_PP(x2), Z_LVAL_PP(y2), Z_LVAL_PP(col));
3472 2 : RETURN_TRUE;
3473 : }
3474 : /* }}} */
3475 :
3476 : /* {{{ proto bool imagerectangle(resource im, int x1, int y1, int x2, int y2, int col)
3477 : Draw a rectangle */
3478 : PHP_FUNCTION(imagerectangle)
3479 9 : {
3480 : zval **IM, **x1, **y1, **x2, **y2, **col;
3481 : gdImagePtr im;
3482 :
3483 9 : if (ZEND_NUM_ARGS() != 6 || zend_get_parameters_ex(6, &IM, &x1, &y1, &x2, &y2, &col) == FAILURE) {
3484 1 : ZEND_WRONG_PARAM_COUNT();
3485 : }
3486 :
3487 8 : ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
3488 :
3489 6 : convert_to_long_ex(x1);
3490 6 : convert_to_long_ex(y1);
3491 6 : convert_to_long_ex(x2);
3492 6 : convert_to_long_ex(y2);
3493 6 : convert_to_long_ex(col);
3494 :
3495 6 : gdImageRectangle(im, Z_LVAL_PP(x1), Z_LVAL_PP(y1), Z_LVAL_PP(x2), Z_LVAL_PP(y2), Z_LVAL_PP(col));
3496 6 : RETURN_TRUE;
3497 : }
3498 : /* }}} */
3499 :
3500 : /* {{{ proto bool imagefilledrectangle(resource im, int x1, int y1, int x2, int y2, int col)
3501 : Draw a filled rectangle */
3502 : PHP_FUNCTION(imagefilledrectangle)
3503 54 : {
3504 : zval **IM, **x1, **y1, **x2, **y2, **col;
3505 : gdImagePtr im;
3506 :
3507 54 : if (ZEND_NUM_ARGS() != 6 || zend_get_parameters_ex(6, &IM, &x1, &y1, &x2, &y2, &col) == FAILURE) {
3508 0 : ZEND_WRONG_PARAM_COUNT();
3509 : }
3510 :
3511 54 : ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
3512 :
3513 54 : convert_to_long_ex(x1);
3514 54 : convert_to_long_ex(y1);
3515 54 : convert_to_long_ex(x2);
3516 54 : convert_to_long_ex(y2);
3517 54 : convert_to_long_ex(col);
3518 :
3519 54 : gdImageFilledRectangle(im, Z_LVAL_PP(x1), Z_LVAL_PP(y1), Z_LVAL_PP(x2), Z_LVAL_PP(y2), Z_LVAL_PP(col));
3520 54 : RETURN_TRUE;
3521 : }
3522 : /* }}} */
3523 :
3524 : /* {{{ proto bool imagearc(resource im, int cx, int cy, int w, int h, int s, int e, int col)
3525 : Draw a partial ellipse */
3526 : PHP_FUNCTION(imagearc)
3527 4 : {
3528 : zval **IM, **cx, **cy, **w, **h, **ST, **E, **col;
3529 : gdImagePtr im;
3530 : int e, st;
3531 :
3532 4 : if (ZEND_NUM_ARGS() != 8 || zend_get_parameters_ex(8, &IM, &cx, &cy, &w, &h, &ST, &E, &col) == FAILURE) {
3533 1 : ZEND_WRONG_PARAM_COUNT();
3534 : }
3535 :
3536 3 : ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
3537 :
3538 3 : convert_to_long_ex(cx);
3539 3 : convert_to_long_ex(cy);
3540 3 : convert_to_long_ex(w);
3541 3 : convert_to_long_ex(h);
3542 3 : convert_to_long_ex(ST);
3543 3 : convert_to_long_ex(E);
3544 3 : convert_to_long_ex(col);
3545 :
3546 3 : e = Z_LVAL_PP(E);
3547 3 : if (e < 0) {
3548 1 : e %= 360;
3549 : }
3550 :
3551 3 : st = Z_LVAL_PP(ST);
3552 3 : if (st < 0) {
3553 1 : st %= 360;
3554 : }
3555 :
3556 3 : gdImageArc(im, Z_LVAL_PP(cx), Z_LVAL_PP(cy), Z_LVAL_PP(w), Z_LVAL_PP(h), st, e, Z_LVAL_PP(col));
3557 3 : RETURN_TRUE;
3558 : }
3559 : /* }}} */
3560 :
3561 : /* {{{ proto bool imageellipse(resource im, int cx, int cy, int w, int h, int color)
3562 : Draw an ellipse */
3563 : PHP_FUNCTION(imageellipse)
3564 8 : {
3565 : zval **IM, **cx, **cy, **w, **h, **color;
3566 : gdImagePtr im;
3567 :
3568 8 : if (ZEND_NUM_ARGS() != 6 || zend_get_parameters_ex(6, &IM, &cx, &cy, &w, &h, &color) == FAILURE) {
3569 1 : ZEND_WRONG_PARAM_COUNT();
3570 : }
3571 :
3572 7 : ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
3573 :
3574 5 : convert_to_long_ex(cx);
3575 5 : convert_to_long_ex(cy);
3576 5 : convert_to_long_ex(w);
3577 5 : convert_to_long_ex(h);
3578 5 : convert_to_long_ex(color);
3579 :
3580 : #ifdef HAVE_GD_IMAGEELLIPSE /* this function is missing from GD 2.0.1 */
3581 5 : gdImageEllipse(im, Z_LVAL_PP(cx), Z_LVAL_PP(cy), Z_LVAL_PP(w), Z_LVAL_PP(h), Z_LVAL_PP(color));
3582 : #else
3583 : gdImageArc(im, Z_LVAL_PP(cx), Z_LVAL_PP(cy), Z_LVAL_PP(w), Z_LVAL_PP(h), 0, 360, Z_LVAL_PP(color));
3584 : #endif
3585 :
3586 5 : RETURN_TRUE;
3587 : }
3588 : /* }}} */
3589 :
3590 : /* {{{ proto bool imagefilltoborder(resource im, int x, int y, int border, int col)
3591 : Flood fill to specific color */
3592 : PHP_FUNCTION(imagefilltoborder)
3593 5 : {
3594 : zval **IM, **x, **y, **border, **col;
3595 : gdImagePtr im;
3596 :
3597 5 : if (ZEND_NUM_ARGS() != 5 || zend_get_parameters_ex(5, &IM, &x, &y, &border, &col) == FAILURE) {
3598 1 : ZEND_WRONG_PARAM_COUNT();
3599 : }
3600 :
3601 4 : ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
3602 :
3603 2 : convert_to_long_ex(x);
3604 2 : convert_to_long_ex(y);
3605 2 : convert_to_long_ex(border);
3606 2 : convert_to_long_ex(col);
3607 :
3608 2 : gdImageFillToBorder(im, Z_LVAL_PP(x), Z_LVAL_PP(y), Z_LVAL_PP(border), Z_LVAL_PP(col));
3609 2 : RETURN_TRUE;
3610 : }
3611 : /* }}} */
3612 :
3613 : /* {{{ proto bool imagefill(resource im, int x, int y, int col)
3614 : Flood fill */
3615 : PHP_FUNCTION(imagefill)
3616 33 : {
3617 : zval **IM, **x, **y, **col;
3618 : gdImagePtr im;
3619 :
3620 33 : if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &IM, &x, &y, &col) == FAILURE) {
3621 0 : ZEND_WRONG_PARAM_COUNT();
3622 : }
3623 :
3624 33 : ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
3625 :
3626 33 : convert_to_long_ex(x);
3627 33 : convert_to_long_ex(y);
3628 33 : convert_to_long_ex(col);
3629 :
3630 33 : gdImageFill(im, Z_LVAL_PP(x), Z_LVAL_PP(y), Z_LVAL_PP(col));
3631 33 : RETURN_TRUE;
3632 : }
3633 : /* }}} */
3634 :
3635 : /* {{{ proto int imagecolorstotal(resource im)
3636 : Find out the number of colors in an image's palette */
3637 : PHP_FUNCTION(imagecolorstotal)
3638 6 : {
3639 : zval **IM;
3640 : gdImagePtr im;
3641 :
3642 6 : if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &IM) == FAILURE) {
3643 2 : ZEND_WRONG_PARAM_COUNT();
3644 : }
3645 :
3646 4 : ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
3647 :
3648 3 : RETURN_LONG(gdImageColorsTotal(im));
3649 : }
3650 : /* }}} */
3651 :
3652 : /* {{{ proto int imagecolortransparent(resource im [, int col])
3653 : Define a color as transparent */
3654 : PHP_FUNCTION(imagecolortransparent)
3655 5 : {
3656 : zval **IM, **COL;
3657 : gdImagePtr im;
3658 :
3659 5 : switch (ZEND_NUM_ARGS()) {
3660 : case 1:
3661 0 : if (zend_get_parameters_ex(1, &IM) == FAILURE) {
3662 0 : ZEND_WRONG_PARAM_COUNT();
3663 : }
3664 0 : break;
3665 : case 2:
3666 5 : if (zend_get_parameters_ex(2, &IM, &COL) == FAILURE) {
3667 0 : ZEND_WRONG_PARAM_COUNT();
3668 : }
3669 5 : convert_to_long_ex(COL);
3670 5 : break;
3671 : default:
3672 0 : ZEND_WRONG_PARAM_COUNT();
3673 : }
3674 :
3675 5 : ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
3676 :
3677 5 : if (ZEND_NUM_ARGS() > 1) {
3678 5 : gdImageColorTransparent(im, Z_LVAL_PP(COL));
3679 : }
3680 :
3681 5 : RETURN_LONG(gdImageGetTransparent(im));
3682 : }
3683 : /* }}} */
3684 :
3685 : /* {{{ proto int imageinterlace(resource im [, int interlace])
3686 : Enable or disable interlace */
3687 : PHP_FUNCTION(imageinterlace)
3688 8 : {
3689 : zval **IM, **INT;
3690 : gdImagePtr im;
3691 :
3692 8 : switch (ZEND_NUM_ARGS()) {
3693 : case 1:
3694 4 : if (zend_get_parameters_ex(1, &IM) == FAILURE) {
3695 0 : ZEND_WRONG_PARAM_COUNT();
3696 : }
3697 4 : break;
3698 : case 2:
3699 3 : if (zend_get_parameters_ex(2, &IM, &INT) == FAILURE) {
3700 0 : ZEND_WRONG_PARAM_COUNT();
3701 : }
3702 3 : convert_to_long_ex(INT);
3703 3 : break;
3704 : default:
3705 1 : ZEND_WRONG_PARAM_COUNT();
3706 : }
3707 :
3708 7 : ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
3709 :
3710 6 : if (ZEND_NUM_ARGS() > 1) {
3711 3 : gdImageInterlace(im, Z_LVAL_PP(INT));
3712 : }
3713 :
3714 6 : RETURN_LONG(gdImageGetInterlaced(im));
3715 : }
3716 : /* }}} */
3717 :
3718 : /* {{{ php_imagepolygon
3719 : arg = 0 normal polygon
3720 : arg = 1 filled polygon */
3721 : /* im, points, num_points, col */
3722 : static void php_imagepolygon(INTERNAL_FUNCTION_PARAMETERS, int filled)
3723 2 : {
3724 : zval **IM, **POINTS, **NPOINTS, **COL;
3725 2 : zval **var = NULL;
3726 : gdImagePtr im;
3727 : gdPointPtr points;
3728 : int npoints, col, nelem, i;
3729 :
3730 2 : if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &IM, &POINTS, &NPOINTS, &COL) == FAILURE) {
3731 0 : ZEND_WRONG_PARAM_COUNT();
3732 : }
3733 :
3734 2 : ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
3735 :
3736 2 : convert_to_long_ex(NPOINTS);
3737 2 : convert_to_long_ex(COL);
3738 :
3739 2 : npoints = Z_LVAL_PP(NPOINTS);
3740 2 : col = Z_LVAL_PP(COL);
3741 :
3742 2 : if (Z_TYPE_PP(POINTS) != IS_ARRAY) {
3743 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "2nd argument to imagepolygon not an array");
3744 0 : RETURN_FALSE;
3745 : }
3746 :
3747 2 : nelem = zend_hash_num_elements(Z_ARRVAL_PP(POINTS));
3748 2 : if (nelem < 6) {
3749 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "You must have at least 3 points in your array");
3750 0 : RETURN_FALSE;
3751 : }
3752 :
3753 2 : if (nelem < npoints * 2) {
3754 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Trying to use %d points in array with only %d points", npoints, nelem/2);
3755 0 : RETURN_FALSE;
3756 : }
3757 :
3758 2 : points = (gdPointPtr) safe_emalloc(npoints, sizeof(gdPoint), 0);
3759 :
3760 11 : for (i = 0; i < npoints; i++) {
3761 9 : if (zend_hash_index_find(Z_ARRVAL_PP(POINTS), (i * 2), (void **) &var) == SUCCESS) {
3762 9 : SEPARATE_ZVAL((var));
3763 9 : convert_to_long(*var);
3764 9 : points[i].x = Z_LVAL_PP(var);
3765 : }
3766 9 : if (zend_hash_index_find(Z_ARRVAL_PP(POINTS), (i * 2) + 1, (void **) &var) == SUCCESS) {
3767 9 : SEPARATE_ZVAL(var);
3768 9 : convert_to_long(*var);
3769 9 : points[i].y = Z_LVAL_PP(var);
3770 : }
3771 : }
3772 :
3773 2 : if (filled) {
3774 1 : gdImageFilledPolygon(im, points, npoints, col);
3775 : } else {
3776 1 : gdImagePolygon(im, points, npoints, col);
3777 : }
3778 :
3779 2 : efree(points);
3780 2 : RETURN_TRUE;
3781 : }
3782 : /* }}} */
3783 :
3784 : /* {{{ proto bool imagepolygon(resource im, array point, int num_points, int col)
3785 : Draw a polygon */
3786 : PHP_FUNCTION(imagepolygon)
3787 1 : {
3788 1 : php_imagepolygon(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
3789 1 : }
3790 : /* }}} */
3791 :
3792 : /* {{{ proto bool imagefilledpolygon(resource im, array point, int num_points, int col)
3793 : Draw a filled polygon */
3794 : PHP_FUNCTION(imagefilledpolygon)
3795 1 : {
3796 1 : php_imagepolygon(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
3797 1 : }
3798 : /* }}} */
3799 :
3800 : /* {{{ php_find_gd_font
3801 : */
3802 : static gdFontPtr php_find_gd_font(int size TSRMLS_DC)
3803 28 : {
3804 : gdFontPtr font;
3805 : int ind_type;
3806 :
3807 28 : switch (size) {
3808 : case 1:
3809 13 : font = gdFontTiny;
3810 13 : break;
3811 : case 2:
3812 2 : font = gdFontSmall;
3813 2 : break;
3814 : case 3:
3815 2 : font = gdFontMediumBold;
3816 2 : break;
3817 : case 4:
3818 3 : font = gdFontLarge;
3819 3 : break;
3820 : case 5:
3821 7 : font = gdFontGiant;
3822 7 : break;
3823 : default:
3824 1 : font = zend_list_find(size - 5, &ind_type);
3825 1 : if (!font || ind_type != le_gd_font) {
3826 1 : if (size < 1) {
3827 1 : font = gdFontTiny;
3828 : } else {
3829 0 : font = gdFontGiant;
3830 : }
3831 : }
3832 : break;
3833 : }
3834 :
3835 28 : return font;
3836 : }
3837 : /* }}} */
3838 :
3839 : /* {{{ php_imagefontsize
3840 : * arg = 0 ImageFontWidth
3841 : * arg = 1 ImageFontHeight
3842 : */
3843 : static void php_imagefontsize(INTERNAL_FUNCTION_PARAMETERS, int arg)
3844 12 : {
3845 : zval **SIZE;
3846 : gdFontPtr font;
3847 :
3848 12 : if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &SIZE) == FAILURE) {
3849 0 : ZEND_WRONG_PARAM_COUNT();
3850 : }
3851 :
3852 12 : convert_to_long_ex(SIZE);
3853 :
3854 12 : font = php_find_gd_font(Z_LVAL_PP(SIZE) TSRMLS_CC);
3855 12 : RETURN_LONG(arg ? font->h : font->w);
3856 : }
3857 : /* }}} */
3858 :
3859 : /* {{{ proto int imagefontwidth(int font)
3860 : Get font width */
3861 : PHP_FUNCTION(imagefontwidth)
3862 7 : {
3863 7 : php_imagefontsize(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
3864 7 : }
3865 : /* }}} */
3866 :
3867 : /* {{{ proto int imagefontheight(int font)
3868 : Get font height */
3869 : PHP_FUNCTION(imagefontheight)
3870 5 : {
3871 5 : php_imagefontsize(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
3872 5 : }
3873 : /* }}} */
3874 :
3875 : /* {{{ php_gdimagecharup
3876 : * workaround for a bug in gd 1.2 */
3877 : static void php_gdimagecharup(gdImagePtr im, gdFontPtr f, int x, int y, int c, int color)
3878 1 : {
3879 : int cx, cy, px, py, fline;
3880 1 : cx = 0;
3881 1 : cy = 0;
3882 :
3883 1 : if ((c < f->offset) || (c >= (f->offset + f->nchars))) {
3884 0 : return;
3885 : }
3886 :
3887 1 : fline = (c - f->offset) * f->h * f->w;
3888 6 : for (py = y; (py > (y - f->w)); py--) {
3889 45 : for (px = x; (px < (x + f->h)); px++) {
3890 40 : if (f->data[fline + cy * f->w + cx]) {
3891 10 : gdImageSetPixel(im, px, py, color);
3892 : }
3893 40 : cy++;
3894 : }
3895 5 : cy = 0;
3896 5 : cx++;
3897 : }
3898 : }
3899 : /* }}} */
3900 :
3901 : /* {{{ php_imagechar
3902 : * arg = 0 ImageChar
3903 : * arg = 1 ImageCharUp
3904 : * arg = 2 ImageString
3905 : * arg = 3 ImageStringUp
3906 : */
3907 : static void php_imagechar(INTERNAL_FUNCTION_PARAMETERS, int mode)
3908 24 : {
3909 : zval **IM, **SIZE, **X, **Y, **C, **COL;
3910 : gdImagePtr im;
3911 24 : int ch = 0, col, x, y, size, i, l = 0;
3912 24 : unsigned char *str = NULL;
3913 : gdFontPtr font;
3914 :
3915 24 : if (ZEND_NUM_ARGS() != 6 || zend_get_parameters_ex(6, &IM, &SIZE, &X, &Y, &C, &COL) == FAILURE) {
3916 0 : ZEND_WRONG_PARAM_COUNT();
3917 : }
3918 :
3919 24 : ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
3920 :
3921 16 : convert_to_long_ex(SIZE);
3922 16 : convert_to_long_ex(X);
3923 16 : convert_to_long_ex(Y);
3924 16 : convert_to_string_ex(C);
3925 16 : convert_to_long_ex(COL);
3926 :
3927 16 : col = Z_LVAL_PP(COL);
3928 :
3929 16 : if (mode < 2) {
3930 2 : ch = (int)((unsigned char)*(Z_STRVAL_PP(C)));
3931 : } else {
3932 14 : str = (unsigned char *) estrndup(Z_STRVAL_PP(C), Z_STRLEN_PP(C));
3933 14 : l = strlen((char *)str);
3934 : }
3935 :
3936 16 : y = Z_LVAL_PP(Y);
3937 16 : x = Z_LVAL_PP(X);
3938 16 : size = Z_LVAL_PP(SIZE);
3939 :
3940 16 : font = php_find_gd_font(size TSRMLS_CC);
3941 :
3942 16 : switch (mode) {
3943 : case 0:
3944 1 : gdImageChar(im, font, x, y, ch, col);
3945 1 : break;
3946 : case 1:
3947 1 : php_gdimagecharup(im, font, x, y, ch, col);
3948 1 : break;
3949 : case 2:
3950 227 : for (i = 0; (i < l); i++) {
3951 214 : gdImageChar(im, font, x, y, (int) ((unsigned char) str[i]), col);
3952 214 : x += font->w;
3953 : }
3954 13 : break;
3955 : case 3: {
3956 4 : for (i = 0; (i < l); i++) {
3957 : /* php_gdimagecharup(im, font, x, y, (int) str[i], col); */
3958 3 : gdImageCharUp(im, font, x, y, (int) str[i], col);
3959 3 : y -= font->w;
3960 : }
3961 : break;
3962 : }
3963 : }
3964 16 : if (str) {
3965 14 : efree(str);
3966 : }
3967 16 : RETURN_TRUE;
3968 : }
3969 : /* }}} */
3970 :
3971 : /* {{{ proto bool imagechar(resource im, int font, int x, int y, string c, int col)
3972 : Draw a character */
3973 : PHP_FUNCTION(imagechar)
3974 3 : {
3975 3 : php_imagechar(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
3976 3 : }
3977 : /* }}} */
3978 :
3979 : /* {{{ proto bool imagecharup(resource im, int font, int x, int y, string c, int col)
3980 : Draw a character rotated 90 degrees counter-clockwise */
3981 : PHP_FUNCTION(imagecharup)
3982 3 : {
3983 3 : php_imagechar(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
3984 3 : }
3985 : /* }}} */
3986 :
3987 : /* {{{ proto bool imagestring(resource im, int font, int x, int y, string str, int col)
3988 : Draw a string horizontally */
3989 : PHP_FUNCTION(imagestring)
3990 15 : {
3991 15 : php_imagechar(INTERNAL_FUNCTION_PARAM_PASSTHRU, 2);
3992 15 : }
3993 : /* }}} */
3994 :
3995 : /* {{{ proto bool imagestringup(resource im, int font, int x, int y, string str, int col)
3996 : Draw a string vertically - rotated 90 degrees counter-clockwise */
3997 : PHP_FUNCTION(imagestringup)
3998 3 : {
3999 3 : php_imagechar(INTERNAL_FUNCTION_PARAM_PASSTHRU, 3);
4000 3 : }
4001 : /* }}} */
4002 :
4003 : /* {{{ proto bool imagecopy(resource dst_im, resource src_im, int dst_x, int dst_y, int src_x, int src_y, int src_w, int src_h)
4004 : Copy part of an image */
4005 : PHP_FUNCTION(imagecopy)
4006 5 : {
4007 : zval **SIM, **DIM, **SX, **SY, **SW, **SH, **DX, **DY;
4008 : gdImagePtr im_dst, im_src;
4009 : int srcH, srcW, srcY, srcX, dstY, dstX;
4010 :
4011 5 : if (ZEND_NUM_ARGS() != 8 || zend_get_parameters_ex(8, &DIM, &SIM, &DX, &DY, &SX, &SY, &SW, &SH) == FAILURE) {
4012 0 : ZEND_WRONG_PARAM_COUNT();
4013 : }
4014 :
4015 5 : ZEND_FETCH_RESOURCE(im_src, gdImagePtr, SIM, -1, "Image", le_gd);
4016 5 : ZEND_FETCH_RESOURCE(im_dst, gdImagePtr, DIM, -1, "Image", le_gd);
4017 :
4018 5 : convert_to_long_ex(SX);
4019 5 : convert_to_long_ex(SY);
4020 5 : convert_to_long_ex(SW);
4021 5 : convert_to_long_ex(SH);
4022 5 : convert_to_long_ex(DX);
4023 5 : convert_to_long_ex(DY);
4024 :
4025 5 : srcX = Z_LVAL_PP(SX);
4026 5 : srcY = Z_LVAL_PP(SY);
4027 5 : srcH = Z_LVAL_PP(SH);
4028 5 : srcW = Z_LVAL_PP(SW);
4029 5 : dstX = Z_LVAL_PP(DX);
4030 5 : dstY = Z_LVAL_PP(DY);
4031 :
4032 5 : gdImageCopy(im_dst, im_src, dstX, dstY, srcX, srcY, srcW, srcH);
4033 5 : RETURN_TRUE;
4034 : }
4035 : /* }}} */
4036 :
4037 : #if HAVE_LIBGD15
4038 : /* {{{ proto bool imagecopymerge(resource src_im, resource dst_im, int dst_x, int dst_y, int src_x, int src_y, int src_w, int src_h, int pct)
4039 : Merge one part of an image with another */
4040 : PHP_FUNCTION(imagecopymerge)
4041 2 : {
4042 : zval **SIM, **DIM, **SX, **SY, **SW, **SH, **DX, **DY, **PCT;
4043 : gdImagePtr im_dst, im_src;
4044 : int srcH, srcW, srcY, srcX, dstY, dstX, pct;
4045 :
4046 2 : if (ZEND_NUM_ARGS() != 9 || zend_get_parameters_ex(9, &DIM, &SIM, &DX, &DY, &SX, &SY, &SW, &SH, &PCT) == FAILURE) {
4047 1 : ZEND_WRONG_PARAM_COUNT();
4048 : }
4049 :
4050 1 : ZEND_FETCH_RESOURCE(im_src, gdImagePtr, SIM, -1, "Image", le_gd);
4051 1 : ZEND_FETCH_RESOURCE(im_dst, gdImagePtr, DIM, -1, "Image", le_gd);
4052 :
4053 1 : convert_to_long_ex(SX);
4054 1 : convert_to_long_ex(SY);
4055 1 : convert_to_long_ex(SW);
4056 1 : convert_to_long_ex(SH);
4057 1 : convert_to_long_ex(DX);
4058 1 : convert_to_long_ex(DY);
4059 1 : convert_to_long_ex(PCT);
4060 :
4061 1 : srcX = Z_LVAL_PP(SX);
4062 1 : srcY = Z_LVAL_PP(SY);
4063 1 : srcH = Z_LVAL_PP(SH);
4064 1 : srcW = Z_LVAL_PP(SW);
4065 1 : dstX = Z_LVAL_PP(DX);
4066 1 : dstY = Z_LVAL_PP(DY);
4067 1 : pct = Z_LVAL_PP(PCT);
4068 :
4069 1 : gdImageCopyMerge(im_dst, im_src, dstX, dstY, srcX, srcY, srcW, srcH, pct);
4070 1 : RETURN_TRUE;
4071 : }
4072 : /* }}} */
4073 :
4074 : /* {{{ proto bool imagecopymergegray(resource src_im, resource dst_im, int dst_x, int dst_y, int src_x, int src_y, int src_w, int src_h, int pct)
4075 : Merge one part of an image with another */
4076 : PHP_FUNCTION(imagecopymergegray)
4077 0 : {
4078 : zval **SIM, **DIM, **SX, **SY, **SW, **SH, **DX, **DY, **PCT;
4079 : gdImagePtr im_dst, im_src;
4080 : int srcH, srcW, srcY, srcX, dstY, dstX, pct;
4081 :
4082 0 : if (ZEND_NUM_ARGS() != 9 || zend_get_parameters_ex(9, &DIM, &SIM, &DX, &DY, &SX, &SY, &SW, &SH, &PCT) == FAILURE) {
4083 0 : ZEND_WRONG_PARAM_COUNT();
4084 : }
4085 :
4086 0 : ZEND_FETCH_RESOURCE(im_src, gdImagePtr, SIM, -1, "Image", le_gd);
4087 0 : ZEND_FETCH_RESOURCE(im_dst, gdImagePtr, DIM, -1, "Image", le_gd);
4088 :
4089 0 : convert_to_long_ex(SX);
4090 0 : convert_to_long_ex(SY);
4091 0 : convert_to_long_ex(SW);
4092 0 : convert_to_long_ex(SH);
4093 0 : convert_to_long_ex(DX);
4094 0 : convert_to_long_ex(DY);
4095 0 : convert_to_long_ex(PCT);
4096 :
4097 0 : srcX = Z_LVAL_PP(SX);
4098 0 : srcY = Z_LVAL_PP(SY);
4099 0 : srcH = Z_LVAL_PP(SH);
4100 0 : srcW = Z_LVAL_PP(SW);
4101 0 : dstX = Z_LVAL_PP(DX);
4102 0 : dstY = Z_LVAL_PP(DY);
4103 0 : pct = Z_LVAL_PP(PCT);
4104 :
4105 0 : gdImageCopyMergeGray(im_dst, im_src, dstX, dstY, srcX, srcY, srcW, srcH, pct);
4106 0 : RETURN_TRUE;
4107 : }
4108 : /* }}} */
4109 : #endif
4110 :
4111 : /* {{{ proto bool imagecopyresized(resource dst_im, resource src_im, int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h)
4112 : Copy and resize part of an image */
4113 : PHP_FUNCTION(imagecopyresized)
4114 4 : {
4115 : zval **SIM, **DIM, **SX, **SY, **SW, **SH, **DX, **DY, **DW, **DH;
4116 : gdImagePtr im_dst, im_src;
4117 : int srcH, srcW, dstH, dstW, srcY, srcX, dstY, dstX;
4118 :
4119 4 : if (ZEND_NUM_ARGS() != 10 || zend_get_parameters_ex(10, &DIM, &SIM, &DX, &DY, &SX, &SY, &DW, &DH, &SW, &SH) == FAILURE) {
4120 0 : ZEND_WRONG_PARAM_COUNT();
4121 : }
4122 :
4123 4 : ZEND_FETCH_RESOURCE(im_dst, gdImagePtr, DIM, -1, "Image", le_gd);
4124 4 : ZEND_FETCH_RESOURCE(im_src, gdImagePtr, SIM, -1, "Image", le_gd);
4125 :
4126 4 : convert_to_long_ex(SX);
4127 4 : convert_to_long_ex(SY);
4128 4 : convert_to_long_ex(SW);
4129 4 : convert_to_long_ex(SH);
4130 4 : convert_to_long_ex(DX);
4131 4 : convert_to_long_ex(DY);
4132 4 : convert_to_long_ex(DW);
4133 4 : convert_to_long_ex(DH);
4134 :
4135 4 : srcX = Z_LVAL_PP(SX);
4136 4 : srcY = Z_LVAL_PP(SY);
4137 4 : srcH = Z_LVAL_PP(SH);
4138 4 : srcW = Z_LVAL_PP(SW);
4139 4 : dstX = Z_LVAL_PP(DX);
4140 4 : dstY = Z_LVAL_PP(DY);
4141 4 : dstH = Z_LVAL_PP(DH);
4142 4 : dstW = Z_LVAL_PP(DW);
4143 :
4144 4 : if (dstW <= 0 || dstH <= 0 || srcW <= 0 || srcH <= 0) {
4145 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid image dimensions");
4146 0 : RETURN_FALSE;
4147 : }
4148 :
4149 4 : gdImageCopyResized(im_dst, im_src, dstX, dstY, srcX, srcY, dstW, dstH, srcW, srcH);
4150 4 : RETURN_TRUE;
4151 : }
4152 : /* }}} */
4153 :
4154 : /* {{{ proto int imagesx(resource im)
4155 : Get image width */
4156 : PHP_FUNCTION(imagesx)
4157 11 : {
4158 : zval **IM;
4159 : gdImagePtr im;
4160 :
4161 11 : if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &IM) == FAILURE) {
4162 0 : ZEND_WRONG_PARAM_COUNT();
4163 : }
4164 :
4165 11 : ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
4166 :
4167 11 : RETURN_LONG(gdImageSX(im));
4168 : }
4169 : /* }}} */
4170 :
4171 : /* {{{ proto int imagesy(resource im)
4172 : Get image height */
4173 : PHP_FUNCTION(imagesy)
4174 11 : {
4175 : zval **IM;
4176 : gdImagePtr im;
4177 :
4178 11 : if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &IM) == FAILURE) {
4179 0 : ZEND_WRONG_PARAM_COUNT();
4180 : }
4181 :
4182 11 : ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
4183 :
4184 11 : RETURN_LONG(gdImageSY(im));
4185 : }
4186 : /* }}} */
4187 :
4188 : #ifdef ENABLE_GD_TTF
4189 : #define TTFTEXT_DRAW 0
4190 : #define TTFTEXT_BBOX 1
4191 : #endif
4192 :
4193 : #ifdef ENABLE_GD_TTF
4194 :
4195 : #if HAVE_LIBGD20 && HAVE_LIBFREETYPE && HAVE_GD_STRINGFTEX
4196 : /* {{{ proto array imageftbbox(float size, float angle, string font_file, string text [, array extrainfo])
4197 : Give the bounding box of a text using fonts via freetype2 */
4198 : PHP_FUNCTION(imageftbbox)
4199 3 : {
4200 3 : php_imagettftext_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, TTFTEXT_BBOX, 1);
4201 3 : }
4202 : /* }}} */
4203 :
4204 : /* {{{ proto array imagefttext(resource im, float size, float angle, int x, int y, int col, string font_file, string text [, array extrainfo])
4205 : Write text to the image using fonts via freetype2 */
4206 : PHP_FUNCTION(imagefttext)
4207 2 : {
4208 2 : php_imagettftext_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, TTFTEXT_DRAW, 1);
4209 2 : }
4210 : /* }}} */
4211 : #endif
4212 :
4213 : /* {{{ proto array imagettfbbox(float size, float angle, string font_file, string text)
4214 : Give the bounding box of a text using TrueType fonts */
4215 : PHP_FUNCTION(imagettfbbox)
4216 0 : {
4217 0 : php_imagettftext_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, TTFTEXT_BBOX, 0);
4218 0 : }
4219 : /* }}} */
4220 :
4221 : /* {{{ proto array imagettftext(resource im, float size, float angle, int x, int y, int col, string font_file, string text)
4222 : Write text to the image using a TrueType font */
4223 : PHP_FUNCTION(imagettftext)
4224 17 : {
4225 17 : php_imagettftext_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, TTFTEXT_DRAW, 0);
4226 17 : }
4227 : /* }}} */
4228 :
4229 : /* {{{ php_imagettftext_common
4230 : */
4231 : static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int mode, int extended)
4232 22 : {
4233 22 : zval *IM, *EXT = NULL;
4234 22 : gdImagePtr im=NULL;
4235 22 : long col = -1, x = -1, y = -1;
4236 : int str_len, fontname_len, i, brect[8];
4237 : double ptsize, angle;
4238 22 : unsigned char *str = NULL, *fontname = NULL;
4239 22 : char *error = NULL;
4240 22 : int argc = ZEND_NUM_ARGS();
4241 : #if HAVE_GD_STRINGFTEX
4242 22 : gdFTStringExtra strex = {0};
4243 : #endif
4244 :
4245 : #if !HAVE_GD_STRINGFTEX
4246 : assert(!extended);
4247 : #endif
4248 :
4249 22 : if (mode == TTFTEXT_BBOX) {
4250 3 : if (argc < 4 || argc > ((extended) ? 5 : 4)) {
4251 0 : ZEND_WRONG_PARAM_COUNT();
4252 3 : } else if (zend_parse_parameters(argc TSRMLS_CC, "ddss|a", &ptsize, &angle, &fontname, &fontname_len, &str, &str_len, &EXT) == FAILURE) {
4253 0 : RETURN_FALSE;
4254 : }
4255 : } else {
4256 19 : if (argc < 8 || argc > ((extended) ? 9 : 8)) {
4257 0 : ZEND_WRONG_PARAM_COUNT();
4258 19 : } else if (zend_parse_parameters(argc TSRMLS_CC, "rddlllss|a", &IM, &ptsize, &angle, &x, &y, &col, &fontname, &fontname_len, &str, &str_len, &EXT) == FAILURE) {
4259 0 : RETURN_FALSE;
4260 : }
4261 19 : ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
4262 : }
4263 :
4264 : /* convert angle to radians */
4265 22 : angle = angle * (M_PI/180);
4266 :
4267 : #if HAVE_GD_STRINGFTEX
4268 22 : if (extended && EXT) { /* parse extended info */
4269 : HashPosition pos;
4270 :
4271 : /* walk the assoc array */
4272 2 : zend_hash_internal_pointer_reset_ex(HASH_OF(EXT), &pos);
4273 : do {
4274 : zval ** item;
4275 : char * key;
4276 : ulong num_key;
4277 :
4278 2 : if (zend_hash_get_current_key_ex(HASH_OF(EXT), &key, NULL, &num_key, 0, &pos) != HASH_KEY_IS_STRING) {
4279 2 : continue;
4280 : }
4281 :
4282 0 : if (zend_hash_get_current_data_ex(HASH_OF(EXT), (void **) &item, &pos) == FAILURE) {
4283 0 : continue;
4284 : }
4285 :
4286 0 : if (strcmp("linespacing", key) == 0) {
4287 0 : convert_to_double_ex(item);
4288 0 : strex.flags |= gdFTEX_LINESPACE;
4289 0 : strex.linespacing = Z_DVAL_PP(item);
4290 : }
4291 :
4292 2 : } while (zend_hash_move_forward_ex(HASH_OF(EXT), &pos) == SUCCESS);
4293 : }
4294 : #endif
4295 :
4296 : #ifdef VIRTUAL_DIR
4297 : {
4298 : char tmp_font_path[MAXPATHLEN];
4299 :
4300 : if (VCWD_REALPATH((char *)fontname, tmp_font_path)) {
4301 : fontname = (unsigned char *) fontname;
4302 : } else {
4303 : fontname = NULL;
4304 : }
4305 : }
4306 : #else
4307 22 : fontname = (unsigned char *) fontname;
4308 : #endif
4309 :
4310 22 : PHP_GD_CHECK_OPEN_BASEDIR((char *)fontname, "Invalid font filename");
4311 :
4312 : #ifdef USE_GD_IMGSTRTTF
4313 : # if HAVE_GD_STRINGFTEX
4314 22 : if (extended) {
4315 5 : error = gdImageStringFTEx(im, brect, col, (char *)fontname, ptsize, angle, x, y, (char *)str, &strex);
4316 : }
4317 : else
4318 : # endif
4319 :
4320 : # if HAVE_GD_STRINGFT
4321 17 : error = gdImageStringFT(im, brect, col, (char *)fontname, ptsize, angle, x, y, (char *)str);
4322 : # elif HAVE_GD_STRINGTTF
4323 : error = gdImageStringTTF(im, brect, col, fontname, ptsize, angle, x, y, str);
4324 : # endif
4325 :
4326 : #else /* !USE_GD_IMGSTRTTF */
4327 : error = gdttf(im, brect, col, fontname, ptsize, angle, x, y, str);
4328 : #endif
4329 :
4330 22 : if (error) {
4331 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", error);
4332 0 : RETURN_FALSE;
4333 : }
4334 :
4335 22 : array_init(return_value);
4336 :
4337 : /* return array with the text's bounding box */
4338 198 : for (i = 0; i < 8; i++) {
4339 176 : add_next_index_long(return_value, brect[i]);
4340 : }
4341 : }
4342 : /* }}} */
4343 : #endif /* ENABLE_GD_TTF */
4344 :
4345 : #if HAVE_LIBT1
4346 :
4347 : /* {{{ php_free_ps_font
4348 : */
4349 : static void php_free_ps_font(zend_rsrc_list_entry *rsrc TSRMLS_DC)
4350 : {
4351 : int *font = (int *) rsrc->ptr;
4352 :
4353 : T1_DeleteFont(*font);
4354 : efree(font);
4355 : }
4356 : /* }}} */
4357 :
4358 : /* {{{ php_free_ps_enc
4359 : */
4360 : static void php_free_ps_enc(zend_rsrc_list_entry *rsrc TSRMLS_DC)
4361 : {
4362 : char **enc = (char **) rsrc->ptr;
4363 :
4364 : T1_DeleteEncoding(enc);
4365 : }
4366 : /* }}} */
4367 :
4368 : /* {{{ proto resource imagepsloadfont(string pathname)
4369 : Load a new font from specified file */
4370 : PHP_FUNCTION(imagepsloadfont)
4371 : {
4372 : zval **file;
4373 : int f_ind, *font;
4374 : #ifdef PHP_WIN32
4375 : struct stat st;
4376 : #endif
4377 :
4378 : if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &file) == FAILURE) {
4379 : ZEND_WRONG_PARAM_COUNT();
4380 : }
4381 :
4382 : convert_to_string_ex(file);
4383 :
4384 : #ifdef PHP_WIN32
4385 : if (VCWD_STAT(Z_STRVAL_PP(file), &st) < 0) {
4386 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Font file not found (%s)", Z_STRVAL_PP(file));
4387 : RETURN_FALSE;
4388 : }
4389 : #endif
4390 :
4391 : f_ind = T1_AddFont(Z_STRVAL_PP(file));
4392 :
4393 : if (f_ind < 0) {
4394 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "T1Lib Error (%i): %s", f_ind, T1_StrError(f_ind));
4395 : RETURN_FALSE;
4396 : }
4397 :
4398 : if (T1_LoadFont(f_ind)) {
4399 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't load the font");
4400 : RETURN_FALSE;
4401 : }
4402 :
4403 : font = (int *) emalloc(sizeof(int));
4404 : *font = f_ind;
4405 : ZEND_REGISTER_RESOURCE(return_value, font, le_ps_font);
4406 : }
4407 : /* }}} */
4408 :
4409 : /* {{{ proto int imagepscopyfont(int font_index)
4410 : Make a copy of a font for purposes like extending or reenconding */
4411 : /* The function in t1lib which this function uses seem to be buggy...
4412 : PHP_FUNCTION(imagepscopyfont)
4413 : {
4414 : zval **fnt;
4415 : int l_ind, type;
4416 : gd_ps_font *nf_ind, *of_ind;
4417 :
4418 : if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &fnt) == FAILURE) {
4419 : ZEND_WRONG_PARAM_COUNT();
4420 : }
4421 :
4422 : convert_to_long_ex(fnt);
4423 :
4424 : of_ind = zend_list_find(Z_LVAL_PP(fnt), &type);
4425 :
4426 : if (type != le_ps_font) {
4427 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "%ld is not a Type 1 font index", Z_LVAL_PP(fnt));
4428 : RETURN_FALSE;
4429 : }
4430 :
4431 : nf_ind = emalloc(sizeof(gd_ps_font));
4432 : nf_ind->font_id = T1_CopyFont(of_ind->font_id);
4433 :
4434 : if (nf_ind->font_id < 0) {
4435 : l_ind = nf_ind->font_id;
4436 : efree(nf_ind);
4437 : switch (l_ind) {
4438 : case -1:
4439 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "FontID %d is not loaded in memory", l_ind);
4440 : RETURN_FALSE;
4441 : break;
4442 : case -2:
4443 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Tried to copy a logical font");
4444 : RETURN_FALSE;
4445 : break;
4446 : case -3:
4447 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Memory allocation fault in t1lib");
4448 : RETURN_FALSE;
4449 : break;
4450 : default:
4451 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "An unknown error occurred in t1lib");
4452 : RETURN_FALSE;
4453 : break;
4454 : }
4455 : }
4456 :
4457 : nf_ind->extend = 1;
4458 : l_ind = zend_list_insert(nf_ind, le_ps_font);
4459 : RETURN_LONG(l_ind);
4460 : }
4461 : */
4462 : /* }}} */
4463 :
4464 : /* {{{ proto bool imagepsfreefont(resource font_index)
4465 : Free memory used by a font */
4466 : PHP_FUNCTION(imagepsfreefont)
4467 : {
4468 : zval **fnt;
4469 : int *f_ind;
4470 :
4471 : if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &fnt) == FAILURE) {
4472 : ZEND_WRONG_PARAM_COUNT();
4473 : }
4474 :
4475 : ZEND_FETCH_RESOURCE(f_ind, int *, fnt, -1, "Type 1 font", le_ps_font);
4476 :
4477 : zend_list_delete(Z_LVAL_PP(fnt));
4478 : RETURN_TRUE;
4479 : }
4480 : /* }}} */
4481 :
4482 : /* {{{ proto bool imagepsencodefont(resource font_index, string filename)
4483 : To change a fonts character encoding vector */
4484 : PHP_FUNCTION(imagepsencodefont)
4485 : {
4486 : zval **fnt, **enc;
4487 : char **enc_vector;
4488 : int *f_ind;
4489 :
4490 : if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &fnt, &enc) == FAILURE) {
4491 : ZEND_WRONG_PARAM_COUNT();
4492 : }
4493 :
4494 : convert_to_string_ex(enc);
4495 :
4496 : ZEND_FETCH_RESOURCE(f_ind, int *, fnt, -1, "Type 1 font", le_ps_font);
4497 :
4498 : if ((enc_vector = T1_LoadEncoding(Z_STRVAL_PP(enc))) == NULL) {
4499 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't load encoding vector from %s", Z_STRVAL_PP(enc));
4500 : RETURN_FALSE;
4501 : }
4502 :
4503 : T1_DeleteAllSizes(*f_ind);
4504 : if (T1_ReencodeFont(*f_ind, enc_vector)) {
4505 : T1_DeleteEncoding(enc_vector);
4506 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't reencode font");
4507 : RETURN_FALSE;
4508 : }
4509 :
4510 : zend_list_insert(enc_vector, le_ps_enc);
4511 :
4512 : RETURN_TRUE;
4513 : }
4514 : /* }}} */
4515 :
4516 : /* {{{ proto bool imagepsextendfont(resource font_index, float extend)
4517 : Extend or or condense (if extend < 1) a font */
4518 : PHP_FUNCTION(imagepsextendfont)
4519 : {
4520 : zval **fnt, **ext;
4521 : int *f_ind;
4522 :
4523 : if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &fnt, &ext) == FAILURE) {
4524 : ZEND_WRONG_PARAM_COUNT();
4525 : }
4526 :
4527 : convert_to_double_ex(ext);
4528 :
4529 : ZEND_FETCH_RESOURCE(f_ind, int *, fnt, -1, "Type 1 font", le_ps_font);
4530 :
4531 : T1_DeleteAllSizes(*f_ind);
4532 :
4533 : if (Z_DVAL_PP(ext) <= 0) {
4534 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Second parameter %F out of range (must be > 0)", Z_DVAL_PP(ext));
4535 : RETURN_FALSE;
4536 : }
4537 :
4538 : if (T1_ExtendFont(*f_ind, Z_DVAL_PP(ext)) != 0) {
4539 : RETURN_FALSE;
4540 : }
4541 :
4542 : RETURN_TRUE;
4543 : }
4544 : /* }}} */
4545 :
4546 : /* {{{ proto bool imagepsslantfont(resource font_index, float slant)
4547 : Slant a font */
4548 : PHP_FUNCTION(imagepsslantfont)
4549 : {
4550 : zval **fnt, **slt;
4551 : int *f_ind;
4552 :
4553 : if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &fnt, &slt) == FAILURE) {
4554 : ZEND_WRONG_PARAM_COUNT();
4555 : }
4556 :
4557 : convert_to_double_ex(slt);
4558 :
4559 : ZEND_FETCH_RESOURCE(f_ind, int *, fnt, -1, "Type 1 font", le_ps_font);
4560 :
4561 : if (T1_SlantFont(*f_ind, Z_DVAL_PP(slt)) != 0) {
4562 : RETURN_FALSE;
4563 : }
4564 :
4565 : RETURN_TRUE;
4566 : }
4567 : /* }}} */
4568 :
4569 : /* {{{ proto array imagepstext(resource image, string text, resource font, int size, int foreground, int background, int xcoord, int ycoord [, int space [, int tightness [, float angle [, int antialias]]]])
4570 : Rasterize a string over an image */
4571 : PHP_FUNCTION(imagepstext)
4572 : {
4573 : zval *img, *fnt;
4574 : int i, j;
4575 : long _fg, _bg, x, y, size, space = 0, aa_steps = 4, width = 0;
4576 : int *f_ind;
4577 : int h_lines, v_lines, c_ind;
4578 : int rd, gr, bl, fg_rd, fg_gr, fg_bl, bg_rd, bg_gr, bg_bl;
4579 : #if HAVE_LIBGD20
4580 : int fg_al, bg_al, al;
4581 : #endif
4582 : int aa[16];
4583 : int amount_kern, add_width;
4584 : double angle = 0.0, extend;
4585 : unsigned long aa_greys[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
4586 : gdImagePtr bg_img;
4587 : GLYPH *str_img;
4588 : T1_OUTLINE *char_path, *str_path;
4589 : T1_TMATRIX *transform = NULL;
4590 : char *str;
4591 : int str_len;
4592 :
4593 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsrlllll|lldl", &img, &str, &str_len, &fnt, &size, &_fg, &_bg, &x, &y, &space, &width, &angle, &aa_steps) == FAILURE) {
4594 : return;
4595 : }
4596 :
4597 : ZEND_FETCH_RESOURCE(bg_img, gdImagePtr, &img, -1, "Image", le_gd);
4598 : ZEND_FETCH_RESOURCE(f_ind, int *, &fnt, -1, "Type 1 font", le_ps_font);
4599 :
4600 : /* Ensure that the provided colors are valid */
4601 : #if HAVE_LIBGD20
4602 : if (_fg < 0 || (!gdImageTrueColor(bg_img) && _fg > gdImageColorsTotal(bg_img))) {
4603 : #else
4604 : if (_fg < 0 || _fg > gdImageColorsTotal(bg_img)) {
4605 : #endif
4606 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Foreground color index %ld out of range", _fg);
4607 : RETURN_FALSE;
4608 : }
4609 :
4610 : #if HAVE_LIBGD20
4611 : if (_bg < 0 || (!gdImageTrueColor(bg_img) && _fg > gdImageColorsTotal(bg_img))) {
4612 : #else
4613 : if (_bg < 0 || _bg > gdImageColorsTotal(bg_img)) {
4614 : #endif
4615 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Background color index %ld out of range", _bg);
4616 : RETURN_FALSE;
4617 : }
4618 :
4619 : fg_rd = gdImageRed (bg_img, _fg);
4620 : fg_gr = gdImageGreen(bg_img, _fg);
4621 : fg_bl = gdImageBlue (bg_img, _fg);
4622 : #if HAVE_LIBGD20
4623 : fg_al = gdImageAlpha(bg_img, _fg);
4624 : #endif
4625 :
4626 : bg_rd = gdImageRed (bg_img, _bg);
4627 : bg_gr = gdImageGreen(bg_img, _bg);
4628 : bg_bl = gdImageBlue (bg_img, _bg);
4629 : #if HAVE_LIBGD20
4630 : bg_al = gdImageAlpha(bg_img, _bg);
4631 : #endif
4632 :
4633 : for (i = 0; i < aa_steps; i++) {
4634 : rd = bg_rd + (double) (fg_rd - bg_rd) / aa_steps * (i + 1);
4635 : gr = bg_gr + (double) (fg_gr - bg_gr) / aa_steps * (i + 1);
4636 : bl = bg_bl + (double) (fg_bl - bg_bl) / aa_steps * (i + 1);
4637 : #if HAVE_LIBGD20
4638 : al = bg_al + (double) (fg_al - bg_al) / aa_steps * (i + 1);
4639 : aa[i] = gdImageColorResolveAlpha(bg_img, rd, gr, bl, al);
4640 : #else
4641 : aa[i] = gdImageColorResolve(bg_img, rd, gr, bl);
4642 : #endif
4643 : }
4644 :
4645 : T1_AASetBitsPerPixel(8);
4646 :
4647 : switch (aa_steps) {
4648 : case 4:
4649 : T1_AASetGrayValues(0, 1, 2, 3, 4);
4650 : T1_AASetLevel(T1_AA_LOW);
4651 : break;
4652 : case 16:
4653 : T1_AAHSetGrayValues(aa_greys);
4654 : T1_AASetLevel(T1_AA_HIGH);
4655 : break;
4656 : default:
4657 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid value %ld as number of steps for antialiasing", aa_steps);
4658 : RETURN_FALSE;
4659 : }
4660 :
4661 : if (angle) {
4662 : transform = T1_RotateMatrix(NULL, angle);
4663 : }
4664 :
4665 : if (width) {
4666 : extend = T1_GetExtend(*f_ind);
4667 : str_path = T1_GetCharOutline(*f_ind, str[0], size, transform);
4668 :
4669 : if (!str_path) {
4670 : if (T1_errno) {
4671 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "T1Lib Error: %s", T1_StrError(T1_errno));
4672 : }
4673 : RETURN_FALSE;
4674 : }
4675 :
4676 : for (i = 1; i < str_len; i++) {
4677 : amount_kern = (int) T1_GetKerning(*f_ind, str[i - 1], str[i]);
4678 : amount_kern += str[i - 1] == ' ' ? space : 0;
4679 : add_width = (int) (amount_kern + width) / extend;
4680 :
4681 : char_path = T1_GetMoveOutline(*f_ind, add_width, 0, 0, size, transform);
4682 : str_path = T1_ConcatOutlines(str_path, char_path);
4683 :
4684 : char_path = T1_GetCharOutline(*f_ind, str[i], size, transform);
4685 : str_path = T1_ConcatOutlines(str_path, char_path);
4686 : }
4687 : str_img = T1_AAFillOutline(str_path, 0);
4688 : } else {
4689 : str_img = T1_AASetString(*f_ind, str, str_len, space, T1_KERNING, size, transform);
4690 : }
4691 : if (T1_errno) {
4692 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "T1Lib Error: %s", T1_StrError(T1_errno));
4693 : RETURN_FALSE;
4694 : }
4695 :
4696 : h_lines = str_img->metrics.ascent - str_img->metrics.descent;
4697 : v_lines = str_img->metrics.rightSideBearing - str_img->metrics.leftSideBearing;
4698 :
4699 : for (i = 0; i < v_lines; i++) {
4700 : for (j = 0; j < h_lines; j++) {
4701 : switch (str_img->bits[j * v_lines + i]) {
4702 : case 0:
4703 : break;
4704 : default:
4705 : c_ind = aa[str_img->bits[j * v_lines + i] - 1];
4706 : gdImageSetPixel(bg_img, x + str_img->metrics.leftSideBearing + i, y - str_img->metrics.ascent + j, c_ind);
4707 : break;
4708 : }
4709 : }
4710 : }
4711 :
4712 : array_init(return_value);
4713 :
4714 : add_next_index_long(return_value, str_img->metrics.leftSideBearing);
4715 : add_next_index_long(return_value, str_img->metrics.descent);
4716 : add_next_index_long(return_value, str_img->metrics.rightSideBearing);
4717 : add_next_index_long(return_value, str_img->metrics.ascent);
4718 : }
4719 : /* }}} */
4720 :
4721 : /* {{{ proto array imagepsbbox(string text, resource font, int size [, int space, int tightness, int angle])
4722 : Return the bounding box needed by a string if rasterized */
4723 : PHP_FUNCTION(imagepsbbox)
4724 : {
4725 : zval **str, **fnt, **sz, **sp, **wd, **ang;
4726 : int i, space, add_width = 0, char_width, amount_kern;
4727 : int cur_x, cur_y, dx, dy;
4728 : int x1, y1, x2, y2, x3, y3, x4, y4;
4729 : int *f_ind;
4730 : int per_char = 0;
4731 : double angle, sin_a = 0, cos_a = 0;
4732 : BBox char_bbox, str_bbox = {0, 0, 0, 0};
4733 :
4734 : switch (ZEND_NUM_ARGS()) {
4735 : case 3:
4736 : if (zend_get_parameters_ex(3, &str, &fnt, &sz) == FAILURE) {
4737 : RETURN_FALSE;
4738 : }
4739 : space = 0;
4740 : break;
4741 : case 6:
4742 : if (zend_get_parameters_ex(6, &str, &fnt, &sz, &sp, &wd, &ang) == FAILURE) {
4743 : RETURN_FALSE;
4744 : }
4745 : convert_to_long_ex(sp);
4746 : convert_to_long_ex(wd);
4747 : convert_to_double_ex(ang);
4748 : space = Z_LVAL_PP(sp);
4749 : add_width = Z_LVAL_PP(wd);
4750 : angle = Z_DVAL_PP(ang) * M_PI / 180;
4751 : sin_a = sin(angle);
4752 : cos_a = cos(angle);
4753 : per_char = add_width || angle ? 1 : 0;
4754 : break;
4755 : default:
4756 : ZEND_WRONG_PARAM_COUNT();
4757 : }
4758 :
4759 : ZEND_FETCH_RESOURCE(f_ind, int *, fnt, -1, "Type 1 font", le_ps_font);
4760 :
4761 : convert_to_string_ex(str);
4762 : convert_to_long_ex(sz);
4763 :
4764 : #define max(a, b) (a > b ? a : b)
4765 : #define min(a, b) (a < b ? a : b)
4766 : #define new_x(a, b) (int) ((a) * cos_a - (b) * sin_a)
4767 : #define new_y(a, b) (int) ((a) * sin_a + (b) * cos_a)
4768 :
4769 : if (per_char) {
4770 : space += T1_GetCharWidth(*f_ind, ' ');
4771 : cur_x = cur_y = 0;
4772 :
4773 : for (i = 0; i < Z_STRLEN_PP(str); i++) {
4774 : if (Z_STRVAL_PP(str)[i] == ' ') {
4775 : char_bbox.llx = char_bbox.lly = char_bbox.ury = 0;
4776 : char_bbox.urx = char_width = space;
4777 : } else {
4778 : char_bbox = T1_GetCharBBox(*f_ind, Z_STRVAL_PP(str)[i]);
4779 : char_width = T1_GetCharWidth(*f_ind, Z_STRVAL_PP(str)[i]);
4780 : }
4781 : amount_kern = i ? T1_GetKerning(*f_ind, Z_STRVAL_PP(str)[i - 1], Z_STRVAL_PP(str)[i]) : 0;
4782 :
4783 : /* Transfer character bounding box to right place */
4784 : x1 = new_x(char_bbox.llx, char_bbox.lly) + cur_x;
4785 : y1 = new_y(char_bbox.llx, char_bbox.lly) + cur_y;
4786 : x2 = new_x(char_bbox.llx, char_bbox.ury) + cur_x;
4787 : y2 = new_y(char_bbox.llx, char_bbox.ury) + cur_y;
4788 : x3 = new_x(char_bbox.urx, char_bbox.ury) + cur_x;
4789 : y3 = new_y(char_bbox.urx, char_bbox.ury) + cur_y;
4790 : x4 = new_x(char_bbox.urx, char_bbox.lly) + cur_x;
4791 : y4 = new_y(char_bbox.urx, char_bbox.lly) + cur_y;
4792 :
4793 : /* Find min & max values and compare them with current bounding box */
4794 : str_bbox.llx = min(str_bbox.llx, min(x1, min(x2, min(x3, x4))));
4795 : str_bbox.lly = min(str_bbox.lly, min(y1, min(y2, min(y3, y4))));
4796 : str_bbox.urx = max(str_bbox.urx, max(x1, max(x2, max(x3, x4))));
4797 : str_bbox.ury = max(str_bbox.ury, max(y1, max(y2, max(y3, y4))));
4798 :
4799 : /* Move to the next base point */
4800 : dx = new_x(char_width + add_width + amount_kern, 0);
4801 : dy = new_y(char_width + add_width + amount_kern, 0);
4802 : cur_x += dx;
4803 : cur_y += dy;
4804 : /*
4805 : printf("%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n", x1, y1, x2, y2, x3, y3, x4, y4, char_bbox.llx, char_bbox.lly, char_bbox.urx, char_bbox.ury, char_width, amount_kern, cur_x, cur_y, dx, dy);
4806 : */
4807 : }
4808 :
4809 : } else {
4810 : str_bbox = T1_GetStringBBox(*f_ind, Z_STRVAL_PP(str), Z_STRLEN_PP(str), space, T1_KERNING);
4811 : }
4812 :
4813 : if (T1_errno) {
4814 : RETURN_FALSE;
4815 : }
4816 :
4817 : array_init(return_value);
4818 : /*
4819 : printf("%d %d %d %d\n", str_bbox.llx, str_bbox.lly, str_bbox.urx, str_bbox.ury);
4820 : */
4821 : add_next_index_long(return_value, (int) ceil(((double) str_bbox.llx)*Z_LVAL_PP(sz)/1000));
4822 : add_next_index_long(return_value, (int) ceil(((double) str_bbox.lly)*Z_LVAL_PP(sz)/1000));
4823 : add_next_index_long(return_value, (int) ceil(((double) str_bbox.urx)*Z_LVAL_PP(sz)/1000));
4824 : add_next_index_long(return_value, (int) ceil(((double) str_bbox.ury)*Z_LVAL_PP(sz)/1000));
4825 : }
4826 : /* }}} */
4827 : #endif
4828 :
4829 : #ifdef HAVE_GD_WBMP
4830 : /* {{{ proto bool image2wbmp(resource im [, string filename [, int threshold]])
4831 : Output WBMP image to browser or file */
4832 : PHP_FUNCTION(image2wbmp)
4833 0 : {
4834 0 : _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_CONVERT_WBM, "WBMP", _php_image_bw_convert);
4835 0 : }
4836 : /* }}} */
4837 : #endif /* HAVE_GD_WBMP */
4838 :
4839 : #if defined(HAVE_GD_JPG) && defined(HAVE_GD_WBMP)
4840 : /* {{{ proto bool jpeg2wbmp (string f_org, string f_dest, int d_height, int d_width, int threshold)
4841 : Convert JPEG image to WBMP image */
4842 : PHP_FUNCTION(jpeg2wbmp)
4843 8 : {
4844 8 : _php_image_convert(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_JPG);
4845 8 : }
4846 : /* }}} */
4847 : #endif
4848 :
4849 : #if defined(HAVE_GD_PNG) && defined(HAVE_GD_WBMP)
4850 : /* {{{ proto bool png2wbmp (string f_org, string f_dest, int d_height, int d_width, int threshold)
4851 : Convert PNG image to WBMP image */
4852 : PHP_FUNCTION(png2wbmp)
4853 8 : {
4854 8 : _php_image_convert(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_PNG);
4855 8 : }
4856 : /* }}} */
4857 : #endif
4858 :
4859 : #ifdef HAVE_GD_WBMP
4860 : /* {{{ _php_image_bw_convert
4861 : * It converts a gd Image to bw using a threshold value */
4862 : static void _php_image_bw_convert(gdImagePtr im_org, gdIOCtx *out, int threshold)
4863 0 : {
4864 : gdImagePtr im_dest;
4865 : int white, black;
4866 : int color, color_org, median;
4867 0 : int dest_height = gdImageSY(im_org);
4868 0 : int dest_width = gdImageSX(im_org);
4869 : int x, y;
4870 : TSRMLS_FETCH();
4871 :
4872 0 : im_dest = gdImageCreate(dest_width, dest_height);
4873 0 : if (im_dest == NULL) {
4874 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to allocate temporary buffer");
4875 0 : return;
4876 : }
4877 :
4878 0 : white = gdImageColorAllocate(im_dest, 255, 255, 255);
4879 0 : if (white == -1) {
4880 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to allocate the colors for the destination buffer");
4881 0 : return;
4882 : }
4883 :
4884 0 : black = gdImageColorAllocate(im_dest, 0, 0, 0);
4885 0 : if (black == -1) {
4886 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to allocate the colors for the destination buffer");
4887 0 : return;
4888 : }
4889 :
4890 : #if HAVE_LIBGD20
4891 0 : if (im_org->trueColor) {
4892 0 : gdImageTrueColorToPalette(im_org, 1, 256);
4893 : }
4894 : #endif
4895 :
4896 0 : for (y = 0; y < dest_height; y++) {
4897 0 : for (x = 0; x < dest_width; x++) {
4898 0 : color_org = gdImageGetPixel(im_org, x, y);
4899 0 : median = (im_org->red[color_org] + im_org->green[color_org] + im_org->blue[color_org]) / 3;
4900 0 : if (median < threshold) {
4901 0 : color = black;
4902 : } else {
4903 0 : color = white;
4904 : }
4905 0 : gdImageSetPixel (im_dest, x, y, color);
4906 : }
4907 : }
4908 : #ifdef USE_GD_IOCTX
4909 0 : gdImageWBMPCtx (im_dest, black, out);
4910 : #else
4911 : gdImageWBMP (im_dest, black, out);
4912 : #endif
4913 :
4914 : }
4915 : /* }}} */
4916 :
4917 : /* {{{ _php_image_convert
4918 : * _php_image_convert converts jpeg/png images to wbmp and resizes them as needed */
4919 : static void _php_image_convert(INTERNAL_FUNCTION_PARAMETERS, int image_type )
4920 16 : {
4921 : zval **f_org, **f_dest, **height, **width, **threshold;
4922 : gdImagePtr im_org, im_dest, im_tmp;
4923 16 : char *fn_org = NULL;
4924 16 : char *fn_dest = NULL;
4925 : FILE *org, *dest;
4926 16 : int argc = ZEND_NUM_ARGS();
4927 16 : int dest_height = -1;
4928 16 : int dest_width = -1;
4929 : int org_height, org_width;
4930 : int white, black;
4931 : int color, color_org, median;
4932 : int int_threshold;
4933 : int x, y;
4934 : float x_ratio, y_ratio;
4935 : #ifdef HAVE_GD_JPG
4936 : long ignore_warning;
4937 : #endif
4938 :
4939 16 : if (argc != 5 || zend_get_parameters_ex(argc, &f_org, &f_dest, &height, &width, &threshold) == FAILURE) {
4940 0 : ZEND_WRONG_PARAM_COUNT();
4941 : }
4942 :
4943 16 : convert_to_string_ex(f_org);
4944 16 : convert_to_string_ex(f_dest);
4945 16 : convert_to_long_ex(height);
4946 16 : convert_to_long_ex(width);
4947 16 : convert_to_long_ex(threshold);
4948 :
4949 16 : fn_org = Z_STRVAL_PP(f_org);
4950 16 : fn_dest = Z_STRVAL_PP(f_dest);
4951 16 : dest_height = Z_LVAL_PP(height);
4952 16 : dest_width = Z_LVAL_PP(width);
4953 16 : int_threshold = Z_LVAL_PP(threshold);
4954 :
4955 : /* Check threshold value */
4956 16 : if (int_threshold < 0 || int_threshold > 8) {
4957 4 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid threshold value '%d'", int_threshold);
4958 4 : RETURN_FALSE;
4959 : }
4960 :
4961 : /* Check origin file */
4962 12 : PHP_GD_CHECK_OPEN_BASEDIR(fn_org, "Invalid origin filename");
4963 :
4964 : /* Check destination file */
4965 12 : PHP_GD_CHECK_OPEN_BASEDIR(fn_dest, "Invalid destination filename");
4966 :
4967 : /* Open origin file */
4968 12 : org = VCWD_FOPEN(fn_org, "rb");
4969 12 : if (!org) {
4970 6 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open '%s' for reading", fn_org);
4971 6 : RETURN_FALSE;
4972 : }
4973 :
4974 : /* Open destination file */
4975 6 : dest = VCWD_FOPEN(fn_dest, "wb");
4976 6 : if (!dest) {
4977 6 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open '%s' for writing", fn_dest);
4978 6 : RETURN_FALSE;
4979 : }
4980 :
4981 0 : switch (image_type) {
4982 : #ifdef HAVE_GD_GIF_READ
4983 : case PHP_GDIMG_TYPE_GIF:
4984 0 : im_org = gdImageCreateFromGif(org);
4985 0 : if (im_org == NULL) {
4986 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open '%s' Not a valid GIF file", fn_dest);
4987 0 : RETURN_FALSE;
4988 : }
4989 0 : break;
4990 : #endif /* HAVE_GD_GIF_READ */
4991 :
4992 : #ifdef HAVE_GD_JPG
4993 : case PHP_GDIMG_TYPE_JPG:
4994 0 : ignore_warning = INI_INT("gd.jpeg_ignore_warning");
4995 : #ifdef HAVE_GD_BUNDLED
4996 0 : im_org = gdImageCreateFromJpeg(org, ignore_warning);
4997 : #else
4998 : im_org = gdImageCreateFromJpeg(org);
4999 : #endif
5000 0 : if (im_org == NULL) {
5001 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open '%s' Not a valid JPEG file", fn_dest);
5002 0 : RETURN_FALSE;
5003 : }
5004 0 : break;
5005 : #endif /* HAVE_GD_JPG */
5006 :
5007 :
5008 : #ifdef HAVE_GD_PNG
5009 : case PHP_GDIMG_TYPE_PNG:
5010 0 : im_org = gdImageCreateFromPng(org);
5011 0 : if (im_org == NULL) {
5012 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open '%s' Not a valid PNG file", fn_dest);
5013 0 : RETURN_FALSE;
5014 : }
5015 0 : break;
5016 : #endif /* HAVE_GD_PNG */
5017 :
5018 : default:
5019 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Format not supported");
5020 0 : RETURN_FALSE;
5021 : break;
5022 : }
5023 :
5024 0 : org_width = gdImageSX (im_org);
5025 0 : org_height = gdImageSY (im_org);
5026 :
5027 0 : x_ratio = (float) org_width / (float) dest_width;
5028 0 : y_ratio = (float) org_height / (float) dest_height;
5029 :
5030 0 : if (x_ratio > 1 && y_ratio > 1) {
5031 0 : if (y_ratio > x_ratio) {
5032 0 : x_ratio = y_ratio;
5033 : } else {
5034 0 : y_ratio = x_ratio;
5035 : }
5036 0 : dest_width = (int) (org_width / x_ratio);
5037 0 : dest_height = (int) (org_height / y_ratio);
5038 : } else {
5039 0 : x_ratio = (float) dest_width / (float) org_width;
5040 0 : y_ratio = (float) dest_height / (float) org_height;
5041 :
5042 0 : if (y_ratio < x_ratio) {
5043 0 : x_ratio = y_ratio;
5044 : } else {
5045 0 : y_ratio = x_ratio;
5046 : }
5047 0 : dest_width = (int) (org_width * x_ratio);
5048 0 : dest_height = (int) (org_height * y_ratio);
5049 : }
5050 :
5051 0 : im_tmp = gdImageCreate (dest_width, dest_height);
5052 0 : if (im_tmp == NULL ) {
5053 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to allocate temporary buffer");
5054 0 : RETURN_FALSE;
5055 : }
5056 :
5057 0 : gdImageCopyResized (im_tmp, im_org, 0, 0, 0, 0, dest_width, dest_height, org_width, org_height);
5058 :
5059 0 : gdImageDestroy(im_org);
5060 :
5061 0 : fclose(org);
5062 :
5063 0 : im_dest = gdImageCreate(dest_width, dest_height);
5064 0 : if (im_dest == NULL) {
5065 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to allocate destination buffer");
5066 0 : RETURN_FALSE;
5067 : }
5068 :
5069 0 : white = gdImageColorAllocate(im_dest, 255, 255, 255);
5070 0 : if (white == -1) {
5071 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to allocate the colors for the destination buffer");
5072 0 : RETURN_FALSE;
5073 : }
5074 :
5075 0 : black = gdImageColorAllocate(im_dest, 0, 0, 0);
5076 0 : if (black == -1) {
5077 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to allocate the colors for the destination buffer");
5078 0 : RETURN_FALSE;
5079 : }
5080 :
5081 0 : int_threshold = int_threshold * 32;
5082 :
5083 0 : for (y = 0; y < dest_height; y++) {
5084 0 : for (x = 0; x < dest_width; x++) {
5085 0 : color_org = gdImageGetPixel (im_tmp, x, y);
5086 0 : median = (im_tmp->red[color_org] + im_tmp->green[color_org] + im_tmp->blue[color_org]) / 3;
5087 0 : if (median < int_threshold) {
5088 0 : color = black;
5089 : } else {
5090 0 : color = white;
5091 : }
5092 0 : gdImageSetPixel (im_dest, x, y, color);
5093 : }
5094 : }
5095 :
5096 0 : gdImageDestroy (im_tmp );
5097 :
5098 0 : gdImageWBMP(im_dest, black , dest);
5099 :
5100 0 : fflush(dest);
5101 0 : fclose(dest);
5102 :
5103 0 : gdImageDestroy(im_dest);
5104 :
5105 0 : RETURN_TRUE;
5106 : }
5107 : /* }}} */
5108 : #endif /* HAVE_GD_WBMP */
5109 :
5110 : #endif /* HAVE_LIBGD */
5111 :
5112 : /* Section Filters */
5113 : #ifdef HAVE_GD_BUNDLED
5114 :
5115 : #define PHP_GD_SINGLE_RES \
5116 : zval **SIM; \
5117 : gdImagePtr im_src; \
5118 : if (zend_get_parameters_ex(1, &SIM) == FAILURE) { \
5119 : RETURN_FALSE; \
5120 : } \
5121 : ZEND_FETCH_RESOURCE(im_src, gdImagePtr, SIM, -1, "Image", le_gd); \
5122 : if (im_src == NULL) { \
5123 : RETURN_FALSE; \
5124 : }
5125 :
5126 : static void php_image_filter_negate(INTERNAL_FUNCTION_PARAMETERS)
5127 2 : {
5128 2 : PHP_GD_SINGLE_RES
5129 :
5130 1 : if (gdImageNegate(im_src) == 1) {
5131 1 : RETURN_TRUE;
5132 : }
5133 :
5134 0 : RETURN_FALSE;
5135 : }
5136 :
5137 : static void php_image_filter_grayscale(INTERNAL_FUNCTION_PARAMETERS)
5138 2 : {
5139 2 : PHP_GD_SINGLE_RES
5140 :
5141 1 : if (gdImageGrayScale(im_src) == 1) {
5142 1 : RETURN_TRUE;
5143 : }
5144 :
5145 0 : RETURN_FALSE;
5146 : }
5147 :
5148 : static void php_image_filter_brightness(INTERNAL_FUNCTION_PARAMETERS)
5149 3 : {
5150 : zval *SIM;
5151 : gdImagePtr im_src;
5152 : long brightness, tmp;
5153 :
5154 3 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zll", &SIM, &tmp, &brightness) == FAILURE) {
5155 1 : RETURN_FALSE;
5156 : }
5157 :
5158 2 : ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
5159 :
5160 1 : if (im_src == NULL) {
5161 0 : RETURN_FALSE;
5162 : }
5163 :
5164 1 : if (gdImageBrightness(im_src, (int)brightness) == 1) {
5165 1 : RETURN_TRUE;
5166 : }
5167 :
5168 0 : RETURN_FALSE;
5169 : }
5170 :
5171 : static void php_image_filter_contrast(INTERNAL_FUNCTION_PARAMETERS)
5172 3 : {
5173 : zval *SIM;
5174 : gdImagePtr im_src;
5175 : long contrast, tmp;
5176 :
5177 3 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &SIM, &tmp, &contrast) == FAILURE) {
5178 1 : RETURN_FALSE;
5179 : }
5180 :
5181 2 : ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
5182 :
5183 1 : if (im_src == NULL) {
5184 0 : RETURN_FALSE;
5185 : }
5186 :
5187 1 : if (gdImageContrast(im_src, (int)contrast) == 1) {
5188 1 : RETURN_TRUE;
5189 : }
5190 :
5191 0 : RETURN_FALSE;
5192 : }
5193 :
5194 : static void php_image_filter_colorize(INTERNAL_FUNCTION_PARAMETERS)
5195 4 : {
5196 : zval *SIM;
5197 : gdImagePtr im_src;
5198 : long r,g,b,tmp;
5199 4 : long a = 0;
5200 :
5201 4 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll|l", &SIM, &tmp, &r, &g, &b, &a) == FAILURE) {
5202 1 : RETURN_FALSE;
5203 : }
5204 :
5205 3 : ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
5206 :
5207 2 : if (im_src == NULL) {
5208 0 : RETURN_FALSE;
5209 : }
5210 :
5211 2 : if (gdImageColor(im_src, (int) r, (int) g, (int) b, (int) a) == 1) {
5212 2 : RETURN_TRUE;
5213 : }
5214 :
5215 0 : RETURN_FALSE;
5216 : }
5217 :
5218 : static void php_image_filter_edgedetect(INTERNAL_FUNCTION_PARAMETERS)
5219 2 : {
5220 2 : PHP_GD_SINGLE_RES
5221 :
5222 1 : if (gdImageEdgeDetectQuick(im_src) == 1) {
5223 1 : RETURN_TRUE;
5224 : }
5225 :
5226 0 : RETURN_FALSE;
5227 : }
5228 :
5229 : static void php_image_filter_emboss(INTERNAL_FUNCTION_PARAMETERS)
5230 2 : {
5231 2 : PHP_GD_SINGLE_RES
5232 :
5233 1 : if (gdImageEmboss(im_src) == 1) {
5234 1 : RETURN_TRUE;
5235 : }
5236 :
5237 0 : RETURN_FALSE;
5238 : }
5239 :
5240 : static void php_image_filter_gaussian_blur(INTERNAL_FUNCTION_PARAMETERS)
5241 2 : {
5242 2 : PHP_GD_SINGLE_RES
5243 :
5244 1 : if (gdImageGaussianBlur(im_src) == 1) {
5245 1 : RETURN_TRUE;
5246 : }
5247 :
5248 0 : RETURN_FALSE;
5249 : }
5250 :
5251 : static void php_image_filter_selective_blur(INTERNAL_FUNCTION_PARAMETERS)
5252 2 : {
5253 2 : PHP_GD_SINGLE_RES
5254 :
5255 1 : if (gdImageSelectiveBlur(im_src) == 1) {
5256 1 : RETURN_TRUE;
5257 : }
5258 :
5259 0 : RETURN_FALSE;
5260 : }
5261 :
5262 : static void php_image_filter_mean_removal(INTERNAL_FUNCTION_PARAMETERS)
5263 2 : {
5264 2 : PHP_GD_SINGLE_RES
5265 :
5266 1 : if (gdImageMeanRemoval(im_src) == 1) {
5267 1 : RETURN_TRUE;
5268 : }
5269 :
5270 0 : RETURN_FALSE;
5271 : }
5272 :
5273 : static void php_image_filter_smooth(INTERNAL_FUNCTION_PARAMETERS)
5274 3 : {
5275 : zval *SIM;
5276 : long tmp;
5277 : gdImagePtr im_src;
5278 : double weight;
5279 :
5280 3 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rld", &SIM, &tmp, &weight) == FAILURE) {
5281 1 : RETURN_FALSE;
5282 : }
5283 :
5284 2 : ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
5285 :
5286 1 : if (im_src == NULL) {
5287 0 : RETURN_FALSE;
5288 : }
5289 :
5290 1 : if (gdImageSmooth(im_src, (float)weight)==1) {
5291 1 : RETURN_TRUE;
5292 : }
5293 :
5294 0 : RETURN_FALSE;
5295 : }
5296 :
5297 : /* {{{ proto bool imagefilter(resource src_im, int filtertype, [args] )
5298 : Applies Filter an image using a custom angle */
5299 : PHP_FUNCTION(imagefilter)
5300 29 : {
5301 : zval *tmp;
5302 :
5303 : typedef void (*image_filter)(INTERNAL_FUNCTION_PARAMETERS);
5304 : long filtertype;
5305 : image_filter filters[] =
5306 : {
5307 : php_image_filter_negate ,
5308 : php_image_filter_grayscale,
5309 : php_image_filter_brightness,
5310 : php_image_filter_contrast,
5311 : php_image_filter_colorize,
5312 : php_image_filter_edgedetect,
5313 : php_image_filter_emboss,
5314 : php_image_filter_gaussian_blur,
5315 : php_image_filter_selective_blur,
5316 : php_image_filter_mean_removal,
5317 : php_image_filter_smooth
5318 29 : }; |