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