Back to index

php5  5.3.10
gd.c
Go to the documentation of this file.
00001 /*
00002    +----------------------------------------------------------------------+
00003    | PHP Version 5                                                        |
00004    +----------------------------------------------------------------------+
00005    | Copyright (c) 1997-2012 The PHP Group                                |
00006    +----------------------------------------------------------------------+
00007    | This source file is subject to version 3.01 of the PHP license,      |
00008    | that is bundled with this package in the file LICENSE, and is        |
00009    | available through the world-wide-web at the following url:           |
00010    | http://www.php.net/license/3_01.txt                                  |
00011    | If you did not receive a copy of the PHP license and are unable to   |
00012    | obtain it through the world-wide-web, please send a note to          |
00013    | license@php.net so we can mail you a copy immediately.               |
00014    +----------------------------------------------------------------------+
00015    | Authors: Rasmus Lerdorf <rasmus@php.net>                             |
00016    |          Stig Bakken <ssb@php.net>                                   |
00017    |          Jim Winstead <jimw@php.net>                                 |
00018    +----------------------------------------------------------------------+
00019  */
00020 
00021 /* $Id: gd.c 321634 2012-01-01 13:15:04Z felipe $ */
00022 
00023 /* gd 1.2 is copyright 1994, 1995, Quest Protein Database Center,
00024    Cold Spring Harbor Labs. */
00025 
00026 /* Note that there is no code from the gd package in this file */
00027 
00028 #ifdef HAVE_CONFIG_H
00029 #include "config.h"
00030 #endif
00031 
00032 #include "php.h"
00033 #include "php_ini.h"
00034 #include "ext/standard/head.h"
00035 #include <math.h>
00036 #include "SAPI.h"
00037 #include "php_gd.h"
00038 #include "ext/standard/info.h"
00039 #include "php_open_temporary_file.h"
00040 
00041 
00042 #if HAVE_SYS_WAIT_H
00043 # include <sys/wait.h>
00044 #endif
00045 #if HAVE_UNISTD_H
00046 # include <unistd.h>
00047 #endif
00048 #ifdef PHP_WIN32
00049 # include <io.h>
00050 # include <fcntl.h>
00051 # include <windows.h>
00052 # include <Winuser.h>
00053 # include <Wingdi.h>
00054 #endif
00055 
00056 #if HAVE_LIBGD
00057 #if !HAVE_GD_BUNDLED
00058 # include "libgd/gd_compat.h"
00059 #endif
00060 
00061 
00062 static int le_gd, le_gd_font;
00063 #if HAVE_LIBT1
00064 #include <t1lib.h>
00065 static int le_ps_font, le_ps_enc;
00066 static void php_free_ps_font(zend_rsrc_list_entry *rsrc TSRMLS_DC);
00067 static void php_free_ps_enc(zend_rsrc_list_entry *rsrc TSRMLS_DC);
00068 #endif
00069 
00070 #include <gd.h>
00071 #include <gdfontt.h>  /* 1 Tiny font */
00072 #include <gdfonts.h>  /* 2 Small font */
00073 #include <gdfontmb.h> /* 3 Medium bold font */
00074 #include <gdfontl.h>  /* 4 Large font */
00075 #include <gdfontg.h>  /* 5 Giant font */
00076 
00077 #ifdef HAVE_GD_WBMP
00078 #include "libgd/wbmp.h"
00079 #endif
00080 #ifdef ENABLE_GD_TTF
00081 # ifdef HAVE_LIBFREETYPE
00082 #  include <ft2build.h>
00083 #  include FT_FREETYPE_H
00084 # endif
00085 #endif
00086 
00087 #ifndef M_PI
00088 #define M_PI 3.14159265358979323846
00089 #endif
00090 
00091 #ifdef ENABLE_GD_TTF
00092 static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int, int);
00093 #endif
00094 
00095 #if HAVE_LIBGD15
00096 /* it's >= 1.5, i.e. has IOCtx */
00097 #define USE_GD_IOCTX 1
00098 #else
00099 #undef USE_GD_IOCTX
00100 #endif
00101 
00102 #ifdef USE_GD_IOCTX
00103 #include "gd_ctx.c"
00104 #else
00105 #define gdImageCreateFromGdCtx      NULL
00106 #define gdImageCreateFromGd2Ctx     NULL
00107 #define gdImageCreateFromGd2partCtx NULL
00108 #define gdImageCreateFromGifCtx     NULL
00109 #define gdImageCreateFromJpegCtx    NULL
00110 #define gdImageCreateFromPngCtx     NULL
00111 #define gdImageCreateFromWBMPCtx    NULL
00112 typedef FILE gdIOCtx;
00113 #define CTX_PUTC(c, fp) fputc(c, fp)
00114 #endif
00115 
00116 #ifndef HAVE_GDIMAGECOLORRESOLVE
00117 extern int gdImageColorResolve(gdImagePtr, int, int, int);
00118 #endif
00119 
00120 #if HAVE_COLORCLOSESTHWB
00121 int gdImageColorClosestHWB(gdImagePtr im, int r, int g, int b);
00122 #endif
00123 
00124 #ifndef HAVE_GD_DYNAMIC_CTX_EX
00125 #define gdNewDynamicCtxEx(len, data, val) gdNewDynamicCtx(len, data)
00126 #endif
00127 
00128 /* Section Filters Declarations */
00129 /* IMPORTANT NOTE FOR NEW FILTER
00130  * Do not forget to update:
00131  * IMAGE_FILTER_MAX: define the last filter index
00132  * IMAGE_FILTER_MAX_ARGS: define the biggest amout of arguments
00133  * image_filter array in PHP_FUNCTION(imagefilter)
00134  * */
00135 #define IMAGE_FILTER_NEGATE         0
00136 #define IMAGE_FILTER_GRAYSCALE      1
00137 #define IMAGE_FILTER_BRIGHTNESS     2
00138 #define IMAGE_FILTER_CONTRAST       3
00139 #define IMAGE_FILTER_COLORIZE       4
00140 #define IMAGE_FILTER_EDGEDETECT     5
00141 #define IMAGE_FILTER_EMBOSS         6
00142 #define IMAGE_FILTER_GAUSSIAN_BLUR  7
00143 #define IMAGE_FILTER_SELECTIVE_BLUR 8
00144 #define IMAGE_FILTER_MEAN_REMOVAL   9
00145 #define IMAGE_FILTER_SMOOTH         10
00146 #define IMAGE_FILTER_PIXELATE       11
00147 #define IMAGE_FILTER_MAX            11
00148 #define IMAGE_FILTER_MAX_ARGS       6
00149 static void php_image_filter_negate(INTERNAL_FUNCTION_PARAMETERS);
00150 static void php_image_filter_grayscale(INTERNAL_FUNCTION_PARAMETERS);
00151 static void php_image_filter_brightness(INTERNAL_FUNCTION_PARAMETERS);
00152 static void php_image_filter_contrast(INTERNAL_FUNCTION_PARAMETERS);
00153 static void php_image_filter_colorize(INTERNAL_FUNCTION_PARAMETERS);
00154 static void php_image_filter_edgedetect(INTERNAL_FUNCTION_PARAMETERS);
00155 static void php_image_filter_emboss(INTERNAL_FUNCTION_PARAMETERS);
00156 static void php_image_filter_gaussian_blur(INTERNAL_FUNCTION_PARAMETERS);
00157 static void php_image_filter_selective_blur(INTERNAL_FUNCTION_PARAMETERS);
00158 static void php_image_filter_mean_removal(INTERNAL_FUNCTION_PARAMETERS);
00159 static void php_image_filter_smooth(INTERNAL_FUNCTION_PARAMETERS);
00160 static void php_image_filter_pixelate(INTERNAL_FUNCTION_PARAMETERS);
00161 
00162 /* End Section filters declarations */
00163 static gdImagePtr _php_image_create_from_string (zval **Data, char *tn, gdImagePtr (*ioctx_func_p)() TSRMLS_DC);
00164 static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, gdImagePtr (*func_p)(), gdImagePtr (*ioctx_func_p)());
00165 static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, void (*func_p)());
00166 static int _php_image_type(char data[8]);
00167 static void _php_image_convert(INTERNAL_FUNCTION_PARAMETERS, int image_type);
00168 static void _php_image_bw_convert(gdImagePtr im_org, gdIOCtx *out, int threshold);
00169 
00170 /* {{{ arginfo */
00171 ZEND_BEGIN_ARG_INFO(arginfo_gd_info, 0)
00172 ZEND_END_ARG_INFO()
00173 
00174 ZEND_BEGIN_ARG_INFO(arginfo_imageloadfont, 0)
00175        ZEND_ARG_INFO(0, filename)
00176 ZEND_END_ARG_INFO()
00177 
00178 ZEND_BEGIN_ARG_INFO(arginfo_imagesetstyle, 0)
00179        ZEND_ARG_INFO(0, im)
00180        ZEND_ARG_INFO(0, styles) /* ARRAY_INFO(0, styles, 0) */
00181 ZEND_END_ARG_INFO()
00182 
00183 ZEND_BEGIN_ARG_INFO(arginfo_imagecreatetruecolor, 0)
00184        ZEND_ARG_INFO(0, x_size)
00185        ZEND_ARG_INFO(0, y_size)
00186 ZEND_END_ARG_INFO()
00187 
00188 ZEND_BEGIN_ARG_INFO(arginfo_imageistruecolor, 0)
00189        ZEND_ARG_INFO(0, im)
00190 ZEND_END_ARG_INFO()
00191 
00192 ZEND_BEGIN_ARG_INFO(arginfo_imagetruecolortopalette, 0)
00193        ZEND_ARG_INFO(0, im)
00194        ZEND_ARG_INFO(0, ditherFlag)
00195        ZEND_ARG_INFO(0, colorsWanted)
00196 ZEND_END_ARG_INFO()
00197 
00198 ZEND_BEGIN_ARG_INFO(arginfo_imagecolormatch, 0)
00199        ZEND_ARG_INFO(0, im1)
00200        ZEND_ARG_INFO(0, im2)
00201 ZEND_END_ARG_INFO()
00202 
00203 ZEND_BEGIN_ARG_INFO(arginfo_imagesetthickness, 0)
00204        ZEND_ARG_INFO(0, im)
00205        ZEND_ARG_INFO(0, thickness)
00206 ZEND_END_ARG_INFO()
00207 
00208 ZEND_BEGIN_ARG_INFO(arginfo_imagefilledellipse, 0)
00209        ZEND_ARG_INFO(0, im)
00210        ZEND_ARG_INFO(0, cx)
00211        ZEND_ARG_INFO(0, cy)
00212        ZEND_ARG_INFO(0, w)
00213        ZEND_ARG_INFO(0, h)
00214        ZEND_ARG_INFO(0, color)
00215 ZEND_END_ARG_INFO()
00216 
00217 ZEND_BEGIN_ARG_INFO(arginfo_imagefilledarc, 0)
00218        ZEND_ARG_INFO(0, im)
00219        ZEND_ARG_INFO(0, cx)
00220        ZEND_ARG_INFO(0, cy)
00221        ZEND_ARG_INFO(0, w)
00222        ZEND_ARG_INFO(0, h)
00223        ZEND_ARG_INFO(0, s)
00224        ZEND_ARG_INFO(0, e)
00225        ZEND_ARG_INFO(0, col)
00226        ZEND_ARG_INFO(0, style)
00227 ZEND_END_ARG_INFO()
00228 
00229 ZEND_BEGIN_ARG_INFO(arginfo_imagealphablending, 0)
00230        ZEND_ARG_INFO(0, im)
00231        ZEND_ARG_INFO(0, blend)
00232 ZEND_END_ARG_INFO()
00233 
00234 ZEND_BEGIN_ARG_INFO(arginfo_imagesavealpha, 0)
00235        ZEND_ARG_INFO(0, im)
00236        ZEND_ARG_INFO(0, save)
00237 ZEND_END_ARG_INFO()
00238 
00239 #if HAVE_GD_BUNDLED
00240 ZEND_BEGIN_ARG_INFO(arginfo_imagelayereffect, 0)
00241        ZEND_ARG_INFO(0, im)
00242        ZEND_ARG_INFO(0, effect)
00243 ZEND_END_ARG_INFO()
00244 #endif
00245 
00246 ZEND_BEGIN_ARG_INFO(arginfo_imagecolorallocatealpha, 0)
00247        ZEND_ARG_INFO(0, im)
00248        ZEND_ARG_INFO(0, red)
00249        ZEND_ARG_INFO(0, green)
00250        ZEND_ARG_INFO(0, blue)
00251        ZEND_ARG_INFO(0, alpha)
00252 ZEND_END_ARG_INFO()
00253 
00254 ZEND_BEGIN_ARG_INFO(arginfo_imagecolorresolvealpha, 0)
00255        ZEND_ARG_INFO(0, im)
00256        ZEND_ARG_INFO(0, red)
00257        ZEND_ARG_INFO(0, green)
00258        ZEND_ARG_INFO(0, blue)
00259        ZEND_ARG_INFO(0, alpha)
00260 ZEND_END_ARG_INFO()
00261 
00262 ZEND_BEGIN_ARG_INFO(arginfo_imagecolorclosestalpha, 0)
00263        ZEND_ARG_INFO(0, im)
00264        ZEND_ARG_INFO(0, red)
00265        ZEND_ARG_INFO(0, green)
00266        ZEND_ARG_INFO(0, blue)
00267        ZEND_ARG_INFO(0, alpha)
00268 ZEND_END_ARG_INFO()
00269 
00270 ZEND_BEGIN_ARG_INFO(arginfo_imagecolorexactalpha, 0)
00271        ZEND_ARG_INFO(0, im)
00272        ZEND_ARG_INFO(0, red)
00273        ZEND_ARG_INFO(0, green)
00274        ZEND_ARG_INFO(0, blue)
00275        ZEND_ARG_INFO(0, alpha)
00276 ZEND_END_ARG_INFO()
00277 
00278 ZEND_BEGIN_ARG_INFO(arginfo_imagecopyresampled, 0)
00279        ZEND_ARG_INFO(0, dst_im)
00280        ZEND_ARG_INFO(0, src_im)
00281        ZEND_ARG_INFO(0, dst_x)
00282        ZEND_ARG_INFO(0, dst_y)
00283        ZEND_ARG_INFO(0, src_x)
00284        ZEND_ARG_INFO(0, src_y)
00285        ZEND_ARG_INFO(0, dst_w)
00286        ZEND_ARG_INFO(0, dst_h)
00287        ZEND_ARG_INFO(0, src_w)
00288        ZEND_ARG_INFO(0, src_h)
00289 ZEND_END_ARG_INFO()
00290 
00291 #ifdef PHP_WIN32
00292 ZEND_BEGIN_ARG_INFO_EX(arginfo_imagegrabwindow, 0, 0, 1)
00293        ZEND_ARG_INFO(0, handle)
00294        ZEND_ARG_INFO(0, client_area)
00295 ZEND_END_ARG_INFO()
00296 
00297 ZEND_BEGIN_ARG_INFO(arginfo_imagegrabscreen, 0)
00298 ZEND_END_ARG_INFO()
00299 #endif
00300 
00301 ZEND_BEGIN_ARG_INFO_EX(arginfo_imagerotate, 0, 0, 3)
00302        ZEND_ARG_INFO(0, im)
00303        ZEND_ARG_INFO(0, angle)
00304        ZEND_ARG_INFO(0, bgdcolor)
00305        ZEND_ARG_INFO(0, ignoretransparent)
00306 ZEND_END_ARG_INFO()
00307 
00308 #if HAVE_GD_IMAGESETTILE
00309 ZEND_BEGIN_ARG_INFO(arginfo_imagesettile, 0)
00310        ZEND_ARG_INFO(0, im)
00311        ZEND_ARG_INFO(0, tile)
00312 ZEND_END_ARG_INFO()
00313 #endif
00314 
00315 #if HAVE_GD_IMAGESETBRUSH
00316 ZEND_BEGIN_ARG_INFO(arginfo_imagesetbrush, 0)
00317        ZEND_ARG_INFO(0, im)
00318        ZEND_ARG_INFO(0, brush)
00319 ZEND_END_ARG_INFO()
00320 #endif
00321 
00322 ZEND_BEGIN_ARG_INFO(arginfo_imagecreate, 0)
00323        ZEND_ARG_INFO(0, x_size)
00324        ZEND_ARG_INFO(0, y_size)
00325 ZEND_END_ARG_INFO()
00326 
00327 ZEND_BEGIN_ARG_INFO(arginfo_imagetypes, 0)
00328 ZEND_END_ARG_INFO()
00329 
00330 #if HAVE_LIBGD15
00331 ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefromstring, 0)
00332        ZEND_ARG_INFO(0, image)
00333 ZEND_END_ARG_INFO()
00334 #endif
00335 
00336 #ifdef HAVE_GD_GIF_READ
00337 ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefromgif, 0)
00338        ZEND_ARG_INFO(0, filename)
00339 ZEND_END_ARG_INFO()
00340 #endif
00341 
00342 #ifdef HAVE_GD_JPG
00343 ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefromjpeg, 0)
00344        ZEND_ARG_INFO(0, filename)
00345 ZEND_END_ARG_INFO()
00346 #endif
00347 
00348 #ifdef HAVE_GD_PNG
00349 ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefrompng, 0)
00350        ZEND_ARG_INFO(0, filename)
00351 ZEND_END_ARG_INFO()
00352 #endif
00353 
00354 #ifdef HAVE_GD_XBM
00355 ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefromxbm, 0)
00356        ZEND_ARG_INFO(0, filename)
00357 ZEND_END_ARG_INFO()
00358 #endif
00359 
00360 #if defined(HAVE_GD_XPM) && defined(HAVE_GD_BUNDLED)
00361 ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefromxpm, 0)
00362        ZEND_ARG_INFO(0, filename)
00363 ZEND_END_ARG_INFO()
00364 #endif
00365 
00366 #ifdef HAVE_GD_WBMP
00367 ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefromwbmp, 0)
00368        ZEND_ARG_INFO(0, filename)
00369 ZEND_END_ARG_INFO()
00370 #endif
00371 
00372 ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefromgd, 0)
00373        ZEND_ARG_INFO(0, filename)
00374 ZEND_END_ARG_INFO()
00375 
00376 #ifdef HAVE_GD_GD2
00377 ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefromgd2, 0)
00378        ZEND_ARG_INFO(0, filename)
00379 ZEND_END_ARG_INFO()
00380 
00381 ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefromgd2part, 0)
00382        ZEND_ARG_INFO(0, filename)
00383        ZEND_ARG_INFO(0, srcX)
00384        ZEND_ARG_INFO(0, srcY)
00385        ZEND_ARG_INFO(0, width)
00386        ZEND_ARG_INFO(0, height)
00387 ZEND_END_ARG_INFO()
00388 #endif
00389 
00390 #if HAVE_GD_BUNDLED
00391 ZEND_BEGIN_ARG_INFO_EX(arginfo_imagexbm, 0, 0, 2)
00392        ZEND_ARG_INFO(0, im)
00393        ZEND_ARG_INFO(0, filename)
00394        ZEND_ARG_INFO(0, foreground)
00395 ZEND_END_ARG_INFO()
00396 #endif
00397 
00398 #ifdef HAVE_GD_GIF_CREATE
00399 ZEND_BEGIN_ARG_INFO_EX(arginfo_imagegif, 0, 0, 1)
00400        ZEND_ARG_INFO(0, im)
00401        ZEND_ARG_INFO(0, filename)
00402 ZEND_END_ARG_INFO()
00403 #endif
00404 
00405 #ifdef HAVE_GD_PNG
00406 ZEND_BEGIN_ARG_INFO_EX(arginfo_imagepng, 0, 0, 1)
00407        ZEND_ARG_INFO(0, im)
00408        ZEND_ARG_INFO(0, filename)
00409 ZEND_END_ARG_INFO()
00410 #endif
00411 
00412 #ifdef HAVE_GD_JPG
00413 ZEND_BEGIN_ARG_INFO_EX(arginfo_imagejpeg, 0, 0, 1)
00414        ZEND_ARG_INFO(0, im)
00415        ZEND_ARG_INFO(0, filename)
00416        ZEND_ARG_INFO(0, quality)
00417 ZEND_END_ARG_INFO()
00418 #endif
00419 
00420 #ifdef HAVE_GD_WBMP
00421 ZEND_BEGIN_ARG_INFO_EX(arginfo_imagewbmp, 0, 0, 1)
00422        ZEND_ARG_INFO(0, im)
00423        ZEND_ARG_INFO(0, filename)
00424        ZEND_ARG_INFO(0, foreground)
00425 ZEND_END_ARG_INFO()
00426 #endif
00427 
00428 ZEND_BEGIN_ARG_INFO_EX(arginfo_imagegd, 0, 0, 1)
00429        ZEND_ARG_INFO(0, im)
00430        ZEND_ARG_INFO(0, filename)
00431 ZEND_END_ARG_INFO()
00432 
00433 #ifdef HAVE_GD_GD2
00434 ZEND_BEGIN_ARG_INFO_EX(arginfo_imagegd2, 0, 0, 1)
00435        ZEND_ARG_INFO(0, im)
00436        ZEND_ARG_INFO(0, filename)
00437        ZEND_ARG_INFO(0, chunk_size)
00438        ZEND_ARG_INFO(0, type)
00439 ZEND_END_ARG_INFO()
00440 #endif
00441 
00442 ZEND_BEGIN_ARG_INFO(arginfo_imagedestroy, 0)
00443        ZEND_ARG_INFO(0, im)
00444 ZEND_END_ARG_INFO()
00445 
00446 ZEND_BEGIN_ARG_INFO(arginfo_imagecolorallocate, 0)
00447        ZEND_ARG_INFO(0, im)
00448        ZEND_ARG_INFO(0, red)
00449        ZEND_ARG_INFO(0, green)
00450        ZEND_ARG_INFO(0, blue)
00451 ZEND_END_ARG_INFO()
00452 
00453 #if HAVE_LIBGD15
00454 ZEND_BEGIN_ARG_INFO(arginfo_imagepalettecopy, 0)
00455        ZEND_ARG_INFO(0, dst)
00456        ZEND_ARG_INFO(0, src)
00457 ZEND_END_ARG_INFO()
00458 #endif
00459 
00460 ZEND_BEGIN_ARG_INFO(arginfo_imagecolorat, 0)
00461        ZEND_ARG_INFO(0, im)
00462        ZEND_ARG_INFO(0, x)
00463        ZEND_ARG_INFO(0, y)
00464 ZEND_END_ARG_INFO()
00465 
00466 ZEND_BEGIN_ARG_INFO(arginfo_imagecolorclosest, 0)
00467        ZEND_ARG_INFO(0, im)
00468        ZEND_ARG_INFO(0, red)
00469        ZEND_ARG_INFO(0, green)
00470        ZEND_ARG_INFO(0, blue)
00471 ZEND_END_ARG_INFO()
00472 
00473 #if HAVE_COLORCLOSESTHWB
00474 ZEND_BEGIN_ARG_INFO(arginfo_imagecolorclosesthwb, 0)
00475        ZEND_ARG_INFO(0, im)
00476        ZEND_ARG_INFO(0, red)
00477        ZEND_ARG_INFO(0, green)
00478        ZEND_ARG_INFO(0, blue)
00479 ZEND_END_ARG_INFO()
00480 #endif
00481 
00482 ZEND_BEGIN_ARG_INFO(arginfo_imagecolordeallocate, 0)
00483        ZEND_ARG_INFO(0, im)
00484        ZEND_ARG_INFO(0, index)
00485 ZEND_END_ARG_INFO()
00486 
00487 ZEND_BEGIN_ARG_INFO(arginfo_imagecolorresolve, 0)
00488        ZEND_ARG_INFO(0, im)
00489        ZEND_ARG_INFO(0, red)
00490        ZEND_ARG_INFO(0, green)
00491        ZEND_ARG_INFO(0, blue)
00492 ZEND_END_ARG_INFO()
00493 
00494 ZEND_BEGIN_ARG_INFO(arginfo_imagecolorexact, 0)
00495        ZEND_ARG_INFO(0, im)
00496        ZEND_ARG_INFO(0, red)
00497        ZEND_ARG_INFO(0, green)
00498        ZEND_ARG_INFO(0, blue)
00499 ZEND_END_ARG_INFO()
00500 
00501 ZEND_BEGIN_ARG_INFO(arginfo_imagecolorset, 0)
00502        ZEND_ARG_INFO(0, im)
00503        ZEND_ARG_INFO(0, color)
00504        ZEND_ARG_INFO(0, red)
00505        ZEND_ARG_INFO(0, green)
00506        ZEND_ARG_INFO(0, blue)
00507 ZEND_END_ARG_INFO()
00508 
00509 ZEND_BEGIN_ARG_INFO(arginfo_imagecolorsforindex, 0)
00510        ZEND_ARG_INFO(0, im)
00511        ZEND_ARG_INFO(0, index)
00512 ZEND_END_ARG_INFO()
00513 
00514 ZEND_BEGIN_ARG_INFO(arginfo_imagegammacorrect, 0)
00515        ZEND_ARG_INFO(0, im)
00516        ZEND_ARG_INFO(0, inputgamma)
00517        ZEND_ARG_INFO(0, outputgamma)
00518 ZEND_END_ARG_INFO()
00519 
00520 ZEND_BEGIN_ARG_INFO(arginfo_imagesetpixel, 0)
00521        ZEND_ARG_INFO(0, im)
00522        ZEND_ARG_INFO(0, x)
00523        ZEND_ARG_INFO(0, y)
00524        ZEND_ARG_INFO(0, col)
00525 ZEND_END_ARG_INFO()
00526 
00527 ZEND_BEGIN_ARG_INFO(arginfo_imageline, 0)
00528        ZEND_ARG_INFO(0, im)
00529        ZEND_ARG_INFO(0, x1)
00530        ZEND_ARG_INFO(0, y1)
00531        ZEND_ARG_INFO(0, x2)
00532        ZEND_ARG_INFO(0, y2)
00533        ZEND_ARG_INFO(0, col)
00534 ZEND_END_ARG_INFO()
00535 
00536 ZEND_BEGIN_ARG_INFO(arginfo_imagedashedline, 0)
00537        ZEND_ARG_INFO(0, im)
00538        ZEND_ARG_INFO(0, x1)
00539        ZEND_ARG_INFO(0, y1)
00540        ZEND_ARG_INFO(0, x2)
00541        ZEND_ARG_INFO(0, y2)
00542        ZEND_ARG_INFO(0, col)
00543 ZEND_END_ARG_INFO()
00544 
00545 ZEND_BEGIN_ARG_INFO(arginfo_imagerectangle, 0)
00546        ZEND_ARG_INFO(0, im)
00547        ZEND_ARG_INFO(0, x1)
00548        ZEND_ARG_INFO(0, y1)
00549        ZEND_ARG_INFO(0, x2)
00550        ZEND_ARG_INFO(0, y2)
00551        ZEND_ARG_INFO(0, col)
00552 ZEND_END_ARG_INFO()
00553 
00554 ZEND_BEGIN_ARG_INFO(arginfo_imagefilledrectangle, 0)
00555        ZEND_ARG_INFO(0, im)
00556        ZEND_ARG_INFO(0, x1)
00557        ZEND_ARG_INFO(0, y1)
00558        ZEND_ARG_INFO(0, x2)
00559        ZEND_ARG_INFO(0, y2)
00560        ZEND_ARG_INFO(0, col)
00561 ZEND_END_ARG_INFO()
00562 
00563 ZEND_BEGIN_ARG_INFO(arginfo_imagearc, 0)
00564        ZEND_ARG_INFO(0, im)
00565        ZEND_ARG_INFO(0, cx)
00566        ZEND_ARG_INFO(0, cy)
00567        ZEND_ARG_INFO(0, w)
00568        ZEND_ARG_INFO(0, h)
00569        ZEND_ARG_INFO(0, s)
00570        ZEND_ARG_INFO(0, e)
00571        ZEND_ARG_INFO(0, col)
00572 ZEND_END_ARG_INFO()
00573 
00574 ZEND_BEGIN_ARG_INFO(arginfo_imageellipse, 0)
00575        ZEND_ARG_INFO(0, im)
00576        ZEND_ARG_INFO(0, cx)
00577        ZEND_ARG_INFO(0, cy)
00578        ZEND_ARG_INFO(0, w)
00579        ZEND_ARG_INFO(0, h)
00580        ZEND_ARG_INFO(0, color)
00581 ZEND_END_ARG_INFO()
00582 
00583 ZEND_BEGIN_ARG_INFO(arginfo_imagefilltoborder, 0)
00584        ZEND_ARG_INFO(0, im)
00585        ZEND_ARG_INFO(0, x)
00586        ZEND_ARG_INFO(0, y)
00587        ZEND_ARG_INFO(0, border)
00588        ZEND_ARG_INFO(0, col)
00589 ZEND_END_ARG_INFO()
00590 
00591 ZEND_BEGIN_ARG_INFO(arginfo_imagefill, 0)
00592        ZEND_ARG_INFO(0, im)
00593        ZEND_ARG_INFO(0, x)
00594        ZEND_ARG_INFO(0, y)
00595        ZEND_ARG_INFO(0, col)
00596 ZEND_END_ARG_INFO()
00597 
00598 ZEND_BEGIN_ARG_INFO(arginfo_imagecolorstotal, 0)
00599        ZEND_ARG_INFO(0, im)
00600 ZEND_END_ARG_INFO()
00601 
00602 ZEND_BEGIN_ARG_INFO_EX(arginfo_imagecolortransparent, 0, 0, 1)
00603        ZEND_ARG_INFO(0, im)
00604        ZEND_ARG_INFO(0, col)
00605 ZEND_END_ARG_INFO()
00606 
00607 ZEND_BEGIN_ARG_INFO_EX(arginfo_imageinterlace, 0, 0, 1)
00608        ZEND_ARG_INFO(0, im)
00609        ZEND_ARG_INFO(0, interlace)
00610 ZEND_END_ARG_INFO()
00611 
00612 ZEND_BEGIN_ARG_INFO(arginfo_imagepolygon, 0)
00613        ZEND_ARG_INFO(0, im)
00614        ZEND_ARG_INFO(0, points) /* ARRAY_INFO(0, points, 0) */
00615        ZEND_ARG_INFO(0, num_pos)
00616        ZEND_ARG_INFO(0, col)
00617 ZEND_END_ARG_INFO()
00618 
00619 ZEND_BEGIN_ARG_INFO(arginfo_imagefilledpolygon, 0)
00620        ZEND_ARG_INFO(0, im)
00621        ZEND_ARG_INFO(0, points) /* ARRAY_INFO(0, points, 0) */
00622        ZEND_ARG_INFO(0, num_pos)
00623        ZEND_ARG_INFO(0, col)
00624 ZEND_END_ARG_INFO()
00625 
00626 ZEND_BEGIN_ARG_INFO(arginfo_imagefontwidth, 0)
00627        ZEND_ARG_INFO(0, font)
00628 ZEND_END_ARG_INFO()
00629 
00630 ZEND_BEGIN_ARG_INFO(arginfo_imagefontheight, 0)
00631        ZEND_ARG_INFO(0, font)
00632 ZEND_END_ARG_INFO()
00633 
00634 ZEND_BEGIN_ARG_INFO(arginfo_imagechar, 0)
00635        ZEND_ARG_INFO(0, im)
00636        ZEND_ARG_INFO(0, font)
00637        ZEND_ARG_INFO(0, x)
00638        ZEND_ARG_INFO(0, y)
00639        ZEND_ARG_INFO(0, c)
00640        ZEND_ARG_INFO(0, col)
00641 ZEND_END_ARG_INFO()
00642 
00643 ZEND_BEGIN_ARG_INFO(arginfo_imagecharup, 0)
00644        ZEND_ARG_INFO(0, im)
00645        ZEND_ARG_INFO(0, font)
00646        ZEND_ARG_INFO(0, x)
00647        ZEND_ARG_INFO(0, y)
00648        ZEND_ARG_INFO(0, c)
00649        ZEND_ARG_INFO(0, col)
00650 ZEND_END_ARG_INFO()
00651 
00652 ZEND_BEGIN_ARG_INFO(arginfo_imagestring, 0)
00653        ZEND_ARG_INFO(0, im)
00654        ZEND_ARG_INFO(0, font)
00655        ZEND_ARG_INFO(0, x)
00656        ZEND_ARG_INFO(0, y)
00657        ZEND_ARG_INFO(0, str)
00658        ZEND_ARG_INFO(0, col)
00659 ZEND_END_ARG_INFO()
00660 
00661 ZEND_BEGIN_ARG_INFO(arginfo_imagestringup, 0)
00662        ZEND_ARG_INFO(0, im)
00663        ZEND_ARG_INFO(0, font)
00664        ZEND_ARG_INFO(0, x)
00665        ZEND_ARG_INFO(0, y)
00666        ZEND_ARG_INFO(0, str)
00667        ZEND_ARG_INFO(0, col)
00668 ZEND_END_ARG_INFO()
00669 
00670 ZEND_BEGIN_ARG_INFO(arginfo_imagecopy, 0)
00671        ZEND_ARG_INFO(0, dst_im)
00672        ZEND_ARG_INFO(0, src_im)
00673        ZEND_ARG_INFO(0, dst_x)
00674        ZEND_ARG_INFO(0, dst_y)
00675        ZEND_ARG_INFO(0, src_x)
00676        ZEND_ARG_INFO(0, src_y)
00677        ZEND_ARG_INFO(0, src_w)
00678        ZEND_ARG_INFO(0, src_h)
00679 ZEND_END_ARG_INFO()
00680 
00681 #if HAVE_LIBGD15
00682 ZEND_BEGIN_ARG_INFO(arginfo_imagecopymerge, 0)
00683        ZEND_ARG_INFO(0, src_im)
00684        ZEND_ARG_INFO(0, dst_im)
00685        ZEND_ARG_INFO(0, dst_x)
00686        ZEND_ARG_INFO(0, dst_y)
00687        ZEND_ARG_INFO(0, src_x)
00688        ZEND_ARG_INFO(0, src_y)
00689        ZEND_ARG_INFO(0, src_w)
00690        ZEND_ARG_INFO(0, src_h)
00691        ZEND_ARG_INFO(0, pct)
00692 ZEND_END_ARG_INFO()
00693 
00694 ZEND_BEGIN_ARG_INFO(arginfo_imagecopymergegray, 0)
00695        ZEND_ARG_INFO(0, src_im)
00696        ZEND_ARG_INFO(0, dst_im)
00697        ZEND_ARG_INFO(0, dst_x)
00698        ZEND_ARG_INFO(0, dst_y)
00699        ZEND_ARG_INFO(0, src_x)
00700        ZEND_ARG_INFO(0, src_y)
00701        ZEND_ARG_INFO(0, src_w)
00702        ZEND_ARG_INFO(0, src_h)
00703        ZEND_ARG_INFO(0, pct)
00704 ZEND_END_ARG_INFO()
00705 #endif
00706 
00707 ZEND_BEGIN_ARG_INFO(arginfo_imagecopyresized, 0)
00708        ZEND_ARG_INFO(0, dst_im)
00709        ZEND_ARG_INFO(0, src_im)
00710        ZEND_ARG_INFO(0, dst_x)
00711        ZEND_ARG_INFO(0, dst_y)
00712        ZEND_ARG_INFO(0, src_x)
00713        ZEND_ARG_INFO(0, src_y)
00714        ZEND_ARG_INFO(0, dst_w)
00715        ZEND_ARG_INFO(0, dst_h)
00716        ZEND_ARG_INFO(0, src_w)
00717        ZEND_ARG_INFO(0, src_h)
00718 ZEND_END_ARG_INFO()
00719 
00720 ZEND_BEGIN_ARG_INFO(arginfo_imagesx, 0)
00721        ZEND_ARG_INFO(0, im)
00722 ZEND_END_ARG_INFO()
00723 
00724 ZEND_BEGIN_ARG_INFO(arginfo_imagesy, 0)
00725        ZEND_ARG_INFO(0, im)
00726 ZEND_END_ARG_INFO()
00727 
00728 #ifdef ENABLE_GD_TTF
00729 #if HAVE_LIBFREETYPE && HAVE_GD_STRINGFTEX
00730 ZEND_BEGIN_ARG_INFO_EX(arginfo_imageftbbox, 0, 0, 4)
00731        ZEND_ARG_INFO(0, size)
00732        ZEND_ARG_INFO(0, angle)
00733        ZEND_ARG_INFO(0, font_file)
00734        ZEND_ARG_INFO(0, text)
00735        ZEND_ARG_INFO(0, extrainfo) /* ARRAY_INFO(0, extrainfo, 0) */
00736 ZEND_END_ARG_INFO()
00737 
00738 ZEND_BEGIN_ARG_INFO_EX(arginfo_imagefttext, 0, 0, 8)
00739        ZEND_ARG_INFO(0, im)
00740        ZEND_ARG_INFO(0, size)
00741        ZEND_ARG_INFO(0, angle)
00742        ZEND_ARG_INFO(0, x)
00743        ZEND_ARG_INFO(0, y)
00744        ZEND_ARG_INFO(0, col)
00745        ZEND_ARG_INFO(0, font_file)
00746        ZEND_ARG_INFO(0, text)
00747        ZEND_ARG_INFO(0, extrainfo) /* ARRAY_INFO(0, extrainfo, 0) */
00748 ZEND_END_ARG_INFO()
00749 #endif
00750 
00751 ZEND_BEGIN_ARG_INFO(arginfo_imagettfbbox, 0)
00752        ZEND_ARG_INFO(0, size)
00753        ZEND_ARG_INFO(0, angle)
00754        ZEND_ARG_INFO(0, font_file)
00755        ZEND_ARG_INFO(0, text)
00756 ZEND_END_ARG_INFO()
00757 
00758 ZEND_BEGIN_ARG_INFO(arginfo_imagettftext, 0)
00759        ZEND_ARG_INFO(0, im)
00760        ZEND_ARG_INFO(0, size)
00761        ZEND_ARG_INFO(0, angle)
00762        ZEND_ARG_INFO(0, x)
00763        ZEND_ARG_INFO(0, y)
00764        ZEND_ARG_INFO(0, col)
00765        ZEND_ARG_INFO(0, font_file)
00766        ZEND_ARG_INFO(0, text)
00767 ZEND_END_ARG_INFO()
00768 #endif
00769 
00770 #ifdef HAVE_LIBT1
00771 ZEND_BEGIN_ARG_INFO(arginfo_imagepsloadfont, 0)
00772        ZEND_ARG_INFO(0, pathname)
00773 ZEND_END_ARG_INFO()
00774 
00775 /*
00776 ZEND_BEGIN_ARG_INFO(arginfo_imagepscopyfont, 0)
00777        ZEND_ARG_INFO(0, font_index)
00778 ZEND_END_ARG_INFO()
00779 */
00780 
00781 ZEND_BEGIN_ARG_INFO(arginfo_imagepsfreefont, 0)
00782        ZEND_ARG_INFO(0, font_index)
00783 ZEND_END_ARG_INFO()
00784 
00785 ZEND_BEGIN_ARG_INFO(arginfo_imagepsencodefont, 0)
00786        ZEND_ARG_INFO(0, font_index)
00787        ZEND_ARG_INFO(0, filename)
00788 ZEND_END_ARG_INFO()
00789 
00790 ZEND_BEGIN_ARG_INFO(arginfo_imagepsextendfont, 0)
00791        ZEND_ARG_INFO(0, font_index)
00792        ZEND_ARG_INFO(0, extend)
00793 ZEND_END_ARG_INFO()
00794 
00795 ZEND_BEGIN_ARG_INFO(arginfo_imagepsslantfont, 0)
00796        ZEND_ARG_INFO(0, font_index)
00797        ZEND_ARG_INFO(0, slant)
00798 ZEND_END_ARG_INFO()
00799 
00800 ZEND_BEGIN_ARG_INFO_EX(arginfo_imagepstext, 0, 0, 8)
00801        ZEND_ARG_INFO(0, im)
00802        ZEND_ARG_INFO(0, text)
00803        ZEND_ARG_INFO(0, font)
00804        ZEND_ARG_INFO(0, size)
00805        ZEND_ARG_INFO(0, foreground)
00806        ZEND_ARG_INFO(0, background)
00807        ZEND_ARG_INFO(0, xcoord)
00808        ZEND_ARG_INFO(0, ycoord)
00809        ZEND_ARG_INFO(0, space)
00810        ZEND_ARG_INFO(0, tightness)
00811        ZEND_ARG_INFO(0, angle)
00812        ZEND_ARG_INFO(0, antialias)
00813 ZEND_END_ARG_INFO()
00814 
00815 ZEND_BEGIN_ARG_INFO_EX(arginfo_imagepsbbox, 0, 0, 3)
00816        ZEND_ARG_INFO(0, text)
00817        ZEND_ARG_INFO(0, font)
00818        ZEND_ARG_INFO(0, size)
00819        ZEND_ARG_INFO(0, space)
00820        ZEND_ARG_INFO(0, tightness)
00821        ZEND_ARG_INFO(0, angle)
00822 ZEND_END_ARG_INFO()
00823 #endif
00824 
00825 #ifdef HAVE_GD_WBMP
00826 ZEND_BEGIN_ARG_INFO_EX(arginfo_image2wbmp, 0, 0, 1)
00827        ZEND_ARG_INFO(0, im)
00828        ZEND_ARG_INFO(0, filename)
00829        ZEND_ARG_INFO(0, threshold)
00830 ZEND_END_ARG_INFO()
00831 #endif
00832 
00833 #if defined(HAVE_GD_JPG) && defined(HAVE_GD_WBMP)
00834 ZEND_BEGIN_ARG_INFO(arginfo_jpeg2wbmp, 0)
00835        ZEND_ARG_INFO(0, f_org)
00836        ZEND_ARG_INFO(0, f_dest)
00837        ZEND_ARG_INFO(0, d_height)
00838        ZEND_ARG_INFO(0, d_width)
00839        ZEND_ARG_INFO(0, d_threshold)
00840 ZEND_END_ARG_INFO()
00841 #endif
00842 
00843 #if defined(HAVE_GD_PNG) && defined(HAVE_GD_WBMP)
00844 ZEND_BEGIN_ARG_INFO(arginfo_png2wbmp, 0)
00845        ZEND_ARG_INFO(0, f_org)
00846        ZEND_ARG_INFO(0, f_dest)
00847        ZEND_ARG_INFO(0, d_height)
00848        ZEND_ARG_INFO(0, d_width)
00849        ZEND_ARG_INFO(0, d_threshold)
00850 ZEND_END_ARG_INFO()
00851 #endif
00852 
00853 ZEND_BEGIN_ARG_INFO_EX(arginfo_imagefilter, 0, 0, 2)
00854        ZEND_ARG_INFO(0, im)
00855        ZEND_ARG_INFO(0, filtertype)
00856        ZEND_ARG_INFO(0, arg1)
00857        ZEND_ARG_INFO(0, arg2)
00858        ZEND_ARG_INFO(0, arg3)
00859        ZEND_ARG_INFO(0, arg4)
00860 ZEND_END_ARG_INFO()
00861 
00862 ZEND_BEGIN_ARG_INFO(arginfo_imageconvolution, 0)
00863        ZEND_ARG_INFO(0, im)
00864        ZEND_ARG_INFO(0, matrix3x3) /* ARRAY_INFO(0, matrix3x3, 0) */
00865        ZEND_ARG_INFO(0, div)
00866        ZEND_ARG_INFO(0, offset)
00867 ZEND_END_ARG_INFO()
00868 
00869 #ifdef HAVE_GD_BUNDLED
00870 ZEND_BEGIN_ARG_INFO(arginfo_imageantialias, 0)
00871        ZEND_ARG_INFO(0, im)
00872        ZEND_ARG_INFO(0, on)
00873 ZEND_END_ARG_INFO()
00874 #endif
00875 
00876 /* }}} */
00877 
00878 /* {{{ gd_functions[]
00879  */
00880 const zend_function_entry gd_functions[] = {
00881        PHP_FE(gd_info,                                 arginfo_gd_info)
00882        PHP_FE(imagearc,                                                      arginfo_imagearc)
00883        PHP_FE(imageellipse,                                           arginfo_imageellipse)
00884        PHP_FE(imagechar,                                                     arginfo_imagechar)
00885        PHP_FE(imagecharup,                                                   arginfo_imagecharup)
00886        PHP_FE(imagecolorat,                                           arginfo_imagecolorat)
00887        PHP_FE(imagecolorallocate,                                     arginfo_imagecolorallocate)
00888 #if HAVE_LIBGD15
00889        PHP_FE(imagepalettecopy,                                       arginfo_imagepalettecopy)
00890        PHP_FE(imagecreatefromstring,                                  arginfo_imagecreatefromstring)
00891 #endif
00892        PHP_FE(imagecolorclosest,                                      arginfo_imagecolorclosest)
00893 #if HAVE_COLORCLOSESTHWB
00894        PHP_FE(imagecolorclosesthwb,                                   arginfo_imagecolorclosesthwb)
00895 #endif
00896        PHP_FE(imagecolordeallocate,                                   arginfo_imagecolordeallocate)
00897        PHP_FE(imagecolorresolve,                                      arginfo_imagecolorresolve)
00898        PHP_FE(imagecolorexact,                                               arginfo_imagecolorexact)
00899        PHP_FE(imagecolorset,                                                 arginfo_imagecolorset)
00900        PHP_FE(imagecolortransparent,                                  arginfo_imagecolortransparent)
00901        PHP_FE(imagecolorstotal,                                       arginfo_imagecolorstotal)
00902        PHP_FE(imagecolorsforindex,                                    arginfo_imagecolorsforindex)
00903        PHP_FE(imagecopy,                                                     arginfo_imagecopy)
00904 #if HAVE_LIBGD15
00905        PHP_FE(imagecopymerge,                                                arginfo_imagecopymerge)
00906        PHP_FE(imagecopymergegray,                                     arginfo_imagecopymergegray)
00907 #endif
00908        PHP_FE(imagecopyresized,                                       arginfo_imagecopyresized)
00909        PHP_FE(imagecreate,                                                   arginfo_imagecreate)
00910        PHP_FE(imagecreatetruecolor,                                   arginfo_imagecreatetruecolor)
00911        PHP_FE(imageistruecolor,                                       arginfo_imageistruecolor)
00912        PHP_FE(imagetruecolortopalette,                                arginfo_imagetruecolortopalette)
00913        PHP_FE(imagesetthickness,                                      arginfo_imagesetthickness)
00914        PHP_FE(imagefilledarc,                                                arginfo_imagefilledarc)
00915        PHP_FE(imagefilledellipse,                                     arginfo_imagefilledellipse)
00916        PHP_FE(imagealphablending,                                     arginfo_imagealphablending)
00917        PHP_FE(imagesavealpha,                                                arginfo_imagesavealpha)
00918        PHP_FE(imagecolorallocatealpha,                                arginfo_imagecolorallocatealpha)
00919        PHP_FE(imagecolorresolvealpha,                                 arginfo_imagecolorresolvealpha)
00920        PHP_FE(imagecolorclosestalpha,                                 arginfo_imagecolorclosestalpha)
00921        PHP_FE(imagecolorexactalpha,                                   arginfo_imagecolorexactalpha)
00922        PHP_FE(imagecopyresampled,                                     arginfo_imagecopyresampled)
00923 
00924 #ifdef PHP_WIN32
00925        PHP_FE(imagegrabwindow,                                               arginfo_imagegrabwindow)
00926        PHP_FE(imagegrabscreen,                                               arginfo_imagegrabscreen)
00927 #endif
00928 
00929        PHP_FE(imagerotate,                                            arginfo_imagerotate)
00930 
00931 #ifdef HAVE_GD_BUNDLED
00932        PHP_FE(imageantialias,                                                arginfo_imageantialias)
00933 #endif
00934 
00935 #if HAVE_GD_IMAGESETTILE
00936        PHP_FE(imagesettile,                                           arginfo_imagesettile)
00937 #endif
00938 
00939 #if HAVE_GD_IMAGESETBRUSH
00940        PHP_FE(imagesetbrush,                                                 arginfo_imagesetbrush)
00941 #endif
00942 
00943        PHP_FE(imagesetstyle,                                                 arginfo_imagesetstyle)
00944 
00945 #ifdef HAVE_GD_PNG
00946        PHP_FE(imagecreatefrompng,                                     arginfo_imagecreatefrompng)
00947 #endif
00948 #ifdef HAVE_GD_GIF_READ
00949        PHP_FE(imagecreatefromgif,                                     arginfo_imagecreatefromgif)
00950 #endif
00951 #ifdef HAVE_GD_JPG
00952        PHP_FE(imagecreatefromjpeg,                                    arginfo_imagecreatefromjpeg)
00953 #endif
00954 #ifdef HAVE_GD_WBMP
00955        PHP_FE(imagecreatefromwbmp,                                    arginfo_imagecreatefromwbmp)
00956 #endif
00957 #ifdef HAVE_GD_XBM
00958        PHP_FE(imagecreatefromxbm,                                     arginfo_imagecreatefromxbm)
00959 #endif
00960 #if defined(HAVE_GD_XPM) && defined(HAVE_GD_BUNDLED)
00961        PHP_FE(imagecreatefromxpm,                                     arginfo_imagecreatefromxpm)
00962 #endif
00963        PHP_FE(imagecreatefromgd,                                      arginfo_imagecreatefromgd)
00964 #ifdef HAVE_GD_GD2
00965        PHP_FE(imagecreatefromgd2,                                     arginfo_imagecreatefromgd2)
00966        PHP_FE(imagecreatefromgd2part,                                 arginfo_imagecreatefromgd2part)
00967 #endif
00968 #ifdef HAVE_GD_PNG
00969        PHP_FE(imagepng,                                                      arginfo_imagepng)
00970 #endif
00971 #ifdef HAVE_GD_GIF_CREATE
00972        PHP_FE(imagegif,                                                      arginfo_imagegif)
00973 #endif
00974 #ifdef HAVE_GD_JPG
00975        PHP_FE(imagejpeg,                                                     arginfo_imagejpeg)
00976 #endif
00977 #ifdef HAVE_GD_WBMP
00978        PHP_FE(imagewbmp,                               arginfo_imagewbmp)
00979 #endif
00980        PHP_FE(imagegd,                                                              arginfo_imagegd)
00981 #ifdef HAVE_GD_GD2
00982        PHP_FE(imagegd2,                                                      arginfo_imagegd2)
00983 #endif
00984 
00985        PHP_FE(imagedestroy,                                           arginfo_imagedestroy)
00986        PHP_FE(imagegammacorrect,                                      arginfo_imagegammacorrect)
00987        PHP_FE(imagefill,                                                     arginfo_imagefill)
00988        PHP_FE(imagefilledpolygon,                                     arginfo_imagefilledpolygon)
00989        PHP_FE(imagefilledrectangle,                                   arginfo_imagefilledrectangle)
00990        PHP_FE(imagefilltoborder,                                      arginfo_imagefilltoborder)
00991        PHP_FE(imagefontwidth,                                                arginfo_imagefontwidth)
00992        PHP_FE(imagefontheight,                                               arginfo_imagefontheight)
00993        PHP_FE(imageinterlace,                                                arginfo_imageinterlace)
00994        PHP_FE(imageline,                                                     arginfo_imageline)
00995        PHP_FE(imageloadfont,                                                 arginfo_imageloadfont)
00996        PHP_FE(imagepolygon,                                           arginfo_imagepolygon)
00997        PHP_FE(imagerectangle,                                                arginfo_imagerectangle)
00998        PHP_FE(imagesetpixel,                                                 arginfo_imagesetpixel)
00999        PHP_FE(imagestring,                                                   arginfo_imagestring)
01000        PHP_FE(imagestringup,                                                 arginfo_imagestringup)
01001        PHP_FE(imagesx,                                                              arginfo_imagesx)
01002        PHP_FE(imagesy,                                                              arginfo_imagesy)
01003        PHP_FE(imagedashedline,                                               arginfo_imagedashedline)
01004 
01005 #ifdef ENABLE_GD_TTF
01006        PHP_FE(imagettfbbox,                                           arginfo_imagettfbbox)
01007        PHP_FE(imagettftext,                                           arginfo_imagettftext)
01008 #if HAVE_LIBFREETYPE && HAVE_GD_STRINGFTEX
01009        PHP_FE(imageftbbox,                                                   arginfo_imageftbbox)
01010        PHP_FE(imagefttext,                                                   arginfo_imagefttext)
01011 #endif
01012 #endif
01013 
01014 #ifdef HAVE_LIBT1
01015        PHP_FE(imagepsloadfont,                                               arginfo_imagepsloadfont)
01016        /*
01017        PHP_FE(imagepscopyfont,                                               arginfo_imagepscopyfont)
01018        */
01019        PHP_FE(imagepsfreefont,                                               arginfo_imagepsfreefont)
01020        PHP_FE(imagepsencodefont,                                      arginfo_imagepsencodefont)
01021        PHP_FE(imagepsextendfont,                                      arginfo_imagepsextendfont)
01022        PHP_FE(imagepsslantfont,                                       arginfo_imagepsslantfont)
01023        PHP_FE(imagepstext,                                                   arginfo_imagepstext)
01024        PHP_FE(imagepsbbox,                                                   arginfo_imagepsbbox)
01025 #endif
01026        PHP_FE(imagetypes,                                                    arginfo_imagetypes)
01027 
01028 #if defined(HAVE_GD_JPG) && defined(HAVE_GD_WBMP)
01029        PHP_FE(jpeg2wbmp,                                                     arginfo_jpeg2wbmp)
01030 #endif
01031 #if defined(HAVE_GD_PNG) && defined(HAVE_GD_WBMP)
01032        PHP_FE(png2wbmp,                                                      arginfo_png2wbmp)
01033 #endif
01034 #ifdef HAVE_GD_WBMP
01035        PHP_FE(image2wbmp,                                                    arginfo_image2wbmp)
01036 #endif
01037 #if HAVE_GD_BUNDLED
01038        PHP_FE(imagelayereffect,                                       arginfo_imagelayereffect)
01039        PHP_FE(imagexbm,                                arginfo_imagexbm)
01040 #endif
01041 
01042        PHP_FE(imagecolormatch,                                               arginfo_imagecolormatch)
01043 
01044 /* gd filters */
01045        PHP_FE(imagefilter,                                            arginfo_imagefilter)
01046        PHP_FE(imageconvolution,                                       arginfo_imageconvolution)
01047 
01048        PHP_FE_END
01049 };
01050 /* }}} */
01051 
01052 zend_module_entry gd_module_entry = {
01053        STANDARD_MODULE_HEADER,
01054        "gd",
01055        gd_functions,
01056        PHP_MINIT(gd),
01057 #if HAVE_LIBT1 || HAVE_GD_FONTMUTEX
01058        PHP_MSHUTDOWN(gd),
01059 #else
01060        NULL,
01061 #endif
01062        NULL,
01063 #if HAVE_GD_STRINGFT && (HAVE_LIBFREETYPE && (HAVE_GD_FONTCACHESHUTDOWN || HAVE_GD_FREEFONTCACHE))
01064        PHP_RSHUTDOWN(gd),
01065 #else
01066        NULL,
01067 #endif
01068        PHP_MINFO(gd),
01069        NO_VERSION_YET,
01070        STANDARD_MODULE_PROPERTIES
01071 };
01072 
01073 #ifdef COMPILE_DL_GD
01074 ZEND_GET_MODULE(gd)
01075 #endif
01076 
01077 /* {{{ PHP_INI_BEGIN */
01078 PHP_INI_BEGIN()
01079        PHP_INI_ENTRY("gd.jpeg_ignore_warning", "0", PHP_INI_ALL, NULL)
01080 PHP_INI_END()
01081 /* }}} */
01082 
01083 /* {{{ php_free_gd_image
01084  */
01085 static void php_free_gd_image(zend_rsrc_list_entry *rsrc TSRMLS_DC)
01086 {
01087        gdImageDestroy((gdImagePtr) rsrc->ptr);
01088 }
01089 /* }}} */
01090 
01091 /* {{{ php_free_gd_font
01092  */
01093 static void php_free_gd_font(zend_rsrc_list_entry *rsrc TSRMLS_DC)
01094 {
01095        gdFontPtr fp = (gdFontPtr) rsrc->ptr;
01096 
01097        if (fp->data) {
01098               efree(fp->data);
01099        }
01100 
01101        efree(fp);
01102 }
01103 /* }}} */
01104 
01105 /* {{{ PHP_MSHUTDOWN_FUNCTION
01106  */
01107 #if HAVE_LIBT1 || HAVE_GD_FONTMUTEX
01108 PHP_MSHUTDOWN_FUNCTION(gd)
01109 {
01110 #if HAVE_LIBT1
01111        T1_CloseLib();
01112 #endif
01113 #if HAVE_GD_FONTMUTEX && HAVE_LIBFREETYPE
01114        gdFontCacheMutexShutdown();
01115 #endif
01116        UNREGISTER_INI_ENTRIES();
01117        return SUCCESS;
01118 }
01119 #endif
01120 /* }}} */
01121 
01122 
01123 /* {{{ PHP_MINIT_FUNCTION
01124  */
01125 PHP_MINIT_FUNCTION(gd)
01126 {
01127        le_gd = zend_register_list_destructors_ex(php_free_gd_image, NULL, "gd", module_number);
01128        le_gd_font = zend_register_list_destructors_ex(php_free_gd_font, NULL, "gd font", module_number);
01129 
01130 #if HAVE_GD_FONTMUTEX && HAVE_LIBFREETYPE
01131        gdFontCacheMutexSetup();
01132 #endif
01133 #if HAVE_LIBT1
01134        T1_SetBitmapPad(8);
01135        T1_InitLib(NO_LOGFILE | IGNORE_CONFIGFILE | IGNORE_FONTDATABASE);
01136        T1_SetLogLevel(T1LOG_DEBUG);
01137        le_ps_font = zend_register_list_destructors_ex(php_free_ps_font, NULL, "gd PS font", module_number);
01138        le_ps_enc = zend_register_list_destructors_ex(php_free_ps_enc, NULL, "gd PS encoding", module_number);
01139 #endif
01140 
01141        REGISTER_INI_ENTRIES();
01142 
01143        REGISTER_LONG_CONSTANT("IMG_GIF", 1, CONST_CS | CONST_PERSISTENT);
01144        REGISTER_LONG_CONSTANT("IMG_JPG", 2, CONST_CS | CONST_PERSISTENT);
01145        REGISTER_LONG_CONSTANT("IMG_JPEG", 2, CONST_CS | CONST_PERSISTENT);
01146        REGISTER_LONG_CONSTANT("IMG_PNG", 4, CONST_CS | CONST_PERSISTENT);
01147        REGISTER_LONG_CONSTANT("IMG_WBMP", 8, CONST_CS | CONST_PERSISTENT);
01148        REGISTER_LONG_CONSTANT("IMG_XPM", 16, CONST_CS | CONST_PERSISTENT);
01149 #ifdef gdTiled
01150        /* special colours for gd */
01151        REGISTER_LONG_CONSTANT("IMG_COLOR_TILED", gdTiled, CONST_CS | CONST_PERSISTENT);
01152        REGISTER_LONG_CONSTANT("IMG_COLOR_STYLED", gdStyled, CONST_CS | CONST_PERSISTENT);
01153        REGISTER_LONG_CONSTANT("IMG_COLOR_BRUSHED", gdBrushed, CONST_CS | CONST_PERSISTENT);
01154        REGISTER_LONG_CONSTANT("IMG_COLOR_STYLEDBRUSHED", gdStyledBrushed, CONST_CS | CONST_PERSISTENT);
01155        REGISTER_LONG_CONSTANT("IMG_COLOR_TRANSPARENT", gdTransparent, CONST_CS | CONST_PERSISTENT);
01156 #endif
01157        /* for imagefilledarc */
01158        REGISTER_LONG_CONSTANT("IMG_ARC_ROUNDED", gdArc, CONST_CS | CONST_PERSISTENT);
01159        REGISTER_LONG_CONSTANT("IMG_ARC_PIE", gdPie, CONST_CS | CONST_PERSISTENT);
01160        REGISTER_LONG_CONSTANT("IMG_ARC_CHORD", gdChord, CONST_CS | CONST_PERSISTENT);
01161        REGISTER_LONG_CONSTANT("IMG_ARC_NOFILL", gdNoFill, CONST_CS | CONST_PERSISTENT);
01162        REGISTER_LONG_CONSTANT("IMG_ARC_EDGED", gdEdged, CONST_CS | CONST_PERSISTENT);
01163 
01164 /* GD2 image format types */
01165 #ifdef GD2_FMT_RAW
01166        REGISTER_LONG_CONSTANT("IMG_GD2_RAW", GD2_FMT_RAW, CONST_CS | CONST_PERSISTENT);
01167 #endif
01168 #ifdef GD2_FMT_COMPRESSED
01169        REGISTER_LONG_CONSTANT("IMG_GD2_COMPRESSED", GD2_FMT_COMPRESSED, CONST_CS | CONST_PERSISTENT);
01170 #endif
01171 #if HAVE_GD_BUNDLED
01172        REGISTER_LONG_CONSTANT("IMG_EFFECT_REPLACE", gdEffectReplace, CONST_CS | CONST_PERSISTENT);
01173        REGISTER_LONG_CONSTANT("IMG_EFFECT_ALPHABLEND", gdEffectAlphaBlend, CONST_CS | CONST_PERSISTENT);
01174        REGISTER_LONG_CONSTANT("IMG_EFFECT_NORMAL", gdEffectNormal, CONST_CS | CONST_PERSISTENT);
01175        REGISTER_LONG_CONSTANT("IMG_EFFECT_OVERLAY", gdEffectOverlay, CONST_CS | CONST_PERSISTENT);
01176        REGISTER_LONG_CONSTANT("GD_BUNDLED", 1, CONST_CS | CONST_PERSISTENT);
01177 #else
01178        REGISTER_LONG_CONSTANT("GD_BUNDLED", 0, CONST_CS | CONST_PERSISTENT);
01179 #endif
01180 
01181        /* Section Filters */
01182        REGISTER_LONG_CONSTANT("IMG_FILTER_NEGATE", IMAGE_FILTER_NEGATE, CONST_CS | CONST_PERSISTENT);
01183        REGISTER_LONG_CONSTANT("IMG_FILTER_GRAYSCALE", IMAGE_FILTER_GRAYSCALE, CONST_CS | CONST_PERSISTENT);
01184        REGISTER_LONG_CONSTANT("IMG_FILTER_BRIGHTNESS", IMAGE_FILTER_BRIGHTNESS, CONST_CS | CONST_PERSISTENT);
01185        REGISTER_LONG_CONSTANT("IMG_FILTER_CONTRAST", IMAGE_FILTER_CONTRAST, CONST_CS | CONST_PERSISTENT);
01186        REGISTER_LONG_CONSTANT("IMG_FILTER_COLORIZE", IMAGE_FILTER_COLORIZE, CONST_CS | CONST_PERSISTENT);
01187        REGISTER_LONG_CONSTANT("IMG_FILTER_EDGEDETECT", IMAGE_FILTER_EDGEDETECT, CONST_CS | CONST_PERSISTENT);
01188        REGISTER_LONG_CONSTANT("IMG_FILTER_GAUSSIAN_BLUR", IMAGE_FILTER_GAUSSIAN_BLUR, CONST_CS | CONST_PERSISTENT);
01189        REGISTER_LONG_CONSTANT("IMG_FILTER_SELECTIVE_BLUR", IMAGE_FILTER_SELECTIVE_BLUR, CONST_CS | CONST_PERSISTENT);
01190        REGISTER_LONG_CONSTANT("IMG_FILTER_EMBOSS", IMAGE_FILTER_EMBOSS, CONST_CS | CONST_PERSISTENT);
01191        REGISTER_LONG_CONSTANT("IMG_FILTER_MEAN_REMOVAL", IMAGE_FILTER_MEAN_REMOVAL, CONST_CS | CONST_PERSISTENT);
01192        REGISTER_LONG_CONSTANT("IMG_FILTER_SMOOTH", IMAGE_FILTER_SMOOTH, CONST_CS | CONST_PERSISTENT);
01193        REGISTER_LONG_CONSTANT("IMG_FILTER_PIXELATE", IMAGE_FILTER_PIXELATE, CONST_CS | CONST_PERSISTENT);
01194        /* End Section Filters */
01195 
01196 #ifdef GD_VERSION_STRING
01197        REGISTER_STRING_CONSTANT("GD_VERSION", GD_VERSION_STRING, CONST_CS | CONST_PERSISTENT);
01198 #endif
01199 
01200 #if defined(GD_MAJOR_VERSION) && defined(GD_MINOR_VERSION) && defined(GD_RELEASE_VERSION) && defined(GD_EXTRA_VERSION)
01201        REGISTER_LONG_CONSTANT("GD_MAJOR_VERSION", GD_MAJOR_VERSION, CONST_CS | CONST_PERSISTENT);
01202        REGISTER_LONG_CONSTANT("GD_MINOR_VERSION", GD_MINOR_VERSION, CONST_CS | CONST_PERSISTENT);
01203        REGISTER_LONG_CONSTANT("GD_RELEASE_VERSION", GD_RELEASE_VERSION, CONST_CS | CONST_PERSISTENT);
01204        REGISTER_STRING_CONSTANT("GD_EXTRA_VERSION", GD_EXTRA_VERSION, CONST_CS | CONST_PERSISTENT);
01205 #endif
01206 
01207 
01208 #ifdef HAVE_GD_PNG
01209 
01210        /*
01211         * cannot include #include "png.h"
01212         * /usr/include/pngconf.h:310:2: error: #error png.h already includes setjmp.h with some additional fixup.
01213         * as error, use the values for now...
01214         */
01215        REGISTER_LONG_CONSTANT("PNG_NO_FILTER",       0x00, CONST_CS | CONST_PERSISTENT);
01216        REGISTER_LONG_CONSTANT("PNG_FILTER_NONE",   0x08, CONST_CS | CONST_PERSISTENT);
01217        REGISTER_LONG_CONSTANT("PNG_FILTER_SUB",    0x10, CONST_CS | CONST_PERSISTENT);
01218        REGISTER_LONG_CONSTANT("PNG_FILTER_UP",     0x20, CONST_CS | CONST_PERSISTENT);
01219        REGISTER_LONG_CONSTANT("PNG_FILTER_AVG",    0x40, CONST_CS | CONST_PERSISTENT);
01220        REGISTER_LONG_CONSTANT("PNG_FILTER_PAETH",  0x80, CONST_CS | CONST_PERSISTENT);
01221        REGISTER_LONG_CONSTANT("PNG_ALL_FILTERS",   0x08 | 0x10 | 0x20 | 0x40 | 0x80, CONST_CS | CONST_PERSISTENT);
01222 #endif
01223 
01224        return SUCCESS;
01225 }
01226 /* }}} */
01227 
01228 /* {{{ PHP_RSHUTDOWN_FUNCTION
01229  */
01230 #if HAVE_GD_STRINGFT && (HAVE_LIBFREETYPE && (HAVE_GD_FONTCACHESHUTDOWN || HAVE_GD_FREEFONTCACHE))
01231 PHP_RSHUTDOWN_FUNCTION(gd)
01232 {
01233 #if HAVE_GD_FONTCACHESHUTDOWN
01234        gdFontCacheShutdown();
01235 #else
01236        gdFreeFontCache();
01237 #endif
01238        return SUCCESS;
01239 }
01240 #endif
01241 /* }}} */
01242 
01243 #if HAVE_GD_BUNDLED
01244 #define PHP_GD_VERSION_STRING "bundled (2.0.34 compatible)"
01245 #else
01246 #define PHP_GD_VERSION_STRING "2.0"
01247 #endif
01248 
01249 /* {{{ PHP_MINFO_FUNCTION
01250  */
01251 PHP_MINFO_FUNCTION(gd)
01252 {
01253        php_info_print_table_start();
01254        php_info_print_table_row(2, "GD Support", "enabled");
01255 
01256        /* need to use a PHPAPI function here because it is external module in windows */
01257 
01258        php_info_print_table_row(2, "GD Version", PHP_GD_VERSION_STRING);
01259 
01260 #ifdef ENABLE_GD_TTF
01261        php_info_print_table_row(2, "FreeType Support", "enabled");
01262 #if HAVE_LIBFREETYPE
01263        php_info_print_table_row(2, "FreeType Linkage", "with freetype");
01264        {
01265               char tmp[256];
01266 
01267 #ifdef FREETYPE_PATCH
01268               snprintf(tmp, sizeof(tmp), "%d.%d.%d", FREETYPE_MAJOR, FREETYPE_MINOR, FREETYPE_PATCH);
01269 #elif defined(FREETYPE_MAJOR)
01270               snprintf(tmp, sizeof(tmp), "%d.%d", FREETYPE_MAJOR, FREETYPE_MINOR);
01271 #else
01272               snprintf(tmp, sizeof(tmp), "1.x");
01273 #endif
01274               php_info_print_table_row(2, "FreeType Version", tmp);
01275        }
01276 #else
01277        php_info_print_table_row(2, "FreeType Linkage", "with unknown library");
01278 #endif
01279 #endif
01280 
01281 #ifdef HAVE_LIBT1
01282        php_info_print_table_row(2, "T1Lib Support", "enabled");
01283 #endif
01284 
01285 /* this next part is stupid ... if I knew better, I'd put them all on one row (cmv) */
01286 
01287 #ifdef HAVE_GD_GIF_READ
01288        php_info_print_table_row(2, "GIF Read Support", "enabled");
01289 #endif
01290 #ifdef HAVE_GD_GIF_CREATE
01291        php_info_print_table_row(2, "GIF Create Support", "enabled");
01292 #endif
01293 #ifdef HAVE_GD_JPG
01294        {
01295               char tmp[12];
01296               snprintf(tmp, sizeof(tmp), "%s", gdJpegGetVersionString());
01297               php_info_print_table_row(2, "JPEG Support", "enabled");
01298               php_info_print_table_row(2, "libJPEG Version", tmp);
01299        }
01300 #endif
01301 
01302 #ifdef HAVE_GD_PNG
01303        php_info_print_table_row(2, "PNG Support", "enabled");
01304        php_info_print_table_row(2, "libPNG Version", gdPngGetVersionString());
01305 #endif
01306 #ifdef HAVE_GD_WBMP
01307        php_info_print_table_row(2, "WBMP Support", "enabled");
01308 #endif
01309 #if defined(HAVE_GD_XPM) && defined(HAVE_GD_BUNDLED)
01310        php_info_print_table_row(2, "XPM Support", "enabled");
01311 #endif
01312 #ifdef HAVE_GD_XBM
01313        php_info_print_table_row(2, "XBM Support", "enabled");
01314 #endif
01315 #if defined(USE_GD_JISX0208) && defined(HAVE_GD_BUNDLED)
01316        php_info_print_table_row(2, "JIS-mapped Japanese Font Support", "enabled");
01317 #endif
01318        php_info_print_table_end();
01319        DISPLAY_INI_ENTRIES();
01320 }
01321 /* }}} */
01322 
01323 /* {{{ proto array gd_info()
01324  */
01325 PHP_FUNCTION(gd_info)
01326 {
01327        if (zend_parse_parameters_none() == FAILURE) {
01328               RETURN_FALSE;
01329        }
01330 
01331        array_init(return_value);
01332 
01333        add_assoc_string(return_value, "GD Version", PHP_GD_VERSION_STRING, 1);
01334 
01335 #ifdef ENABLE_GD_TTF
01336        add_assoc_bool(return_value, "FreeType Support", 1);
01337 #if HAVE_LIBFREETYPE
01338        add_assoc_string(return_value, "FreeType Linkage", "with freetype", 1);
01339 #else
01340        add_assoc_string(return_value, "FreeType Linkage", "with unknown library", 1);
01341 #endif
01342 #else
01343        add_assoc_bool(return_value, "FreeType Support", 0);
01344 #endif
01345 
01346 #ifdef HAVE_LIBT1
01347        add_assoc_bool(return_value, "T1Lib Support", 1);
01348 #else
01349        add_assoc_bool(return_value, "T1Lib Support", 0);
01350 #endif
01351 #ifdef HAVE_GD_GIF_READ
01352        add_assoc_bool(return_value, "GIF Read Support", 1);
01353 #else
01354        add_assoc_bool(return_value, "GIF Read Support", 0);
01355 #endif
01356 #ifdef HAVE_GD_GIF_CREATE
01357        add_assoc_bool(return_value, "GIF Create Support", 1);
01358 #else
01359        add_assoc_bool(return_value, "GIF Create Support", 0);
01360 #endif
01361 #ifdef HAVE_GD_JPG
01362        add_assoc_bool(return_value, "JPEG Support", 1);
01363 #else
01364        add_assoc_bool(return_value, "JPEG Support", 0);
01365 #endif
01366 #ifdef HAVE_GD_PNG
01367        add_assoc_bool(return_value, "PNG Support", 1);
01368 #else
01369        add_assoc_bool(return_value, "PNG Support", 0);
01370 #endif
01371 #ifdef HAVE_GD_WBMP
01372        add_assoc_bool(return_value, "WBMP Support", 1);
01373 #else
01374        add_assoc_bool(return_value, "WBMP Support", 0);
01375 #endif
01376 #if defined(HAVE_GD_XPM) && defined(HAVE_GD_BUNDLED)
01377        add_assoc_bool(return_value, "XPM Support", 1);
01378 #else
01379        add_assoc_bool(return_value, "XPM Support", 0);
01380 #endif
01381 #ifdef HAVE_GD_XBM
01382        add_assoc_bool(return_value, "XBM Support", 1);
01383 #else
01384        add_assoc_bool(return_value, "XBM Support", 0);
01385 #endif
01386 #if defined(USE_GD_JISX0208) && defined(HAVE_GD_BUNDLED)
01387        add_assoc_bool(return_value, "JIS-mapped Japanese Font Support", 1);
01388 #else
01389        add_assoc_bool(return_value, "JIS-mapped Japanese Font Support", 0);
01390 #endif
01391 }
01392 /* }}} */
01393 
01394 /* Need this for cpdf. See also comment in file.c php3i_get_le_fp() */
01395 PHP_GD_API int phpi_get_le_gd(void)
01396 {
01397        return le_gd;
01398 }
01399 /* }}} */
01400 
01401 #ifndef HAVE_GDIMAGECOLORRESOLVE
01402 
01403 /* {{{ gdImageColorResolve
01404  */
01405 /********************************************************************/
01406 /* gdImageColorResolve is a replacement for the old fragment:       */
01407 /*                                                                  */
01408 /*      if ((color=gdImageColorExact(im,R,G,B)) < 0)                */
01409 /*        if ((color=gdImageColorAllocate(im,R,G,B)) < 0)           */
01410 /*          color=gdImageColorClosest(im,R,G,B);                    */
01411 /*                                                                  */
01412 /* in a single function                                             */
01413 
01414 int gdImageColorResolve(gdImagePtr im, int r, int g, int b)
01415 {
01416        int c;
01417        int ct = -1;
01418        int op = -1;
01419        long rd, gd, bd, dist;
01420        long mindist = 3*255*255;  /* init to max poss dist */
01421 
01422        for (c = 0; c < im->colorsTotal; c++) {
01423               if (im->open[c]) {
01424                      op = c;             /* Save open slot */
01425                      continue;           /* Color not in use */
01426               }
01427               rd = (long) (im->red  [c] - r);
01428               gd = (long) (im->green[c] - g);
01429               bd = (long) (im->blue [c] - b);
01430               dist = rd * rd + gd * gd + bd * bd;
01431               if (dist < mindist) {
01432                      if (dist == 0) {
01433                             return c;       /* Return exact match color */
01434                      }
01435                      mindist = dist;
01436                      ct = c;
01437               }
01438        }
01439        /* no exact match.  We now know closest, but first try to allocate exact */
01440        if (op == -1) {
01441               op = im->colorsTotal;
01442               if (op == gdMaxColors) {    /* No room for more colors */
01443                      return ct;          /* Return closest available color */
01444               }
01445               im->colorsTotal++;
01446        }
01447        im->red  [op] = r;
01448        im->green[op] = g;
01449        im->blue [op] = b;
01450        im->open [op] = 0;
01451        return op;                  /* Return newly allocated color */
01452 }
01453 /* }}} */
01454 
01455 #endif
01456 
01457 #define FLIPWORD(a) (((a & 0xff000000) >> 24) | ((a & 0x00ff0000) >> 8) | ((a & 0x0000ff00) << 8) | ((a & 0x000000ff) << 24))
01458 
01459 /* {{{ proto int imageloadfont(string filename)
01460    Load a new font */
01461 PHP_FUNCTION(imageloadfont)
01462 {
01463        char *file;
01464        int file_name, hdr_size = sizeof(gdFont) - sizeof(char *);
01465        int ind, body_size, n = 0, b, i, body_size_check;
01466        gdFontPtr font;
01467        php_stream *stream;
01468 
01469        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_name) == FAILURE) {
01470               return;
01471        }
01472 
01473        stream = php_stream_open_wrapper(file, "rb", ENFORCE_SAFE_MODE | IGNORE_PATH | IGNORE_URL_WIN | REPORT_ERRORS, NULL);
01474        if (stream == NULL) {
01475               RETURN_FALSE;
01476        }
01477 
01478        /* Only supports a architecture-dependent binary dump format
01479         * at the moment.
01480         * The file format is like this on machines with 32-byte integers:
01481         *
01482         * byte 0-3:   (int) number of characters in the font
01483         * byte 4-7:   (int) value of first character in the font (often 32, space)
01484         * byte 8-11:  (int) pixel width of each character
01485         * byte 12-15: (int) pixel height of each character
01486         * bytes 16-:  (char) array with character data, one byte per pixel
01487         *                    in each character, for a total of
01488         *                    (nchars*width*height) bytes.
01489         */
01490        font = (gdFontPtr) emalloc(sizeof(gdFont));
01491        b = 0;
01492        while (b < hdr_size && (n = php_stream_read(stream, (char*)&font[b], hdr_size - b))) {
01493               b += n;
01494        }
01495 
01496        if (!n) {
01497               efree(font);
01498               if (php_stream_eof(stream)) {
01499                      php_error_docref(NULL TSRMLS_CC, E_WARNING, "End of file while reading header");
01500               } else {
01501                      php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error while reading header");
01502               }
01503               php_stream_close(stream);
01504               RETURN_FALSE;
01505        }
01506        i = php_stream_tell(stream);
01507        php_stream_seek(stream, 0, SEEK_END);
01508        body_size_check = php_stream_tell(stream) - hdr_size;
01509        php_stream_seek(stream, i, SEEK_SET);
01510 
01511        body_size = font->w * font->h * font->nchars;
01512        if (body_size != body_size_check) {
01513               font->w = FLIPWORD(font->w);
01514               font->h = FLIPWORD(font->h);
01515               font->nchars = FLIPWORD(font->nchars);
01516               body_size = font->w * font->h * font->nchars;
01517        }
01518 
01519        if (overflow2(font->nchars, font->h)) {
01520               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error reading font, invalid font header");
01521               efree(font);
01522               php_stream_close(stream);
01523               RETURN_FALSE;
01524        }
01525        if (overflow2(font->nchars * font->h, font->w )) {
01526               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error reading font, invalid font header");
01527               efree(font);
01528               php_stream_close(stream);
01529               RETURN_FALSE;
01530        }
01531 
01532        if (body_size != body_size_check) {
01533               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error reading font");
01534               efree(font);
01535               php_stream_close(stream);
01536               RETURN_FALSE;
01537        }
01538 
01539        font->data = emalloc(body_size);
01540        b = 0;
01541        while (b < body_size && (n = php_stream_read(stream, &font->data[b], body_size - b))) {
01542               b += n;
01543        }
01544 
01545        if (!n) {
01546               efree(font->data);
01547               efree(font);
01548               if (php_stream_eof(stream)) {
01549                      php_error_docref(NULL TSRMLS_CC, E_WARNING, "End of file while reading body");
01550               } else {
01551                      php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error while reading body");
01552               }
01553               php_stream_close(stream);
01554               RETURN_FALSE;
01555        }
01556        php_stream_close(stream);
01557 
01558        /* Adding 5 to the font index so we will never have font indices
01559         * that overlap with the old fonts (with indices 1-5).  The first
01560         * list index given out is always 1.
01561         */
01562        ind = 5 + zend_list_insert(font, le_gd_font);
01563 
01564        RETURN_LONG(ind);
01565 }
01566 /* }}} */
01567 
01568 /* {{{ proto bool imagesetstyle(resource im, array styles)
01569    Set the line drawing styles for use with imageline and IMG_COLOR_STYLED. */
01570 PHP_FUNCTION(imagesetstyle)
01571 {
01572        zval *IM, *styles;
01573        gdImagePtr im;
01574        int * stylearr;
01575        int index;
01576        HashPosition pos;
01577 
01578        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ra", &IM, &styles) == FAILURE)  {
01579               return;
01580        }
01581 
01582        ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
01583 
01584        /* copy the style values in the stylearr */
01585        stylearr = safe_emalloc(sizeof(int), zend_hash_num_elements(HASH_OF(styles)), 0);
01586 
01587        zend_hash_internal_pointer_reset_ex(HASH_OF(styles), &pos);
01588 
01589        for (index = 0;; zend_hash_move_forward_ex(HASH_OF(styles), &pos))    {
01590               zval ** item;
01591 
01592               if (zend_hash_get_current_data_ex(HASH_OF(styles), (void **) &item, &pos) == FAILURE) {
01593                      break;
01594               }
01595 
01596               convert_to_long_ex(item);
01597 
01598               stylearr[index++] = Z_LVAL_PP(item);
01599        }
01600 
01601        gdImageSetStyle(im, stylearr, index);
01602 
01603        efree(stylearr);
01604 
01605        RETURN_TRUE;
01606 }
01607 /* }}} */
01608 
01609 /* {{{ proto resource imagecreatetruecolor(int x_size, int y_size)
01610    Create a new true color image */
01611 PHP_FUNCTION(imagecreatetruecolor)
01612 {
01613        long x_size, y_size;
01614        gdImagePtr im;
01615 
01616        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &x_size, &y_size) == FAILURE) {
01617               return;
01618        }
01619 
01620        if (x_size <= 0 || y_size <= 0 || x_size >= INT_MAX || y_size >= INT_MAX) {
01621               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid image dimensions");
01622               RETURN_FALSE;
01623        }
01624 
01625        im = gdImageCreateTrueColor(x_size, y_size);
01626 
01627        if (!im) {
01628               RETURN_FALSE;
01629        }
01630 
01631        ZEND_REGISTER_RESOURCE(return_value, im, le_gd);
01632 }
01633 /* }}} */
01634 
01635 /* {{{ proto bool imageistruecolor(resource im)
01636    return true if the image uses truecolor */
01637 PHP_FUNCTION(imageistruecolor)
01638 {
01639        zval *IM;
01640        gdImagePtr im;
01641 
01642        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &IM) == FAILURE) {
01643               return;
01644        }
01645 
01646        ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
01647 
01648        RETURN_BOOL(im->trueColor);
01649 }
01650 /* }}} */
01651 
01652 /* {{{ proto void imagetruecolortopalette(resource im, bool ditherFlag, int colorsWanted)
01653    Convert a true colour image to a palette based image with a number of colours, optionally using dithering. */
01654 PHP_FUNCTION(imagetruecolortopalette)
01655 {
01656        zval *IM;
01657        zend_bool dither;
01658        long ncolors;
01659        gdImagePtr im;
01660 
01661        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rbl", &IM, &dither, &ncolors) == FAILURE)  {
01662               return;
01663        }
01664 
01665        ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
01666 
01667        if (ncolors <= 0) {
01668               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Number of colors has to be greater than zero");
01669               RETURN_FALSE;
01670        }
01671        gdImageTrueColorToPalette(im, dither, ncolors);
01672 
01673        RETURN_TRUE;
01674 }
01675 /* }}} */
01676 
01677 /* {{{ proto bool imagecolormatch(resource im1, resource im2)
01678    Makes the colors of the palette version of an image more closely match the true color version */
01679 PHP_FUNCTION(imagecolormatch)
01680 {
01681        zval *IM1, *IM2;
01682        gdImagePtr im1, im2;
01683        int result;
01684 
01685        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr", &IM1, &IM2) == FAILURE) {
01686               return;
01687        }
01688 
01689        ZEND_FETCH_RESOURCE(im1, gdImagePtr, &IM1, -1, "Image", le_gd);
01690        ZEND_FETCH_RESOURCE(im2, gdImagePtr, &IM2, -1, "Image", le_gd);
01691 
01692        result = gdImageColorMatch(im1, im2);
01693        switch (result) {
01694               case -1:
01695                      php_error_docref(NULL TSRMLS_CC, E_WARNING, "Image1 must be TrueColor" );
01696                      RETURN_FALSE;
01697                      break;
01698               case -2:
01699                      php_error_docref(NULL TSRMLS_CC, E_WARNING, "Image2 must be Palette" );
01700                      RETURN_FALSE;
01701                      break;
01702               case -3:
01703                      php_error_docref(NULL TSRMLS_CC, E_WARNING, "Image1 and Image2 must be the same size" );
01704                      RETURN_FALSE;
01705                      break;
01706               case -4:
01707                      php_error_docref(NULL TSRMLS_CC, E_WARNING, "Image2 must have at least one color" );
01708                      RETURN_FALSE;
01709                      break;
01710        }
01711 
01712        RETURN_TRUE;
01713 }
01714 /* }}} */
01715 
01716 /* {{{ proto bool imagesetthickness(resource im, int thickness)
01717    Set line thickness for drawing lines, ellipses, rectangles, polygons etc. */
01718 PHP_FUNCTION(imagesetthickness)
01719 {
01720        zval *IM;
01721        long thick;
01722        gdImagePtr im;
01723 
01724        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &IM, &thick) == FAILURE) {
01725               return;
01726        }
01727 
01728        ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
01729 
01730        gdImageSetThickness(im, thick);
01731 
01732        RETURN_TRUE;
01733 }
01734 /* }}} */
01735 
01736 /* {{{ proto bool imagefilledellipse(resource im, int cx, int cy, int w, int h, int color)
01737    Draw an ellipse */
01738 PHP_FUNCTION(imagefilledellipse)
01739 {
01740        zval *IM;
01741        long cx, cy, w, h, color;
01742        gdImagePtr im;
01743 
01744        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllll", &IM, &cx, &cy, &w, &h, &color) == FAILURE) {
01745               return;
01746        }
01747 
01748        ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
01749 
01750        gdImageFilledEllipse(im, cx, cy, w, h, color);
01751 
01752        RETURN_TRUE;
01753 }
01754 /* }}} */
01755 
01756 /* {{{ proto bool imagefilledarc(resource im, int cx, int cy, int w, int h, int s, int e, int col, int style)
01757    Draw a filled partial ellipse */
01758 PHP_FUNCTION(imagefilledarc)
01759 {
01760        zval *IM;
01761        long cx, cy, w, h, ST, E, col, style;
01762        gdImagePtr im;
01763        int e, st;
01764        
01765        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllllllll", &IM, &cx, &cy, &w, &h, &ST, &E, &col, &style) == FAILURE) {
01766               return;
01767        }
01768 
01769        ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
01770 
01771        e = E;
01772        if (e < 0) {
01773               e %= 360;
01774        }
01775 
01776        st = ST;
01777        if (st < 0) {
01778               st %= 360;
01779        }
01780 
01781        gdImageFilledArc(im, cx, cy, w, h, st, e, col, style);
01782 
01783        RETURN_TRUE;
01784 }
01785 /* }}} */
01786 
01787 /* {{{ proto bool imagealphablending(resource im, bool on)
01788    Turn alpha blending mode on or off for the given image */
01789 PHP_FUNCTION(imagealphablending)
01790 {
01791        zval *IM;
01792        zend_bool blend;
01793        gdImagePtr im;
01794 
01795        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rb", &IM, &blend) == FAILURE) {
01796               return;
01797        }
01798 
01799        ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
01800        gdImageAlphaBlending(im, blend);
01801 
01802        RETURN_TRUE;
01803 }
01804 /* }}} */
01805 
01806 /* {{{ proto bool imagesavealpha(resource im, bool on)
01807    Include alpha channel to a saved image */
01808 PHP_FUNCTION(imagesavealpha)
01809 {
01810        zval *IM;
01811        zend_bool save;
01812        gdImagePtr im;
01813 
01814        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rb", &IM, &save) == FAILURE) {
01815               return;
01816        }
01817 
01818        ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
01819        gdImageSaveAlpha(im, save);
01820 
01821        RETURN_TRUE;
01822 }
01823 /* }}} */
01824 
01825 #if HAVE_GD_BUNDLED
01826 /* {{{ proto bool imagelayereffect(resource im, int effect)
01827    Set the alpha blending flag to use the bundled libgd layering effects */
01828 PHP_FUNCTION(imagelayereffect)
01829 {
01830        zval *IM;
01831        long effect;
01832        gdImagePtr im;
01833 
01834        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &IM, &effect) == FAILURE) {
01835               return;
01836        }
01837 
01838        ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
01839        gdImageAlphaBlending(im, effect);
01840 
01841        RETURN_TRUE;
01842 }
01843 /* }}} */
01844 #endif
01845 
01846 /* {{{ proto int imagecolorallocatealpha(resource im, int red, int green, int blue, int alpha)
01847    Allocate a color with an alpha level.  Works for true color and palette based images */
01848 PHP_FUNCTION(imagecolorallocatealpha)
01849 {
01850        zval *IM;
01851        long red, green, blue, alpha;
01852        gdImagePtr im;
01853        int ct = (-1);
01854 
01855        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll", &IM, &red, &green, &blue, &alpha) == FAILURE) {
01856               RETURN_FALSE;
01857        }
01858 
01859        ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
01860        ct = gdImageColorAllocateAlpha(im, red, green, blue, alpha);
01861        if (ct < 0) {
01862               RETURN_FALSE;
01863        }
01864        RETURN_LONG((long)ct);
01865 }
01866 /* }}} */
01867 
01868 /* {{{ proto int imagecolorresolvealpha(resource im, int red, int green, int blue, int alpha)
01869    Resolve/Allocate a colour with an alpha level.  Works for true colour and palette based images */
01870 PHP_FUNCTION(imagecolorresolvealpha)
01871 {
01872        zval *IM;
01873        long red, green, blue, alpha;
01874        gdImagePtr im;
01875 
01876        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll", &IM, &red, &green, &blue, &alpha) == FAILURE) {
01877               return;
01878        }
01879 
01880        ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
01881 
01882        RETURN_LONG(gdImageColorResolveAlpha(im, red, green, blue, alpha));
01883 }
01884 /* }}} */
01885 
01886 /* {{{ proto int imagecolorclosestalpha(resource im, int red, int green, int blue, int alpha)
01887    Find the closest matching colour with alpha transparency */
01888 PHP_FUNCTION(imagecolorclosestalpha)
01889 {
01890        zval *IM;
01891        long red, green, blue, alpha;
01892        gdImagePtr im;
01893 
01894        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll", &IM, &red, &green, &blue, &alpha) == FAILURE) {
01895               return;
01896        }
01897 
01898        ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
01899 
01900        RETURN_LONG(gdImageColorClosestAlpha(im, red, green, blue, alpha));
01901 }
01902 /* }}} */
01903 
01904 /* {{{ proto int imagecolorexactalpha(resource im, int red, int green, int blue, int alpha)
01905    Find exact match for colour with transparency */
01906 PHP_FUNCTION(imagecolorexactalpha)
01907 {
01908        zval *IM;
01909        long red, green, blue, alpha;
01910        gdImagePtr im;
01911 
01912        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll", &IM, &red, &green, &blue, &alpha) == FAILURE) {
01913               return;
01914        }
01915 
01916        ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
01917 
01918        RETURN_LONG(gdImageColorExactAlpha(im, red, green, blue, alpha));
01919 }
01920 /* }}} */
01921 
01922 /* {{{ 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)
01923    Copy and resize part of an image using resampling to help ensure clarity */
01924 PHP_FUNCTION(imagecopyresampled)
01925 {
01926        zval *SIM, *DIM;
01927        long SX, SY, SW, SH, DX, DY, DW, DH;
01928        gdImagePtr im_dst, im_src;
01929        int srcH, srcW, dstH, dstW, srcY, srcX, dstY, dstX;
01930 
01931        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrllllllll", &DIM, &SIM, &DX, &DY, &SX, &SY, &DW, &DH, &SW, &SH) == FAILURE) {
01932               return;
01933        }
01934 
01935        ZEND_FETCH_RESOURCE(im_dst, gdImagePtr, &DIM, -1, "Image", le_gd);
01936        ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
01937 
01938        srcX = SX;
01939        srcY = SY;
01940        srcH = SH;
01941        srcW = SW;
01942        dstX = DX;
01943        dstY = DY;
01944        dstH = DH;
01945        dstW = DW;
01946 
01947        gdImageCopyResampled(im_dst, im_src, dstX, dstY, srcX, srcY, dstW, dstH, srcW, srcH);
01948 
01949        RETURN_TRUE;
01950 }
01951 /* }}} */
01952 
01953 #ifdef PHP_WIN32
01954 /* {{{ proto resource imagegrabwindow(int window_handle [, int client_area])
01955    Grab a window or its client area using a windows handle (HWND property in COM instance) */
01956 PHP_FUNCTION(imagegrabwindow)
01957 {
01958        HWND window;
01959        long client_area = 0;
01960        RECT rc = {0};
01961        RECT rc_win = {0};
01962        int Width, Height;
01963        HDC           hdc;
01964        HDC memDC;
01965        HBITMAP memBM;
01966        HBITMAP hOld;
01967        HINSTANCE handle;
01968        long lwindow_handle;
01969        typedef BOOL (WINAPI *tPrintWindow)(HWND, HDC,UINT);
01970        tPrintWindow pPrintWindow = 0;
01971        gdImagePtr im;
01972 
01973        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l", &lwindow_handle, &client_area) == FAILURE) {
01974               RETURN_FALSE;
01975        }
01976 
01977        window = (HWND) lwindow_handle;
01978 
01979        if (!IsWindow(window)) {
01980               php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Invalid window handle");
01981               RETURN_FALSE;
01982        }
01983 
01984        hdc           = GetDC(0);
01985 
01986        if (client_area) {
01987               GetClientRect(window, &rc);
01988               Width = rc.right;
01989               Height = rc.bottom;
01990        } else {
01991               GetWindowRect(window, &rc);
01992               Width  = rc.right - rc.left;
01993               Height = rc.bottom - rc.top;
01994        }
01995 
01996        Width         = (Width/4)*4;
01997 
01998        memDC  = CreateCompatibleDC(hdc);
01999        memBM  = CreateCompatibleBitmap(hdc, Width, Height);
02000        hOld   = (HBITMAP) SelectObject (memDC, memBM);
02001 
02002 
02003        handle = LoadLibrary("User32.dll");
02004        if ( handle == 0 ) {
02005               goto clean;
02006        }
02007        pPrintWindow = (tPrintWindow) GetProcAddress(handle, "PrintWindow");  
02008 
02009        if ( pPrintWindow )  {
02010               pPrintWindow(window, memDC, (UINT) client_area);
02011        } else {
02012               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Windows API too old");
02013               goto clean;
02014        }
02015 
02016        FreeLibrary(handle);
02017 
02018        im = gdImageCreateTrueColor(Width, Height);
02019        if (im) {
02020               int x,y;
02021               for (y=0; y <= Height; y++) {
02022                      for (x=0; x <= Width; x++) {
02023                             int c = GetPixel(memDC, x,y);
02024                             gdImageSetPixel(im, x, y, gdTrueColor(GetRValue(c), GetGValue(c), GetBValue(c)));
02025                      }
02026               }
02027        }
02028 
02029 clean:
02030        SelectObject(memDC,hOld);
02031        DeleteObject(memBM);
02032        DeleteDC(memDC);
02033        ReleaseDC( 0, hdc );
02034 
02035        if (!im) {
02036               RETURN_FALSE;
02037        } else {
02038               ZEND_REGISTER_RESOURCE(return_value, im, le_gd);
02039        }
02040 }
02041 /* }}} */
02042 
02043 /* {{{ proto resource imagegrabscreen()
02044    Grab a screenshot */
02045 PHP_FUNCTION(imagegrabscreen)
02046 {
02047        HWND window = GetDesktopWindow();
02048        RECT rc = {0};
02049        int Width, Height;
02050        HDC           hdc;
02051        HDC memDC;
02052        HBITMAP memBM;
02053        HBITMAP hOld;
02054        typedef BOOL (WINAPI *tPrintWindow)(HWND, HDC,UINT);
02055        tPrintWindow pPrintWindow = 0;
02056        gdImagePtr im;
02057        hdc           = GetDC(0);
02058 
02059        if (zend_parse_parameters_none() == FAILURE) {
02060               return;
02061        }
02062 
02063        if (!hdc) {
02064               RETURN_FALSE;
02065        }
02066 
02067        GetWindowRect(window, &rc);
02068        Width  = rc.right - rc.left;
02069        Height = rc.bottom - rc.top;
02070 
02071        Width         = (Width/4)*4;
02072 
02073        memDC  = CreateCompatibleDC(hdc);
02074        memBM  = CreateCompatibleBitmap(hdc, Width, Height);
02075        hOld   = (HBITMAP) SelectObject (memDC, memBM);
02076        BitBlt( memDC, 0, 0, Width, Height , hdc, rc.left, rc.top , SRCCOPY );
02077 
02078        im = gdImageCreateTrueColor(Width, Height);
02079        if (im) {
02080               int x,y;
02081               for (y=0; y <= Height; y++) {
02082                      for (x=0; x <= Width; x++) {
02083                             int c = GetPixel(memDC, x,y);
02084                             gdImageSetPixel(im, x, y, gdTrueColor(GetRValue(c), GetGValue(c), GetBValue(c)));
02085                      }
02086               }
02087        }
02088 
02089        SelectObject(memDC,hOld);
02090        DeleteObject(memBM);
02091        DeleteDC(memDC);
02092        ReleaseDC( 0, hdc );
02093 
02094        if (!im) {
02095               RETURN_FALSE;
02096        } else {
02097               ZEND_REGISTER_RESOURCE(return_value, im, le_gd);
02098        }
02099 }
02100 /* }}} */
02101 #endif /* PHP_WIN32 */
02102 
02103 /* {{{ proto resource imagerotate(resource src_im, float angle, int bgdcolor [, int ignoretransparent])
02104    Rotate an image using a custom angle */
02105 PHP_FUNCTION(imagerotate)
02106 {
02107        zval *SIM;
02108        gdImagePtr im_dst, im_src;
02109        double degrees;
02110        long color;
02111        long ignoretransparent = 0;
02112 
02113        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rdl|l", &SIM, &degrees, &color, &ignoretransparent) == FAILURE) {
02114               RETURN_FALSE;
02115        }
02116 
02117        ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
02118 
02119        im_dst = gdImageRotate(im_src, degrees, color, ignoretransparent);
02120 
02121        if (im_dst != NULL) {
02122               ZEND_REGISTER_RESOURCE(return_value, im_dst, le_gd);
02123        } else {
02124               RETURN_FALSE;
02125        }
02126 }
02127 /* }}} */
02128 
02129 #if HAVE_GD_IMAGESETTILE
02130 /* {{{ proto bool imagesettile(resource image, resource tile)
02131    Set the tile image to $tile when filling $image with the "IMG_COLOR_TILED" color */
02132 PHP_FUNCTION(imagesettile)
02133 {
02134        zval *IM, *TILE;
02135        gdImagePtr im, tile;
02136 
02137        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr", &IM, &TILE) == FAILURE) {
02138               return;
02139        }
02140 
02141        ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
02142        ZEND_FETCH_RESOURCE(tile, gdImagePtr, &TILE, -1, "Image", le_gd);
02143 
02144        gdImageSetTile(im, tile);
02145 
02146        RETURN_TRUE;
02147 }
02148 /* }}} */
02149 #endif
02150 
02151 #if HAVE_GD_IMAGESETBRUSH
02152 /* {{{ proto bool imagesetbrush(resource image, resource brush)
02153    Set the brush image to $brush when filling $image with the "IMG_COLOR_BRUSHED" color */
02154 PHP_FUNCTION(imagesetbrush)
02155 {
02156        zval *IM, *TILE;
02157        gdImagePtr im, tile;
02158 
02159        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr", &IM, &TILE) == FAILURE) {
02160               return;
02161        }
02162 
02163        ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
02164        ZEND_FETCH_RESOURCE(tile, gdImagePtr, &TILE, -1, "Image", le_gd);
02165 
02166        gdImageSetBrush(im, tile);
02167 
02168        RETURN_TRUE;
02169 }
02170 /* }}} */
02171 #endif
02172 
02173 /* {{{ proto resource imagecreate(int x_size, int y_size)
02174    Create a new image */
02175 PHP_FUNCTION(imagecreate)
02176 {
02177        long x_size, y_size;
02178        gdImagePtr im;
02179 
02180        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &x_size, &y_size) == FAILURE) {
02181               return;
02182        }
02183 
02184        if (x_size <= 0 || y_size <= 0 || x_size >= INT_MAX || y_size >= INT_MAX) {
02185               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid image dimensions");
02186               RETURN_FALSE;
02187        }
02188 
02189        im = gdImageCreate(x_size, y_size);
02190 
02191        if (!im) {
02192               RETURN_FALSE;
02193        }
02194 
02195        ZEND_REGISTER_RESOURCE(return_value, im, le_gd);
02196 }
02197 /* }}} */
02198 
02199 /* {{{ proto int imagetypes(void)
02200    Return the types of images supported in a bitfield - 1=GIF, 2=JPEG, 4=PNG, 8=WBMP, 16=XPM */
02201 PHP_FUNCTION(imagetypes)
02202 {
02203        int ret=0;
02204 #ifdef HAVE_GD_GIF_CREATE
02205        ret = 1;
02206 #endif
02207 #ifdef HAVE_GD_JPG
02208        ret |= 2;
02209 #endif
02210 #ifdef HAVE_GD_PNG
02211        ret |= 4;
02212 #endif
02213 #ifdef HAVE_GD_WBMP
02214        ret |= 8;
02215 #endif
02216 #if defined(HAVE_GD_XPM) && defined(HAVE_GD_BUNDLED)
02217        ret |= 16;
02218 #endif
02219 
02220        if (zend_parse_parameters_none() == FAILURE) {
02221               return;
02222        }
02223 
02224        RETURN_LONG(ret);
02225 }
02226 /* }}} */
02227 
02228 /* {{{ _php_image_type
02229  */
02230 static const char php_sig_gd2[3] = {'g', 'd', '2'};
02231 
02232 static int _php_image_type (char data[8])
02233 {
02234 #ifdef HAVE_LIBGD15
02235        /* Based on ext/standard/image.c */
02236 
02237        if (data == NULL) {
02238               return -1;
02239        }
02240 
02241        if (!memcmp(data, php_sig_gd2, 3)) {
02242               return PHP_GDIMG_TYPE_GD2;
02243        } else if (!memcmp(data, php_sig_jpg, 3)) {
02244               return PHP_GDIMG_TYPE_JPG;
02245        } else if (!memcmp(data, php_sig_png, 3)) {
02246               if (!memcmp(data, php_sig_png, 8)) {
02247                      return PHP_GDIMG_TYPE_PNG;
02248               }
02249        } else if (!memcmp(data, php_sig_gif, 3)) {
02250               return PHP_GDIMG_TYPE_GIF;
02251        }
02252 #ifdef HAVE_GD_WBMP
02253        else {
02254               gdIOCtx *io_ctx;
02255               io_ctx = gdNewDynamicCtxEx(8, data, 0);
02256               if (io_ctx) {
02257                      if (getmbi((int(*)(void *)) gdGetC, io_ctx) == 0 && skipheader((int(*)(void *)) gdGetC, io_ctx) == 0 ) {
02258 #if HAVE_LIBGD204
02259                             io_ctx->gd_free(io_ctx);
02260 #else
02261                             io_ctx->free(io_ctx);
02262 #endif
02263                             return PHP_GDIMG_TYPE_WBM;
02264                      } else {
02265 #if HAVE_LIBGD204
02266                             io_ctx->gd_free(io_ctx);
02267 #else
02268                             io_ctx->free(io_ctx);
02269 #endif
02270                      }
02271               }
02272        }
02273 #endif
02274        return -1;
02275 #endif
02276 }
02277 /* }}} */
02278 
02279 #ifdef HAVE_LIBGD15
02280 /* {{{ _php_image_create_from_string
02281  */
02282 gdImagePtr _php_image_create_from_string(zval **data, char *tn, gdImagePtr (*ioctx_func_p)() TSRMLS_DC)
02283 {
02284        gdImagePtr im;
02285        gdIOCtx *io_ctx;
02286 
02287        io_ctx = gdNewDynamicCtxEx(Z_STRLEN_PP(data), Z_STRVAL_PP(data), 0);
02288 
02289        if (!io_ctx) {
02290               return NULL;
02291        }
02292 
02293        im = (*ioctx_func_p)(io_ctx);
02294        if (!im) {
02295               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Passed data is not in '%s' format", tn);
02296 #if HAVE_LIBGD204
02297               io_ctx->gd_free(io_ctx);
02298 #else
02299               io_ctx->free(io_ctx);
02300 #endif
02301               return NULL;
02302        }
02303 
02304 #if HAVE_LIBGD204
02305        io_ctx->gd_free(io_ctx);
02306 #else
02307        io_ctx->free(io_ctx);
02308 #endif
02309 
02310        return im;
02311 }
02312 /* }}} */
02313 
02314 /* {{{ proto resource imagecreatefromstring(string image)
02315    Create a new image from the image stream in the string */
02316 PHP_FUNCTION(imagecreatefromstring)
02317 {
02318        zval **data;
02319        gdImagePtr im;
02320        int imtype;
02321        char sig[8];
02322 
02323        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &data) == FAILURE) {
02324               return;
02325        }
02326 
02327        convert_to_string_ex(data);
02328        if (Z_STRLEN_PP(data) < 8) {
02329               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty string or invalid image");
02330               RETURN_FALSE;
02331        }
02332 
02333        memcpy(sig, Z_STRVAL_PP(data), 8);
02334 
02335        imtype = _php_image_type(sig);
02336 
02337        switch (imtype) {
02338               case PHP_GDIMG_TYPE_JPG:
02339 #ifdef HAVE_GD_JPG
02340                      im = _php_image_create_from_string(data, "JPEG", gdImageCreateFromJpegCtx TSRMLS_CC);
02341 #else
02342                      php_error_docref(NULL TSRMLS_CC, E_WARNING, "No JPEG support in this PHP build");
02343                      RETURN_FALSE;
02344 #endif
02345                      break;
02346 
02347               case PHP_GDIMG_TYPE_PNG:
02348 #ifdef HAVE_GD_PNG
02349                      im = _php_image_create_from_string(data, "PNG", gdImageCreateFromPngCtx TSRMLS_CC);
02350 #else
02351                      php_error_docref(NULL TSRMLS_CC, E_WARNING, "No PNG support in this PHP build");
02352                      RETURN_FALSE;
02353 #endif
02354                      break;
02355 
02356               case PHP_GDIMG_TYPE_GIF:
02357 #ifdef HAVE_GD_GIF_READ
02358                      im = _php_image_create_from_string(data, "GIF", gdImageCreateFromGifCtx TSRMLS_CC);
02359 #else
02360                      php_error_docref(NULL TSRMLS_CC, E_WARNING, "No GIF support in this PHP build");
02361                      RETURN_FALSE;
02362 #endif
02363                      break;
02364 
02365               case PHP_GDIMG_TYPE_WBM:
02366 #ifdef HAVE_GD_WBMP
02367                      im = _php_image_create_from_string(data, "WBMP", gdImageCreateFromWBMPCtx TSRMLS_CC);
02368 #else
02369                      php_error_docref(NULL TSRMLS_CC, E_WARNING, "No WBMP support in this PHP build");
02370                      RETURN_FALSE;
02371 #endif
02372                      break;
02373 
02374               case PHP_GDIMG_TYPE_GD2:
02375 #ifdef HAVE_GD_GD2
02376                      im = _php_image_create_from_string(data, "GD2", gdImageCreateFromGd2Ctx TSRMLS_CC);
02377 #else
02378                      php_error_docref(NULL TSRMLS_CC, E_WARNING, "No GD2 support in this PHP build");
02379                      RETURN_FALSE;
02380 #endif
02381                      break;
02382 
02383               default:
02384                      php_error_docref(NULL TSRMLS_CC, E_WARNING, "Data is not in a recognized format");
02385                      RETURN_FALSE;
02386        }
02387 
02388        if (!im) {
02389               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't create GD Image Stream out of Data");
02390               RETURN_FALSE;
02391        }
02392 
02393        ZEND_REGISTER_RESOURCE(return_value, im, le_gd);
02394 }
02395 /* }}} */
02396 #endif
02397 
02398 /* {{{ _php_image_create_from
02399  */
02400 static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, gdImagePtr (*func_p)(), gdImagePtr (*ioctx_func_p)())
02401 {
02402        char *file;
02403        int file_len;
02404        long srcx, srcy, width, height;
02405        gdImagePtr im = NULL;
02406        php_stream *stream;
02407        FILE * fp = NULL;
02408 #ifdef HAVE_GD_JPG
02409        long ignore_warning;
02410 #endif
02411        if (image_type == PHP_GDIMG_TYPE_GD2PART) {
02412               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sllll", &file, &file_len, &srcx, &srcy, &width, &height) == FAILURE) {
02413                      return;
02414               }
02415               if (width < 1 || height < 1) {
02416                      php_error_docref(NULL TSRMLS_CC, E_WARNING, "Zero width or height not allowed");
02417                      RETURN_FALSE;
02418               }
02419        } else {
02420               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_len) == FAILURE) {
02421                      return;
02422               }
02423        }
02424 
02425        stream = php_stream_open_wrapper(file, "rb", ENFORCE_SAFE_MODE|REPORT_ERRORS|IGNORE_PATH|IGNORE_URL_WIN, NULL);
02426        if (stream == NULL)  {
02427               RETURN_FALSE;
02428        }
02429 
02430 #ifndef USE_GD_IOCTX
02431        ioctx_func_p = NULL; /* don't allow sockets without IOCtx */
02432 #endif
02433 
02434        /* try and avoid allocating a FILE* if the stream is not naturally a FILE* */
02435        if (php_stream_is(stream, PHP_STREAM_IS_STDIO))  {
02436               if (FAILURE == php_stream_cast(stream, PHP_STREAM_AS_STDIO, (void**)&fp, REPORT_ERRORS)) {
02437                      goto out_err;
02438               }
02439        } else if (ioctx_func_p) {
02440 #ifdef USE_GD_IOCTX
02441               /* we can create an io context */
02442               gdIOCtx* io_ctx;
02443               size_t buff_size;
02444               char *buff;
02445 
02446               /* needs to be malloc (persistent) - GD will free() it later */
02447               buff_size = php_stream_copy_to_mem(stream, &buff, PHP_STREAM_COPY_ALL, 1);
02448 
02449               if (!buff_size) {
02450                      php_error_docref(NULL TSRMLS_CC, E_WARNING,"Cannot read image data");
02451                      goto out_err;
02452               }
02453 
02454               io_ctx = gdNewDynamicCtxEx(buff_size, buff, 0);
02455               if (!io_ctx) {
02456                      pefree(buff, 1);
02457                      php_error_docref(NULL TSRMLS_CC, E_WARNING,"Cannot allocate GD IO context");
02458                      goto out_err;
02459               }
02460 
02461               if (image_type == PHP_GDIMG_TYPE_GD2PART) {
02462                      im = (*ioctx_func_p)(io_ctx, srcx, srcy, width, height);
02463               } else {
02464                      im = (*ioctx_func_p)(io_ctx);
02465               }
02466 #if HAVE_LIBGD204
02467               io_ctx->gd_free(io_ctx);
02468 #else
02469               io_ctx->free(io_ctx);
02470 #endif
02471               pefree(buff, 1);
02472 #endif
02473        }
02474        else {
02475               /* try and force the stream to be FILE* */
02476               if (FAILURE == php_stream_cast(stream, PHP_STREAM_AS_STDIO | PHP_STREAM_CAST_TRY_HARD, (void **) &fp, REPORT_ERRORS)) {
02477                      goto out_err;
02478               }
02479        }
02480 
02481        if (!im && fp) {
02482               switch (image_type) {
02483                      case PHP_GDIMG_TYPE_GD2PART:
02484                             im = (*func_p)(fp, srcx, srcy, width, height);
02485                             break;
02486 #if defined(HAVE_GD_XPM) && defined(HAVE_GD_BUNDLED)
02487                      case PHP_GDIMG_TYPE_XPM:
02488                             im = gdImageCreateFromXpm(file);
02489                             break;
02490 #endif
02491 
02492 #ifdef HAVE_GD_JPG
02493                      case PHP_GDIMG_TYPE_JPG:
02494                             ignore_warning = INI_INT("gd.jpeg_ignore_warning");
02495 #ifdef HAVE_GD_BUNDLED
02496                             im = gdImageCreateFromJpeg(fp, ignore_warning);
02497 #else
02498                             im = gdImageCreateFromJpeg(fp);
02499 #endif
02500                      break;
02501 #endif
02502 
02503                      default:
02504                             im = (*func_p)(fp);
02505                             break;
02506               }
02507 
02508               fflush(fp);
02509        }
02510 
02511        if (im) {
02512               ZEND_REGISTER_RESOURCE(return_value, im, le_gd);
02513               php_stream_close(stream);
02514               return;
02515        }
02516 
02517        php_error_docref(NULL TSRMLS_CC, E_WARNING, "'%s' is not a valid %s file", file, tn);
02518 out_err:
02519        php_stream_close(stream);
02520        RETURN_FALSE;
02521 
02522 }
02523 /* }}} */
02524 
02525 #ifdef HAVE_GD_GIF_READ
02526 /* {{{ proto resource imagecreatefromgif(string filename)
02527    Create a new image from GIF file or URL */
02528 PHP_FUNCTION(imagecreatefromgif)
02529 {
02530        _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_GIF, "GIF", gdImageCreateFromGif, gdImageCreateFromGifCtx);
02531 }
02532 /* }}} */
02533 #endif /* HAVE_GD_GIF_READ */
02534 
02535 #ifdef HAVE_GD_JPG
02536 /* {{{ proto resource imagecreatefromjpeg(string filename)
02537    Create a new image from JPEG file or URL */
02538 PHP_FUNCTION(imagecreatefromjpeg)
02539 {
02540        _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_JPG, "JPEG", gdImageCreateFromJpeg, gdImageCreateFromJpegCtx);
02541 }
02542 /* }}} */
02543 #endif /* HAVE_GD_JPG */
02544 
02545 #ifdef HAVE_GD_PNG
02546 /* {{{ proto resource imagecreatefrompng(string filename)
02547    Create a new image from PNG file or URL */
02548 PHP_FUNCTION(imagecreatefrompng)
02549 {
02550        _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_PNG, "PNG", gdImageCreateFromPng, gdImageCreateFromPngCtx);
02551 }
02552 /* }}} */
02553 #endif /* HAVE_GD_PNG */
02554 
02555 #ifdef HAVE_GD_XBM
02556 /* {{{ proto resource imagecreatefromxbm(string filename)
02557    Create a new image from XBM file or URL */
02558 PHP_FUNCTION(imagecreatefromxbm)
02559 {
02560        _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_XBM, "XBM", gdImageCreateFromXbm, NULL);
02561 }
02562 /* }}} */
02563 #endif /* HAVE_GD_XBM */
02564 
02565 #if defined(HAVE_GD_XPM) && defined(HAVE_GD_BUNDLED)
02566 /* {{{ proto resource imagecreatefromxpm(string filename)
02567    Create a new image from XPM file or URL */
02568 PHP_FUNCTION(imagecreatefromxpm)
02569 {
02570        _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_XPM, "XPM", gdImageCreateFromXpm, NULL);
02571 }
02572 /* }}} */
02573 #endif
02574 
02575 #ifdef HAVE_GD_WBMP
02576 /* {{{ proto resource imagecreatefromwbmp(string filename)
02577    Create a new image from WBMP file or URL */
02578 PHP_FUNCTION(imagecreatefromwbmp)
02579 {
02580        _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_WBM, "WBMP", gdImageCreateFromWBMP, gdImageCreateFromWBMPCtx);
02581 }
02582 /* }}} */
02583 #endif /* HAVE_GD_WBMP */
02584 
02585 /* {{{ proto resource imagecreatefromgd(string filename)
02586    Create a new image from GD file or URL */
02587 PHP_FUNCTION(imagecreatefromgd)
02588 {
02589        _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_GD, "GD", gdImageCreateFromGd, gdImageCreateFromGdCtx);
02590 }
02591 /* }}} */
02592 
02593 #ifdef HAVE_GD_GD2
02594 /* {{{ proto resource imagecreatefromgd2(string filename)
02595    Create a new image from GD2 file or URL */
02596 PHP_FUNCTION(imagecreatefromgd2)
02597 {
02598        _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_GD2, "GD2", gdImageCreateFromGd2, gdImageCreateFromGd2Ctx);
02599 }
02600 /* }}} */
02601 
02602 /* {{{ proto resource imagecreatefromgd2part(string filename, int srcX, int srcY, int width, int height)
02603    Create a new image from a given part of GD2 file or URL */
02604 PHP_FUNCTION(imagecreatefromgd2part)
02605 {
02606        _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_GD2PART, "GD2", gdImageCreateFromGd2Part, gdImageCreateFromGd2PartCtx);
02607 }
02608 /* }}} */
02609 #endif /* HAVE_GD_GD2 */
02610 
02611 /* {{{ _php_image_output
02612  */
02613 static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, void (*func_p)())
02614 {
02615        zval *imgind;
02616        char *file = NULL;
02617        long quality = 0, type = 0;
02618        gdImagePtr im;
02619        char *fn = NULL;
02620        FILE *fp;
02621        int file_len = 0, argc = ZEND_NUM_ARGS();
02622        int q = -1, i, t = 1;
02623 
02624        /* The quality parameter for Wbmp stands for the threshold when called from image2wbmp() */
02625        /* When called from imagewbmp() the quality parameter stands for the foreground color. Default: black. */
02626        /* The quality parameter for gd2 stands for chunk size */
02627 
02628        if (zend_parse_parameters(argc TSRMLS_CC, "r|sll", &imgind, &file, &file_len, &quality, &type) == FAILURE) {
02629               return;
02630        }
02631 
02632        ZEND_FETCH_RESOURCE(im, gdImagePtr, &imgind, -1, "Image", le_gd);
02633 
02634        if (argc > 1) {
02635               fn = file;
02636               if (argc == 3) {
02637                      q = quality;
02638               }
02639               if (argc == 4) {
02640                      t = type;
02641               }
02642        }
02643 
02644        if (argc >= 2 && file_len) {
02645               if (strlen(file) != file_len) {
02646                      RETURN_FALSE;
02647               }
02648               PHP_GD_CHECK_OPEN_BASEDIR(fn, "Invalid filename");
02649 
02650               fp = VCWD_FOPEN(fn, "wb");
02651               if (!fp) {
02652                      php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open '%s' for writing", fn);
02653                      RETURN_FALSE;
02654               }
02655 
02656               switch (image_type) {
02657 #ifdef HAVE_GD_WBMP
02658                      case PHP_GDIMG_CONVERT_WBM:
02659                             if (q == -1) {
02660                                    q = 0;
02661                             } else if (q < 0 || q > 255) {
02662                                    php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid threshold value '%d'. It must be between 0 and 255", q);
02663                                    q = 0;
02664                             }
02665                             gdImageWBMP(im, q, fp);
02666                             break;
02667 #endif
02668                      case PHP_GDIMG_TYPE_JPG:
02669                             (*func_p)(im, fp, q);
02670                             break;
02671                      case PHP_GDIMG_TYPE_WBM:
02672                             for (i = 0; i < gdImageColorsTotal(im); i++) {
02673                                    if (gdImageRed(im, i) == 0) break;
02674                             }
02675                             (*func_p)(im, i, fp);
02676                             break;
02677                      case PHP_GDIMG_TYPE_GD:
02678                             if (im->trueColor){
02679                                    gdImageTrueColorToPalette(im,1,256);
02680                             }
02681                             (*func_p)(im, fp);
02682                             break;
02683 #ifdef HAVE_GD_GD2
02684                      case PHP_GDIMG_TYPE_GD2:
02685                             if (q == -1) {
02686                                    q = 128;
02687                             }
02688                             (*func_p)(im, fp, q, t);
02689                             break;
02690 #endif
02691                      default:
02692                             if (q == -1) {
02693                                    q = 128;
02694                             }
02695                             (*func_p)(im, fp, q, t);
02696                             break;
02697               }
02698               fflush(fp);
02699               fclose(fp);
02700        } else {
02701               int   b;
02702               FILE *tmp;
02703               char  buf[4096];
02704               char *path;
02705 
02706               tmp = php_open_temporary_file(NULL, NULL, &path TSRMLS_CC);
02707               if (tmp == NULL) {
02708                      php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open temporary file");
02709                      RETURN_FALSE;
02710               }
02711 
02712               switch (image_type) {
02713 #ifdef HAVE_GD_WBMP
02714                      case PHP_GDIMG_CONVERT_WBM:
02715                             if (q == -1) {
02716                                    q = 0;
02717                             } else if (q < 0 || q > 255) {
02718                                    php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid threshold value '%d'. It must be between 0 and 255", q);
02719                                    q = 0;
02720                             }
02721                             gdImageWBMP(im, q, tmp);
02722                             break;
02723 #endif
02724                      case PHP_GDIMG_TYPE_JPG:
02725                             (*func_p)(im, tmp, q);
02726                             break;
02727                      case PHP_GDIMG_TYPE_WBM:
02728                             for (i = 0; i < gdImageColorsTotal(im); i++) {
02729                                    if (gdImageRed(im, i) == 0) {
02730                                           break;
02731                                    }
02732                             }
02733                             (*func_p)(im, q, tmp);
02734                             break;
02735                      case PHP_GDIMG_TYPE_GD:
02736                             if (im->trueColor) {
02737                                    gdImageTrueColorToPalette(im,1,256);
02738                             }
02739                             (*func_p)(im, tmp);
02740                             break;
02741 #ifdef HAVE_GD_GD2
02742                      case PHP_GDIMG_TYPE_GD2:
02743                             if (q == -1) {
02744                                    q = 128;
02745                             }
02746                             (*func_p)(im, tmp, q, t);
02747                             break;
02748 #endif
02749                      default:
02750                             (*func_p)(im, tmp);
02751                             break;
02752               }
02753 
02754               fseek(tmp, 0, SEEK_SET);
02755 
02756 #if APACHE && defined(CHARSET_EBCDIC)
02757               /* XXX this is unlikely to work any more thies@thieso.net */
02758 
02759               /* This is a binary file already: avoid EBCDIC->ASCII conversion */
02760               ap_bsetflag(php3_rqst->connection->client, B_EBCDIC2ASCII, 0);
02761 #endif
02762               while ((b = fread(buf, 1, sizeof(buf), tmp)) > 0) {
02763                      php_write(buf, b TSRMLS_CC);
02764               }
02765 
02766               fclose(tmp);
02767               VCWD_UNLINK((const char *)path); /* make sure that the temporary file is removed */
02768               efree(path);
02769        }
02770        RETURN_TRUE;
02771 }
02772 /* }}} */
02773 
02774 /* {{{ proto int imagexbm(int im, string filename [, int foreground])
02775    Output XBM image to browser or file */
02776 #if HAVE_GD_BUNDLED
02777 PHP_FUNCTION(imagexbm)
02778 {
02779        _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_XBM, "XBM", gdImageXbmCtx);
02780 }
02781 #endif
02782 /* }}} */
02783 
02784 #ifdef HAVE_GD_GIF_CREATE
02785 /* {{{ proto bool imagegif(resource im [, string filename])
02786    Output GIF image to browser or file */
02787 PHP_FUNCTION(imagegif)
02788 {
02789 #ifdef HAVE_GD_GIF_CTX
02790        _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_GIF, "GIF", gdImageGifCtx);
02791 #else
02792        _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_GIF, "GIF", gdImageGif);
02793 #endif
02794 }
02795 /* }}} */
02796 #endif /* HAVE_GD_GIF_CREATE */
02797 
02798 #ifdef HAVE_GD_PNG
02799 /* {{{ proto bool imagepng(resource im [, string filename])
02800    Output PNG image to browser or file */
02801 PHP_FUNCTION(imagepng)
02802 {
02803 #ifdef USE_GD_IOCTX
02804        _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_PNG, "PNG", gdImagePngCtxEx);
02805 #else
02806        _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_PNG, "PNG", gdImagePng);
02807 #endif
02808 }
02809 /* }}} */
02810 #endif /* HAVE_GD_PNG */
02811 
02812 #ifdef HAVE_GD_JPG
02813 /* {{{ proto bool imagejpeg(resource im [, string filename [, int quality]])
02814    Output JPEG image to browser or file */
02815 PHP_FUNCTION(imagejpeg)
02816 {
02817 #ifdef USE_GD_IOCTX
02818        _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_JPG, "JPEG", gdImageJpegCtx);
02819 #else
02820        _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_JPG, "JPEG", gdImageJpeg);
02821 #endif
02822 }
02823 /* }}} */
02824 #endif /* HAVE_GD_JPG */
02825 
02826 #ifdef HAVE_GD_WBMP
02827 /* {{{ proto bool imagewbmp(resource im [, string filename, [, int foreground]])
02828    Output WBMP image to browser or file */
02829 PHP_FUNCTION(imagewbmp)
02830 {
02831 #ifdef USE_GD_IOCTX
02832        _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_WBM, "WBMP", gdImageWBMPCtx);
02833 #else
02834        _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_WBM, "WBMP", gdImageWBMP);
02835 #endif
02836 }
02837 /* }}} */
02838 #endif /* HAVE_GD_WBMP */
02839 
02840 /* {{{ proto bool imagegd(resource im [, string filename])
02841    Output GD image to browser or file */
02842 PHP_FUNCTION(imagegd)
02843 {
02844        _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_GD, "GD", gdImageGd);
02845 }
02846 /* }}} */
02847 
02848 #ifdef HAVE_GD_GD2
02849 /* {{{ proto bool imagegd2(resource im [, string filename, [, int chunk_size, [, int type]]])
02850    Output GD2 image to browser or file */
02851 PHP_FUNCTION(imagegd2)
02852 {
02853        _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_GD2, "GD2", gdImageGd2);
02854 }
02855 /* }}} */
02856 #endif /* HAVE_GD_GD2 */
02857 
02858 /* {{{ proto bool imagedestroy(resource im)
02859    Destroy an image */
02860 PHP_FUNCTION(imagedestroy)
02861 {
02862        zval *IM;
02863        gdImagePtr im;
02864 
02865        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &IM) == FAILURE) {
02866               return;
02867        }
02868 
02869        ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
02870 
02871        zend_list_delete(Z_LVAL_P(IM));
02872 
02873        RETURN_TRUE;
02874 }
02875 /* }}} */
02876 
02877 
02878 /* {{{ proto int imagecolorallocate(resource im, int red, int green, int blue)
02879    Allocate a color for an image */
02880 PHP_FUNCTION(imagecolorallocate)
02881 {
02882        zval *IM;
02883        long red, green, blue;
02884        gdImagePtr im;
02885        int ct = (-1);
02886 
02887        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlll", &IM, &red, &green, &blue) == FAILURE) {
02888               return;
02889        }
02890 
02891        ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
02892 
02893        ct = gdImageColorAllocate(im, red, green, blue);
02894        if (ct < 0) {
02895               RETURN_FALSE;
02896        }
02897        RETURN_LONG(ct);
02898 }
02899 /* }}} */
02900 
02901 #if HAVE_LIBGD15
02902 /* {{{ proto void imagepalettecopy(resource dst, resource src)
02903    Copy the palette from the src image onto the dst image */
02904 PHP_FUNCTION(imagepalettecopy)
02905 {
02906        zval *dstim, *srcim;
02907        gdImagePtr dst, src;
02908 
02909        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr", &dstim, &srcim) == FAILURE) {
02910               return;
02911        }
02912 
02913        ZEND_FETCH_RESOURCE(dst, gdImagePtr, &dstim, -1, "Image", le_gd);
02914        ZEND_FETCH_RESOURCE(src, gdImagePtr, &srcim, -1, "Image", le_gd);
02915 
02916        gdImagePaletteCopy(dst, src);
02917 }
02918 /* }}} */
02919 #endif
02920 
02921 /* {{{ proto int imagecolorat(resource im, int x, int y)
02922    Get the index of the color of a pixel */
02923 PHP_FUNCTION(imagecolorat)
02924 {
02925        zval *IM;
02926        long x, y;
02927        gdImagePtr im;
02928 
02929        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &IM, &x, &y) == FAILURE) {
02930               return;
02931        }
02932 
02933        ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
02934 
02935        if (gdImageTrueColor(im)) {
02936               if (im->tpixels && gdImageBoundsSafe(im, x, y)) {
02937                      RETURN_LONG(gdImageTrueColorPixel(im, x, y));
02938               } else {
02939                      php_error_docref(NULL TSRMLS_CC, E_NOTICE, "%ld,%ld is out of bounds", x, y);
02940                      RETURN_FALSE;
02941               }
02942        } else {
02943               if (im->pixels && gdImageBoundsSafe(im, x, y)) {
02944                      RETURN_LONG(im->pixels[y][x]);
02945               } else {
02946                      php_error_docref(NULL TSRMLS_CC, E_NOTICE, "%ld,%ld is out of bounds", x, y);
02947                      RETURN_FALSE;
02948               }
02949        }
02950 }
02951 /* }}} */
02952 
02953 /* {{{ proto int imagecolorclosest(resource im, int red, int green, int blue)
02954    Get the index of the closest color to the specified color */
02955 PHP_FUNCTION(imagecolorclosest)
02956 {
02957        zval *IM;
02958        long red, green, blue;
02959        gdImagePtr im;
02960 
02961        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlll", &IM, &red, &green, &blue) == FAILURE) {
02962               return;
02963        }
02964 
02965        ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
02966 
02967        RETURN_LONG(gdImageColorClosest(im, red, green, blue));
02968 }
02969 /* }}} */
02970 
02971 #if HAVE_COLORCLOSESTHWB
02972 /* {{{ proto int imagecolorclosesthwb(resource im, int red, int green, int blue)
02973    Get the index of the color which has the hue, white and blackness nearest to the given color */
02974 PHP_FUNCTION(imagecolorclosesthwb)
02975 {
02976        zval *IM;
02977        long red, green, blue;
02978        gdImagePtr im;
02979 
02980        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlll", &IM, &red, &green, &blue) == FAILURE) {
02981               return;
02982        }
02983 
02984        ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
02985 
02986        RETURN_LONG(gdImageColorClosestHWB(im, red, green, blue));
02987 }
02988 /* }}} */
02989 #endif
02990 
02991 /* {{{ proto bool imagecolordeallocate(resource im, int index)
02992    De-allocate a color for an image */
02993 PHP_FUNCTION(imagecolordeallocate)
02994 {
02995        zval *IM;
02996        long index;
02997        int col;
02998        gdImagePtr im;
02999 
03000        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &IM, &index) == FAILURE) {
03001               return;
03002        }
03003 
03004        ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
03005 
03006        /* We can return right away for a truecolor image as deallocating colours is meaningless here */
03007        if (gdImageTrueColor(im)) {
03008               RETURN_TRUE;
03009        }
03010 
03011        col = index;
03012 
03013        if (col >= 0 && col < gdImageColorsTotal(im)) {
03014               gdImageColorDeallocate(im, col);
03015               RETURN_TRUE;
03016        } else {
03017               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Color index %d out of range",   col);
03018               RETURN_FALSE;
03019        }
03020 }
03021 /* }}} */
03022 
03023 /* {{{ proto int imagecolorresolve(resource im, int red, int green, int blue)
03024    Get the index of the specified color or its closest possible alternative */
03025 PHP_FUNCTION(imagecolorresolve)
03026 {
03027        zval *IM;
03028        long red, green, blue;
03029        gdImagePtr im;
03030 
03031        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlll", &IM, &red, &green, &blue) == FAILURE) {
03032               return;
03033        }
03034 
03035        ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
03036 
03037        RETURN_LONG(gdImageColorResolve(im, red, green, blue));
03038 }
03039 /* }}} */
03040 
03041 /* {{{ proto int imagecolorexact(resource im, int red, int green, int blue)
03042    Get the index of the specified color */
03043 PHP_FUNCTION(imagecolorexact)
03044 {
03045        zval *IM;
03046        long red, green, blue;
03047        gdImagePtr im;
03048 
03049        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlll", &IM, &red, &green, &blue) == FAILURE) {
03050               return;
03051        }
03052 
03053        ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
03054 
03055        RETURN_LONG(gdImageColorExact(im, red, green, blue));
03056 }
03057 /* }}} */
03058 
03059 /* {{{ proto void imagecolorset(resource im, int col, int red, int green, int blue)
03060    Set the color for the specified palette index */
03061 PHP_FUNCTION(imagecolorset)
03062 {
03063        zval *IM;
03064        long color, red, green, blue;
03065        int col;
03066        gdImagePtr im;
03067 
03068        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll", &IM, &color, &red, &green, &blue) == FAILURE) {
03069               return;
03070        }
03071 
03072        ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
03073 
03074        col = color;
03075 
03076        if (col >= 0 && col < gdImageColorsTotal(im)) {
03077               im->red[col]   = red;
03078               im->green[col] = green;
03079               im->blue[col]  = blue;
03080        } else {
03081               RETURN_FALSE;
03082        }
03083 }
03084 /* }}} */
03085 
03086 /* {{{ proto array imagecolorsforindex(resource im, int col)
03087    Get the colors for an index */
03088 PHP_FUNCTION(imagecolorsforindex)
03089 {
03090        zval *IM;
03091        long index;
03092        int col;
03093        gdImagePtr im;
03094 
03095        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &IM, &index) == FAILURE) {
03096               return;
03097        }
03098 
03099        ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
03100 
03101        col = index;
03102 
03103        if ((col >= 0 && gdImageTrueColor(im)) || (!gdImageTrueColor(im) && col >= 0 && col < gdImageColorsTotal(im))) {
03104               array_init(return_value);
03105 
03106               add_assoc_long(return_value,"red",  gdImageRed(im,col));
03107               add_assoc_long(return_value,"green", gdImageGreen(im,col));
03108               add_assoc_long(return_value,"blue", gdImageBlue(im,col));
03109               add_assoc_long(return_value,"alpha", gdImageAlpha(im,col));
03110        } else {
03111               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Color index %d out of range", col);
03112               RETURN_FALSE;
03113        }
03114 }
03115 /* }}} */
03116 
03117 /* {{{ proto bool imagegammacorrect(resource im, float inputgamma, float outputgamma)
03118    Apply a gamma correction to a GD image */
03119 PHP_FUNCTION(imagegammacorrect)
03120 {
03121        zval *IM;
03122        gdImagePtr im;
03123        int i;
03124        double input, output;
03125 
03126        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rdd", &IM, &input, &output) == FAILURE) {
03127               return;
03128        }
03129 
03130        ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
03131 
03132        if (gdImageTrueColor(im))   {
03133               int x, y, c;
03134 
03135               for (y = 0; y < gdImageSY(im); y++)       {
03136                      for (x = 0; x < gdImageSX(im); x++)       {
03137                             c = gdImageGetPixel(im, x, y);
03138                             gdImageSetPixel(im, x, y,
03139                                    gdTrueColor(
03140                                           (int) ((pow((pow((gdTrueColorGetRed(c)   / 255.0), input)), 1.0 / output) * 255) + .5),
03141                                           (int) ((pow((pow((gdTrueColorGetGreen(c) / 255.0), input)), 1.0 / output) * 255) + .5),
03142                                           (int) ((pow((pow((gdTrueColorGetBlue(c)  / 255.0), input)), 1.0 / output) * 255) + .5)
03143                                    )
03144                             );
03145                      }
03146               }
03147               RETURN_TRUE;
03148        }
03149 
03150        for (i = 0; i < gdImageColorsTotal(im); i++) {
03151               im->red[i]   = (int)((pow((pow((im->red[i]   / 255.0), input)), 1.0 / output) * 255) + .5);
03152               im->green[i] = (int)((pow((pow((im->green[i] / 255.0), input)), 1.0 / output) * 255) + .5);
03153               im->blue[i]  = (int)((pow((pow((im->blue[i]  / 255.0), input)), 1.0 / output) * 255) + .5);
03154        }
03155 
03156        RETURN_TRUE;
03157 }
03158 /* }}} */
03159 
03160 /* {{{ proto bool imagesetpixel(resource im, int x, int y, int col)
03161    Set a single pixel */
03162 PHP_FUNCTION(imagesetpixel)
03163 {
03164        zval *IM;
03165        long x, y, col;
03166        gdImagePtr im;
03167 
03168        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlll", &IM, &x, &y, &col) == FAILURE) {
03169               return;
03170        }
03171 
03172        ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
03173        gdImageSetPixel(im, x, y, col);
03174        RETURN_TRUE;
03175 }
03176 /* }}} */
03177 
03178 /* {{{ proto bool imageline(resource im, int x1, int y1, int x2, int y2, int col)
03179    Draw a line */
03180 PHP_FUNCTION(imageline)
03181 {
03182        zval *IM;
03183        long x1, y1, x2, y2, col;
03184        gdImagePtr im;
03185 
03186        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllll", &IM, &x1, &y1, &x2, &y2, &col) == FAILURE) {
03187               return;
03188        }
03189 
03190        ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
03191 
03192 #ifdef HAVE_GD_BUNDLED
03193        if (im->antialias) {
03194               gdImageAALine(im, x1, y1, x2, y2, col);
03195        } else
03196 #endif
03197        {
03198               gdImageLine(im, x1, y1, x2, y2, col);
03199        }
03200        RETURN_TRUE;
03201 }
03202 /* }}} */
03203 
03204 /* {{{ proto bool imagedashedline(resource im, int x1, int y1, int x2, int y2, int col)
03205    Draw a dashed line */
03206 PHP_FUNCTION(imagedashedline)
03207 {
03208        zval *IM;
03209        long x1, y1, x2, y2, col;
03210        gdImagePtr im;
03211 
03212        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllll", &IM, &x1, &y1, &x2, &y2, &col) == FAILURE) {
03213               return;
03214        }
03215 
03216        ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
03217        gdImageDashedLine(im, x1, y1, x2, y2, col);
03218        RETURN_TRUE;
03219 }
03220 /* }}} */
03221 
03222 /* {{{ proto bool imagerectangle(resource im, int x1, int y1, int x2, int y2, int col)
03223    Draw a rectangle */
03224 PHP_FUNCTION(imagerectangle)
03225 {
03226        zval *IM;
03227        long x1, y1, x2, y2, col;
03228        gdImagePtr im;
03229 
03230        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllll", &IM, &x1, &y1, &x2, &y2, &col) == FAILURE) {
03231               return;
03232        }
03233 
03234        ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
03235        gdImageRectangle(im, x1, y1, x2, y2, col);
03236        RETURN_TRUE;
03237 }
03238 /* }}} */
03239 
03240 /* {{{ proto bool imagefilledrectangle(resource im, int x1, int y1, int x2, int y2, int col)
03241    Draw a filled rectangle */
03242 PHP_FUNCTION(imagefilledrectangle)
03243 {
03244        zval *IM;
03245        long x1, y1, x2, y2, col;
03246        gdImagePtr im;
03247 
03248        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllll", &IM, &x1, &y1, &x2, &y2, &col) == FAILURE) {
03249               return;
03250        }
03251 
03252        ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
03253        gdImageFilledRectangle(im, x1, y1, x2, y2, col);
03254        RETURN_TRUE;
03255 }
03256 /* }}} */
03257 
03258 /* {{{ proto bool imagearc(resource im, int cx, int cy, int w, int h, int s, int e, int col)
03259    Draw a partial ellipse */
03260 PHP_FUNCTION(imagearc)
03261 {
03262        zval *IM;
03263        long cx, cy, w, h, ST, E, col;
03264        gdImagePtr im;
03265        int e, st;
03266 
03267        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllllll", &IM, &cx, &cy, &w, &h, &ST, &E, &col) == FAILURE) {
03268               return;
03269        }
03270 
03271        ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
03272 
03273        e = E;
03274        if (e < 0) {
03275               e %= 360;
03276        }
03277 
03278        st = ST;
03279        if (st < 0) {
03280               st %= 360;
03281        }
03282 
03283        gdImageArc(im, cx, cy, w, h, st, e, col);
03284        RETURN_TRUE;
03285 }
03286 /* }}} */
03287 
03288 /* {{{ proto bool imageellipse(resource im, int cx, int cy, int w, int h, int color)
03289    Draw an ellipse */
03290 PHP_FUNCTION(imageellipse)
03291 {
03292        zval *IM;
03293        long cx, cy, w, h, color;
03294        gdImagePtr im;
03295 
03296        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllll", &IM, &cx, &cy, &w, &h, &color) == FAILURE) {
03297               return;
03298        }
03299 
03300        ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
03301 
03302        gdImageEllipse(im, cx, cy, w, h, color);
03303        RETURN_TRUE;
03304 }
03305 /* }}} */
03306 
03307 /* {{{ proto bool imagefilltoborder(resource im, int x, int y, int border, int col)
03308    Flood fill to specific color */
03309 PHP_FUNCTION(imagefilltoborder)
03310 {
03311        zval *IM;
03312        long x, y, border, col;
03313        gdImagePtr im;
03314 
03315        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll", &IM, &x, &y, &border, &col) == FAILURE) {
03316               return;
03317        }
03318 
03319        ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
03320        gdImageFillToBorder(im, x, y, border, col);
03321        RETURN_TRUE;
03322 }
03323 /* }}} */
03324 
03325 /* {{{ proto bool imagefill(resource im, int x, int y, int col)
03326    Flood fill */
03327 PHP_FUNCTION(imagefill)
03328 {
03329        zval *IM;
03330        long x, y, col;
03331        gdImagePtr im;
03332 
03333        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlll", &IM, &x, &y, &col) == FAILURE) {
03334               return;
03335        }
03336 
03337        ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
03338        gdImageFill(im, x, y, col);
03339        RETURN_TRUE;
03340 }
03341 /* }}} */
03342 
03343 /* {{{ proto int imagecolorstotal(resource im)
03344    Find out the number of colors in an image's palette */
03345 PHP_FUNCTION(imagecolorstotal)
03346 {
03347        zval *IM;
03348        gdImagePtr im;
03349 
03350        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &IM) == FAILURE) {
03351               return;
03352        }
03353 
03354        ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
03355 
03356        RETURN_LONG(gdImageColorsTotal(im));
03357 }
03358 /* }}} */
03359 
03360 /* {{{ proto int imagecolortransparent(resource im [, int col])
03361    Define a color as transparent */
03362 PHP_FUNCTION(imagecolortransparent)
03363 {
03364        zval *IM;
03365        long COL = 0;
03366        gdImagePtr im;
03367        int argc = ZEND_NUM_ARGS();
03368 
03369        if (zend_parse_parameters(argc TSRMLS_CC, "r|l", &IM, &COL) == FAILURE) {
03370               return;
03371        }
03372 
03373        ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
03374 
03375        if (argc > 1) {
03376               gdImageColorTransparent(im, COL);
03377        }
03378 
03379        RETURN_LONG(gdImageGetTransparent(im));
03380 }
03381 /* }}} */
03382 
03383 /* {{{ proto int imageinterlace(resource im [, int interlace])
03384    Enable or disable interlace */
03385 PHP_FUNCTION(imageinterlace)
03386 {
03387        zval *IM;
03388        int argc = ZEND_NUM_ARGS();
03389        long INT = 0;
03390        gdImagePtr im;
03391 
03392        if (zend_parse_parameters(argc TSRMLS_CC, "r|l", &IM, &INT) == FAILURE) {
03393               return;
03394        }
03395 
03396        ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
03397 
03398        if (argc > 1) {
03399               gdImageInterlace(im, INT);
03400        }
03401 
03402        RETURN_LONG(gdImageGetInterlaced(im));
03403 }
03404 /* }}} */
03405 
03406 /* {{{ php_imagepolygon
03407    arg = 0  normal polygon
03408    arg = 1  filled polygon */
03409 /* im, points, num_points, col */
03410 static void php_imagepolygon(INTERNAL_FUNCTION_PARAMETERS, int filled)
03411 {
03412        zval *IM, *POINTS;
03413        long NPOINTS, COL;
03414        zval **var = NULL;
03415        gdImagePtr im;
03416        gdPointPtr points;
03417        int npoints, col, nelem, i;
03418 
03419        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rall", &IM, &POINTS, &NPOINTS, &COL) == FAILURE) {
03420               return;
03421        }
03422 
03423        ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
03424 
03425        npoints = NPOINTS;
03426        col = COL;
03427 
03428        nelem = zend_hash_num_elements(Z_ARRVAL_P(POINTS));
03429        if (nelem < 6) {
03430               php_error_docref(NULL TSRMLS_CC, E_WARNING, "You must have at least 3 points in your array");
03431               RETURN_FALSE;
03432        }
03433        if (npoints <= 0) {
03434               php_error_docref(NULL TSRMLS_CC, E_WARNING, "You must give a positive number of points");
03435               RETURN_FALSE;
03436        }
03437        if (nelem < npoints * 2) {
03438               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Trying to use %d points in array with only %d points", npoints, nelem/2);
03439               RETURN_FALSE;
03440        }
03441 
03442        points = (gdPointPtr) safe_emalloc(npoints, sizeof(gdPoint), 0);
03443 
03444        for (i = 0; i < npoints; i++) {
03445               if (zend_hash_index_find(Z_ARRVAL_P(POINTS), (i * 2), (void **) &var) == SUCCESS) {
03446                      SEPARATE_ZVAL((var));
03447                      convert_to_long(*var);
03448                      points[i].x = Z_LVAL_PP(var);
03449               }
03450               if (zend_hash_index_find(Z_ARRVAL_P(POINTS), (i * 2) + 1, (void **) &var) == SUCCESS) {
03451                      SEPARATE_ZVAL(var);
03452                      convert_to_long(*var);
03453                      points[i].y = Z_LVAL_PP(var);
03454               }
03455        }
03456 
03457        if (filled) {
03458               gdImageFilledPolygon(im, points, npoints, col);
03459        } else {
03460               gdImagePolygon(im, points, npoints, col);
03461        }
03462 
03463        efree(points);
03464        RETURN_TRUE;
03465 }
03466 /* }}} */
03467 
03468 /* {{{ proto bool imagepolygon(resource im, array point, int num_points, int col)
03469    Draw a polygon */
03470 PHP_FUNCTION(imagepolygon)
03471 {
03472        php_imagepolygon(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
03473 }
03474 /* }}} */
03475 
03476 /* {{{ proto bool imagefilledpolygon(resource im, array point, int num_points, int col)
03477    Draw a filled polygon */
03478 PHP_FUNCTION(imagefilledpolygon)
03479 {
03480        php_imagepolygon(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
03481 }
03482 /* }}} */
03483 
03484 /* {{{ php_find_gd_font
03485  */
03486 static gdFontPtr php_find_gd_font(int size TSRMLS_DC)
03487 {
03488        gdFontPtr font;
03489        int ind_type;
03490 
03491        switch (size) {
03492               case 1:
03493                       font = gdFontTiny;
03494                       break;
03495               case 2:
03496                       font = gdFontSmall;
03497                       break;
03498               case 3:
03499                       font = gdFontMediumBold;
03500                       break;
03501               case 4:
03502                       font = gdFontLarge;
03503                       break;
03504               case 5:
03505                       font = gdFontGiant;
03506                       break;
03507               default:
03508                      font = zend_list_find(size - 5, &ind_type);
03509                       if (!font || ind_type != le_gd_font) {
03510                               if (size < 1) {
03511                                       font = gdFontTiny;
03512                               } else {
03513                                       font = gdFontGiant;
03514                               }
03515                       }
03516                       break;
03517        }
03518 
03519        return font;
03520 }
03521 /* }}} */
03522 
03523 /* {{{ php_imagefontsize
03524  * arg = 0  ImageFontWidth
03525  * arg = 1  ImageFontHeight
03526  */
03527 static void php_imagefontsize(INTERNAL_FUNCTION_PARAMETERS, int arg)
03528 {
03529        long SIZE;
03530        gdFontPtr font;
03531 
03532        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &SIZE) == FAILURE) {
03533               return;
03534        }
03535 
03536        font = php_find_gd_font(SIZE TSRMLS_CC);
03537        RETURN_LONG(arg ? font->h : font->w);
03538 }
03539 /* }}} */
03540 
03541 /* {{{ proto int imagefontwidth(int font)
03542    Get font width */
03543 PHP_FUNCTION(imagefontwidth)
03544 {
03545        php_imagefontsize(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
03546 }
03547 /* }}} */
03548 
03549 /* {{{ proto int imagefontheight(int font)
03550    Get font height */
03551 PHP_FUNCTION(imagefontheight)
03552 {
03553        php_imagefontsize(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
03554 }
03555 /* }}} */
03556 
03557 /* {{{ php_gdimagecharup
03558  * workaround for a bug in gd 1.2 */
03559 static void php_gdimagecharup(gdImagePtr im, gdFontPtr f, int x, int y, int c, int color)
03560 {
03561        int cx, cy, px, py, fline;
03562        cx = 0;
03563        cy = 0;
03564 
03565        if ((c < f->offset) || (c >= (f->offset + f->nchars))) {
03566               return;
03567        }
03568 
03569        fline = (c - f->offset) * f->h * f->w;
03570        for (py = y; (py > (y - f->w)); py--) {
03571               for (px = x; (px < (x + f->h)); px++) {
03572                      if (f->data[fline + cy * f->w + cx]) {
03573                             gdImageSetPixel(im, px, py, color);
03574                      }
03575                      cy++;
03576               }
03577               cy = 0;
03578               cx++;
03579        }
03580 }
03581 /* }}} */
03582 
03583 /* {{{ php_imagechar
03584  * arg = 0  ImageChar
03585  * arg = 1  ImageCharUp
03586  * arg = 2  ImageString
03587  * arg = 3  ImageStringUp
03588  */
03589 static void php_imagechar(INTERNAL_FUNCTION_PARAMETERS, int mode)
03590 {
03591        zval *IM;
03592        long SIZE, X, Y, COL;
03593        char *C;
03594        int C_len;
03595        gdImagePtr im;
03596        int ch = 0, col, x, y, size, i, l = 0;
03597        unsigned char *str = NULL;
03598        gdFontPtr font;
03599 
03600        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllsl", &IM, &SIZE, &X, &Y, &C, &C_len, &COL) == FAILURE) {
03601               return;
03602        }
03603 
03604        ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
03605 
03606        col = COL;
03607 
03608        if (mode < 2) {
03609               ch = (int)((unsigned char)*C);
03610        } else {
03611               str = (unsigned char *) estrndup(C, C_len);
03612               l = strlen((char *)str);
03613        }
03614 
03615        y = Y;
03616        x = X;
03617        size = SIZE;
03618 
03619        font = php_find_gd_font(size TSRMLS_CC);
03620 
03621        switch (mode) {
03622               case 0:
03623                      gdImageChar(im, font, x, y, ch, col);
03624                      break;
03625               case 1:
03626                      php_gdimagecharup(im, font, x, y, ch, col);
03627                      break;
03628               case 2:
03629                      for (i = 0; (i < l); i++) {
03630                             gdImageChar(im, font, x, y, (int) ((unsigned char) str[i]), col);
03631                             x += font->w;
03632                      }
03633                      break;
03634               case 3: {
03635                      for (i = 0; (i < l); i++) {
03636                             /* php_gdimagecharup(im, font, x, y, (int) str[i], col); */
03637                             gdImageCharUp(im, font, x, y, (int) str[i], col);
03638                             y -= font->w;
03639                      }
03640                      break;
03641               }
03642        }
03643        if (str) {
03644               efree(str);
03645        }
03646        RETURN_TRUE;
03647 }
03648 /* }}} */
03649 
03650 /* {{{ proto bool imagechar(resource im, int font, int x, int y, string c, int col)
03651    Draw a character */
03652 PHP_FUNCTION(imagechar)
03653 {
03654        php_imagechar(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
03655 }
03656 /* }}} */
03657 
03658 /* {{{ proto bool imagecharup(resource im, int font, int x, int y, string c, int col)
03659    Draw a character rotated 90 degrees counter-clockwise */
03660 PHP_FUNCTION(imagecharup)
03661 {
03662        php_imagechar(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
03663 }
03664 /* }}} */
03665 
03666 /* {{{ proto bool imagestring(resource im, int font, int x, int y, string str, int col)
03667    Draw a string horizontally */
03668 PHP_FUNCTION(imagestring)
03669 {
03670        php_imagechar(INTERNAL_FUNCTION_PARAM_PASSTHRU, 2);
03671 }
03672 /* }}} */
03673 
03674 /* {{{ proto bool imagestringup(resource im, int font, int x, int y, string str, int col)
03675    Draw a string vertically - rotated 90 degrees counter-clockwise */
03676 PHP_FUNCTION(imagestringup)
03677 {
03678        php_imagechar(INTERNAL_FUNCTION_PARAM_PASSTHRU, 3);
03679 }
03680 /* }}} */
03681 
03682 /* {{{ 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)
03683    Copy part of an image */
03684 PHP_FUNCTION(imagecopy)
03685 {
03686        zval *SIM, *DIM;
03687        long SX, SY, SW, SH, DX, DY;
03688        gdImagePtr im_dst, im_src;
03689        int srcH, srcW, srcY, srcX, dstY, dstX;
03690 
03691        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrllllll", &DIM, &SIM, &DX, &DY, &SX, &SY, &SW, &SH) == FAILURE) {
03692               return;
03693        }
03694 
03695        ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
03696        ZEND_FETCH_RESOURCE(im_dst, gdImagePtr, &DIM, -1, "Image", le_gd);
03697 
03698        srcX = SX;
03699        srcY = SY;
03700        srcH = SH;
03701        srcW = SW;
03702        dstX = DX;
03703        dstY = DY;
03704 
03705        gdImageCopy(im_dst, im_src, dstX, dstY, srcX, srcY, srcW, srcH);
03706        RETURN_TRUE;
03707 }
03708 /* }}} */
03709 
03710 #if HAVE_LIBGD15
03711 /* {{{ 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)
03712    Merge one part of an image with another */
03713 PHP_FUNCTION(imagecopymerge)
03714 {
03715        zval *SIM, *DIM;
03716        long SX, SY, SW, SH, DX, DY, PCT;
03717        gdImagePtr im_dst, im_src;
03718        int srcH, srcW, srcY, srcX, dstY, dstX, pct;
03719 
03720        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrlllllll", &DIM, &SIM, &DX, &DY, &SX, &SY, &SW, &SH, &PCT) == FAILURE) {
03721               return;
03722        }
03723 
03724        ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
03725        ZEND_FETCH_RESOURCE(im_dst, gdImagePtr, &DIM, -1, "Image", le_gd);
03726 
03727        srcX = SX;
03728        srcY = SY;
03729        srcH = SH;
03730        srcW = SW;
03731        dstX = DX;
03732        dstY = DY;
03733        pct  = PCT;
03734 
03735        gdImageCopyMerge(im_dst, im_src, dstX, dstY, srcX, srcY, srcW, srcH, pct);
03736        RETURN_TRUE;
03737 }
03738 /* }}} */
03739 
03740 /* {{{ 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)
03741    Merge one part of an image with another */
03742 PHP_FUNCTION(imagecopymergegray)
03743 {
03744        zval *SIM, *DIM;
03745        long SX, SY, SW, SH, DX, DY, PCT;
03746        gdImagePtr im_dst, im_src;
03747        int srcH, srcW, srcY, srcX, dstY, dstX, pct;
03748 
03749        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrlllllll", &DIM, &SIM, &DX, &DY, &SX, &SY, &SW, &SH, &PCT) == FAILURE) {
03750               return;
03751        }
03752 
03753        ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
03754        ZEND_FETCH_RESOURCE(im_dst, gdImagePtr, &DIM, -1, "Image", le_gd);
03755 
03756        srcX = SX;
03757        srcY = SY;
03758        srcH = SH;
03759        srcW = SW;
03760        dstX = DX;
03761        dstY = DY;
03762        pct  = PCT;
03763 
03764        gdImageCopyMergeGray(im_dst, im_src, dstX, dstY, srcX, srcY, srcW, srcH, pct);
03765        RETURN_TRUE;
03766 }
03767 /* }}} */
03768 #endif
03769 
03770 /* {{{ 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)
03771    Copy and resize part of an image */
03772 PHP_FUNCTION(imagecopyresized)
03773 {
03774        zval *SIM, *DIM;
03775        long SX, SY, SW, SH, DX, DY, DW, DH;
03776        gdImagePtr im_dst, im_src;
03777        int srcH, srcW, dstH, dstW, srcY, srcX, dstY, dstX;
03778 
03779        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrllllllll", &DIM, &SIM, &DX, &DY, &SX, &SY, &DW, &DH, &SW, &SH) == FAILURE) {
03780               return;
03781        }
03782 
03783        ZEND_FETCH_RESOURCE(im_dst, gdImagePtr, &DIM, -1, "Image", le_gd);
03784        ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
03785 
03786        srcX = SX;
03787        srcY = SY;
03788        srcH = SH;
03789        srcW = SW;
03790        dstX = DX;
03791        dstY = DY;
03792        dstH = DH;
03793        dstW = DW;
03794 
03795        if (dstW <= 0 || dstH <= 0 || srcW <= 0 || srcH <= 0) {
03796               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid image dimensions");
03797               RETURN_FALSE;
03798        }
03799 
03800        gdImageCopyResized(im_dst, im_src, dstX, dstY, srcX, srcY, dstW, dstH, srcW, srcH);
03801        RETURN_TRUE;
03802 }
03803 /* }}} */
03804 
03805 /* {{{ proto int imagesx(resource im)
03806    Get image width */
03807 PHP_FUNCTION(imagesx)
03808 {
03809        zval *IM;
03810        gdImagePtr im;
03811 
03812        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &IM) == FAILURE) {
03813               return;
03814        }
03815 
03816        ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
03817 
03818        RETURN_LONG(gdImageSX(im));
03819 }
03820 /* }}} */
03821 
03822 /* {{{ proto int imagesy(resource im)
03823    Get image height */
03824 PHP_FUNCTION(imagesy)
03825 {
03826        zval *IM;
03827        gdImagePtr im;
03828 
03829        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &IM) == FAILURE) {
03830               return;
03831        }
03832 
03833        ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
03834 
03835        RETURN_LONG(gdImageSY(im));
03836 }
03837 /* }}} */
03838 
03839 #ifdef ENABLE_GD_TTF
03840 #define TTFTEXT_DRAW 0
03841 #define TTFTEXT_BBOX 1
03842 #endif
03843 
03844 #ifdef ENABLE_GD_TTF
03845 
03846 #if  HAVE_LIBFREETYPE && HAVE_GD_STRINGFTEX
03847 /* {{{ proto array imageftbbox(float size, float angle, string font_file, string text [, array extrainfo])
03848    Give the bounding box of a text using fonts via freetype2 */
03849 PHP_FUNCTION(imageftbbox)
03850 {
03851        php_imagettftext_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, TTFTEXT_BBOX, 1);
03852 }
03853 /* }}} */
03854 
03855 /* {{{ proto array imagefttext(resource im, float size, float angle, int x, int y, int col, string font_file, string text [, array extrainfo])
03856    Write text to the image using fonts via freetype2 */
03857 PHP_FUNCTION(imagefttext)
03858 {
03859        php_imagettftext_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, TTFTEXT_DRAW, 1);
03860 }
03861 /* }}} */
03862 #endif
03863 
03864 /* {{{ proto array imagettfbbox(float size, float angle, string font_file, string text)
03865    Give the bounding box of a text using TrueType fonts */
03866 PHP_FUNCTION(imagettfbbox)
03867 {
03868        php_imagettftext_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, TTFTEXT_BBOX, 0);
03869 }
03870 /* }}} */
03871 
03872 /* {{{ proto array imagettftext(resource im, float size, float angle, int x, int y, int col, string font_file, string text)
03873    Write text to the image using a TrueType font */
03874 PHP_FUNCTION(imagettftext)
03875 {
03876        php_imagettftext_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, TTFTEXT_DRAW, 0);
03877 }
03878 /* }}} */
03879 
03880 /* {{{ php_imagettftext_common
03881  */
03882 static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int mode, int extended)
03883 {
03884        zval *IM, *EXT = NULL;
03885        gdImagePtr im=NULL;
03886        long col = -1, x = -1, y = -1;
03887        int str_len, fontname_len, i, brect[8];
03888        double ptsize, angle;
03889        char *str = NULL, *fontname = NULL;
03890        char *error = NULL;
03891        int argc = ZEND_NUM_ARGS();
03892 #if HAVE_GD_STRINGFTEX
03893        gdFTStringExtra strex = {0};
03894 #endif
03895 
03896 #if !HAVE_GD_STRINGFTEX
03897        assert(!extended);
03898 #endif
03899 
03900        if (mode == TTFTEXT_BBOX) {
03901               if (argc < 4 || argc > ((extended) ? 5 : 4)) {
03902                      ZEND_WRONG_PARAM_COUNT();
03903               } else if (zend_parse_parameters(argc TSRMLS_CC, "ddss|a", &ptsize, &angle, &fontname, &fontname_len, &str, &str_len, &EXT) == FAILURE) {
03904                      RETURN_FALSE;
03905               }
03906        } else {
03907               if (argc < 8 || argc > ((extended) ? 9 : 8)) {
03908                      ZEND_WRONG_PARAM_COUNT();
03909               } else if (zend_parse_parameters(argc TSRMLS_CC, "rddlllss|a", &IM, &ptsize, &angle, &x, &y, &col, &fontname, &fontname_len, &str, &str_len, &EXT) == FAILURE) {
03910                      RETURN_FALSE;
03911               }
03912               ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
03913        }
03914 
03915        /* convert angle to radians */
03916        angle = angle * (M_PI/180);
03917 
03918 #if HAVE_GD_STRINGFTEX
03919        if (extended && EXT) {      /* parse extended info */
03920               HashPosition pos;
03921 
03922               /* walk the assoc array */
03923               zend_hash_internal_pointer_reset_ex(HASH_OF(EXT), &pos);
03924               do {
03925                      zval ** item;
03926                      char * key;
03927                      ulong num_key;
03928 
03929                      if (zend_hash_get_current_key_ex(HASH_OF(EXT), &key, NULL, &num_key, 0, &pos) != HASH_KEY_IS_STRING) {
03930                             continue;
03931                      }
03932 
03933                      if (zend_hash_get_current_data_ex(HASH_OF(EXT), (void **) &item, &pos) == FAILURE) {
03934                             continue;
03935                      }
03936               
03937                      if (strcmp("linespacing", key) == 0) {
03938                             convert_to_double_ex(item);
03939                             strex.flags |= gdFTEX_LINESPACE;
03940                             strex.linespacing = Z_DVAL_PP(item);
03941                      }
03942 
03943               } while (zend_hash_move_forward_ex(HASH_OF(EXT), &pos) == SUCCESS);
03944        }
03945 #endif
03946 
03947 #ifdef VIRTUAL_DIR
03948        {
03949               char tmp_font_path[MAXPATHLEN];
03950 
03951               if (!VCWD_REALPATH(fontname, tmp_font_path)) {
03952                      fontname = NULL;
03953               }
03954        }
03955 #endif
03956 
03957        PHP_GD_CHECK_OPEN_BASEDIR(fontname, "Invalid font filename");
03958        
03959 #ifdef USE_GD_IMGSTRTTF
03960 # if HAVE_GD_STRINGFTEX
03961        if (extended) {
03962               error = gdImageStringFTEx(im, brect, col, fontname, ptsize, angle, x, y, str, &strex);
03963        }
03964        else
03965 # endif
03966 
03967 # if HAVE_GD_STRINGFT
03968        error = gdImageStringFT(im, brect, col, fontname, ptsize, angle, x, y, str);
03969 # elif HAVE_GD_STRINGTTF
03970        error = gdImageStringTTF(im, brect, col, fontname, ptsize, angle, x, y, str);
03971 # endif
03972 
03973 #endif
03974 
03975        if (error) {
03976               php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", error);
03977               RETURN_FALSE;
03978        }
03979 
03980        array_init(return_value);
03981 
03982        /* return array with the text's bounding box */
03983        for (i = 0; i < 8; i++) {
03984               add_next_index_long(return_value, brect[i]);
03985        }
03986 }
03987 /* }}} */
03988 #endif /* ENABLE_GD_TTF */
03989 
03990 #if HAVE_LIBT1
03991 
03992 /* {{{ php_free_ps_font
03993  */
03994 static void php_free_ps_font(zend_rsrc_list_entry *rsrc TSRMLS_DC)
03995 {
03996        int *font = (int *) rsrc->ptr;
03997 
03998        T1_DeleteFont(*font);
03999        efree(font);
04000 }
04001 /* }}} */
04002 
04003 /* {{{ php_free_ps_enc
04004  */
04005 static void php_free_ps_enc(zend_rsrc_list_entry *rsrc TSRMLS_DC)
04006 {
04007        char **enc = (char **) rsrc->ptr;
04008 
04009        T1_DeleteEncoding(enc);
04010 }
04011 /* }}} */
04012 
04013 /* {{{ proto resource imagepsloadfont(string pathname)
04014    Load a new font from specified file */
04015 PHP_FUNCTION(imagepsloadfont)
04016 {
04017        char *file;
04018        int file_len, f_ind, *font;
04019 #ifdef PHP_WIN32
04020        struct stat st;
04021 #endif
04022 
04023        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_len) == FAILURE) {
04024               return;
04025        }
04026 
04027 #ifdef PHP_WIN32
04028        if (VCWD_STAT(file, &st) < 0) {
04029               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Font file not found (%s)", file);
04030               RETURN_FALSE;
04031        }
04032 #endif
04033 
04034        f_ind = T1_AddFont(file);
04035 
04036        if (f_ind < 0) {
04037               php_error_docref(NULL TSRMLS_CC, E_WARNING, "T1Lib Error (%i): %s", f_ind, T1_StrError(f_ind));
04038               RETURN_FALSE;
04039        }
04040 
04041        if (T1_LoadFont(f_ind)) {
04042               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't load the font");
04043               RETURN_FALSE;
04044        }
04045 
04046        font = (int *) emalloc(sizeof(int));
04047        *font = f_ind;
04048        ZEND_REGISTER_RESOURCE(return_value, font, le_ps_font);
04049 }
04050 /* }}} */
04051 
04052 /* {{{ proto int imagepscopyfont(int font_index)
04053    Make a copy of a font for purposes like extending or reenconding */
04054 /* The function in t1lib which this function uses seem to be buggy...
04055 PHP_FUNCTION(imagepscopyfont)
04056 {
04057        int l_ind, type;
04058        gd_ps_font *nf_ind, *of_ind;
04059        long fnt;
04060 
04061        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &fnt) == FAILURE) {
04062               return;
04063        }
04064 
04065        of_ind = zend_list_find(fnt, &type);
04066 
04067        if (type != le_ps_font) {
04068               php_error_docref(NULL TSRMLS_CC, E_WARNING, "%ld is not a Type 1 font index", fnt);
04069               RETURN_FALSE;
04070        }
04071 
04072        nf_ind = emalloc(sizeof(gd_ps_font));
04073        nf_ind->font_id = T1_CopyFont(of_ind->font_id);
04074 
04075        if (nf_ind->font_id < 0) {
04076               l_ind = nf_ind->font_id;
04077               efree(nf_ind);
04078               switch (l_ind) {
04079                      case -1:
04080                             php_error_docref(NULL TSRMLS_CC, E_WARNING, "FontID %d is not loaded in memory", l_ind);
04081                             RETURN_FALSE;
04082                             break;
04083                      case -2:
04084                             php_error_docref(NULL TSRMLS_CC, E_WARNING, "Tried to copy a logical font");
04085                             RETURN_FALSE;
04086                             break;
04087                      case -3:
04088                             php_error_docref(NULL TSRMLS_CC, E_WARNING, "Memory allocation fault in t1lib");
04089                             RETURN_FALSE;
04090                             break;
04091                      default:
04092                             php_error_docref(NULL TSRMLS_CC, E_WARNING, "An unknown error occurred in t1lib");
04093                             RETURN_FALSE;
04094                             break;
04095               }
04096        }
04097 
04098        nf_ind->extend = 1;
04099        l_ind = zend_list_insert(nf_ind, le_ps_font);
04100        RETURN_LONG(l_ind);
04101 }
04102 */
04103 /* }}} */
04104 
04105 /* {{{ proto bool imagepsfreefont(resource font_index)
04106    Free memory used by a font */
04107 PHP_FUNCTION(imagepsfreefont)
04108 {
04109        zval *fnt;
04110        int *f_ind;
04111 
04112        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &fnt) == FAILURE) {
04113               return;
04114        }
04115 
04116        ZEND_FETCH_RESOURCE(f_ind, int *, &fnt, -1, "Type 1 font", le_ps_font);
04117        zend_list_delete(Z_LVAL_P(fnt));
04118        RETURN_TRUE;
04119 }
04120 /* }}} */
04121 
04122 /* {{{ proto bool imagepsencodefont(resource font_index, string filename)
04123    To change a fonts character encoding vector */
04124 PHP_FUNCTION(imagepsencodefont)
04125 {
04126        zval *fnt;
04127        char *enc, **enc_vector;
04128        int enc_len, *f_ind;
04129 
04130        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &fnt, &enc, &enc_len) == FAILURE) {
04131               return;
04132        }
04133 
04134        ZEND_FETCH_RESOURCE(f_ind, int *, &fnt, -1, "Type 1 font", le_ps_font);
04135 
04136        if ((enc_vector = T1_LoadEncoding(enc)) == NULL) {
04137               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't load encoding vector from %s", enc);
04138               RETURN_FALSE;
04139        }
04140 
04141        T1_DeleteAllSizes(*f_ind);
04142        if (T1_ReencodeFont(*f_ind, enc_vector)) {
04143               T1_DeleteEncoding(enc_vector);
04144               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't re-encode font");
04145               RETURN_FALSE;
04146        }
04147 
04148        zend_list_insert(enc_vector, le_ps_enc);
04149 
04150        RETURN_TRUE;
04151 }
04152 /* }}} */
04153 
04154 /* {{{ proto bool imagepsextendfont(resource font_index, float extend)
04155    Extend or or condense (if extend < 1) a font */
04156 PHP_FUNCTION(imagepsextendfont)
04157 {
04158        zval *fnt;
04159        double ext;
04160        int *f_ind;
04161 
04162        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rd", &fnt, &ext) == FAILURE) {
04163               return;
04164        }
04165 
04166        ZEND_FETCH_RESOURCE(f_ind, int *, &fnt, -1, "Type 1 font", le_ps_font);
04167 
04168        T1_DeleteAllSizes(*f_ind);
04169 
04170        if (ext <= 0) {
04171               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Second parameter %F out of range (must be > 0)", ext);
04172               RETURN_FALSE;
04173        }
04174 
04175        if (T1_ExtendFont(*f_ind, ext) != 0) {
04176               RETURN_FALSE;
04177        }
04178 
04179        RETURN_TRUE;
04180 }
04181 /* }}} */
04182 
04183 /* {{{ proto bool imagepsslantfont(resource font_index, float slant)
04184    Slant a font */
04185 PHP_FUNCTION(imagepsslantfont)
04186 {
04187        zval *fnt;
04188        double slt;
04189        int *f_ind;
04190 
04191        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rd", &fnt, &slt) == FAILURE) {
04192               return;
04193        }
04194 
04195        ZEND_FETCH_RESOURCE(f_ind, int *, &fnt, -1, "Type 1 font", le_ps_font);
04196 
04197        if (T1_SlantFont(*f_ind, slt) != 0) {
04198               RETURN_FALSE;
04199        }
04200 
04201        RETURN_TRUE;
04202 }
04203 /* }}} */
04204 
04205 /* {{{ 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])
04206    Rasterize a string over an image */
04207 PHP_FUNCTION(imagepstext)
04208 {
04209        zval *img, *fnt;
04210        int i, j;
04211        long _fg, _bg, x, y, size, space = 0, aa_steps = 4, width = 0;
04212        int *f_ind;
04213        int h_lines, v_lines, c_ind;
04214        int rd, gr, bl, fg_rd, fg_gr, fg_bl, bg_rd, bg_gr, bg_bl;
04215        int fg_al, bg_al, al;
04216        int aa[16];
04217        int amount_kern, add_width;
04218        double angle = 0.0, extend;
04219        unsigned long aa_greys[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
04220        gdImagePtr bg_img;
04221        GLYPH *str_img;
04222        T1_OUTLINE *char_path, *str_path;
04223        T1_TMATRIX *transform = NULL;
04224        char *str;
04225        int str_len;
04226 
04227        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) {
04228               return;
04229        }
04230 
04231        if (aa_steps != 4 && aa_steps != 16) {
04232               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Antialias steps must be 4 or 16");
04233               RETURN_FALSE;
04234        }
04235 
04236        ZEND_FETCH_RESOURCE(bg_img, gdImagePtr, &img, -1, "Image", le_gd);
04237        ZEND_FETCH_RESOURCE(f_ind, int *, &fnt, -1, "Type 1 font", le_ps_font);
04238 
04239        /* Ensure that the provided colors are valid */
04240        if (_fg < 0 || (!gdImageTrueColor(bg_img) && _fg > gdImageColorsTotal(bg_img))) {
04241               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Foreground color index %ld out of range", _fg);
04242               RETURN_FALSE;
04243        }
04244 
04245        if (_bg < 0 || (!gdImageTrueColor(bg_img) && _fg > gdImageColorsTotal(bg_img))) {
04246               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Background color index %ld out of range", _bg);
04247               RETURN_FALSE;
04248        }
04249 
04250        fg_rd = gdImageRed  (bg_img, _fg);
04251        fg_gr = gdImageGreen(bg_img, _fg);
04252        fg_bl = gdImageBlue (bg_img, _fg);
04253        fg_al = gdImageAlpha(bg_img, _fg);
04254 
04255        bg_rd = gdImageRed  (bg_img, _bg);
04256        bg_gr = gdImageGreen(bg_img, _bg);
04257        bg_bl = gdImageBlue (bg_img, _bg);
04258        bg_al = gdImageAlpha(bg_img, _bg);
04259 
04260        for (i = 0; i < aa_steps; i++) {
04261               rd = bg_rd + (double) (fg_rd - bg_rd) / aa_steps * (i + 1);
04262               gr = bg_gr + (double) (fg_gr - bg_gr) / aa_steps * (i + 1);
04263               bl = bg_bl + (double) (fg_bl - bg_bl) / aa_steps * (i + 1);
04264               al = bg_al + (double) (fg_al - bg_al) / aa_steps * (i + 1);
04265               aa[i] = gdImageColorResolveAlpha(bg_img, rd, gr, bl, al);
04266        }
04267 
04268        T1_AASetBitsPerPixel(8);
04269 
04270        switch (aa_steps) {
04271               case 4:
04272                      T1_AASetGrayValues(0, 1, 2, 3, 4);
04273                      T1_AASetLevel(T1_AA_LOW);
04274                      break;
04275               case 16:
04276                      T1_AAHSetGrayValues(aa_greys);
04277                      T1_AASetLevel(T1_AA_HIGH);
04278                      break;
04279               default:
04280                      php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid value %ld as number of steps for antialiasing", aa_steps);
04281                      RETURN_FALSE;
04282        }
04283 
04284        if (angle) {
04285               transform = T1_RotateMatrix(NULL, angle);
04286        }
04287 
04288        if (width) {
04289               extend = T1_GetExtend(*f_ind);
04290               str_path = T1_GetCharOutline(*f_ind, str[0], size, transform);
04291 
04292               if (!str_path) {
04293                      if (T1_errno) {
04294                             php_error_docref(NULL TSRMLS_CC, E_WARNING, "T1Lib Error: %s", T1_StrError(T1_errno));
04295                      }
04296                      RETURN_FALSE;
04297               }
04298 
04299               for (i = 1; i < str_len; i++) {
04300                      amount_kern = (int) T1_GetKerning(*f_ind, str[i - 1], str[i]);
04301                      amount_kern += str[i - 1] == ' ' ? space : 0;
04302                      add_width = (int) (amount_kern + width) / extend;
04303 
04304                      char_path = T1_GetMoveOutline(*f_ind, add_width, 0, 0, size, transform);
04305                      str_path = T1_ConcatOutlines(str_path, char_path);
04306 
04307                      char_path = T1_GetCharOutline(*f_ind, str[i], size, transform);
04308                      str_path = T1_ConcatOutlines(str_path, char_path);
04309               }
04310               str_img = T1_AAFillOutline(str_path, 0);
04311        } else {
04312               str_img = T1_AASetString(*f_ind, str,  str_len, space, T1_KERNING, size, transform);
04313        }
04314        if (T1_errno) {
04315               php_error_docref(NULL TSRMLS_CC, E_WARNING, "T1Lib Error: %s", T1_StrError(T1_errno));
04316               RETURN_FALSE;
04317        }
04318 
04319        h_lines = str_img->metrics.ascent -  str_img->metrics.descent;
04320        v_lines = str_img->metrics.rightSideBearing - str_img->metrics.leftSideBearing;
04321 
04322        for (i = 0; i < v_lines; i++) {
04323               for (j = 0; j < h_lines; j++) {
04324                      switch (str_img->bits[j * v_lines + i]) {
04325                             case 0:
04326                                    break;
04327                             default:
04328                                    c_ind = aa[str_img->bits[j * v_lines + i] - 1];
04329                                    gdImageSetPixel(bg_img, x + str_img->metrics.leftSideBearing + i, y - str_img->metrics.ascent + j, c_ind);
04330                                    break;
04331                      }
04332               }
04333        }
04334 
04335        array_init(return_value);
04336 
04337        add_next_index_long(return_value, str_img->metrics.leftSideBearing);
04338        add_next_index_long(return_value, str_img->metrics.descent);
04339        add_next_index_long(return_value, str_img->metrics.rightSideBearing);
04340        add_next_index_long(return_value, str_img->metrics.ascent);
04341 }
04342 /* }}} */
04343 
04344 /* {{{ proto array imagepsbbox(string text, resource font, int size [, int space, int tightness, float angle])
04345    Return the bounding box needed by a string if rasterized */
04346 PHP_FUNCTION(imagepsbbox)
04347 {
04348        zval *fnt;
04349        long sz = 0, sp = 0, wd = 0;
04350        char *str;
04351        int i, space = 0, add_width = 0, char_width, amount_kern;
04352        int cur_x, cur_y, dx, dy;
04353        int x1, y1, x2, y2, x3, y3, x4, y4;
04354        int *f_ind;
04355        int str_len, per_char = 0;
04356        int argc = ZEND_NUM_ARGS();
04357        double angle = 0, sin_a = 0, cos_a = 0;
04358        BBox char_bbox, str_bbox = {0, 0, 0, 0};
04359 
04360        if (argc != 3 && argc != 6) {
04361               ZEND_WRONG_PARAM_COUNT();
04362        }
04363        
04364        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "srl|lld", &str, &str_len, &fnt, &sz, &sp, &wd, &angle) == FAILURE) {
04365               return;
04366        }
04367        
04368        if (argc == 6) {
04369               space = sp;
04370               add_width = wd;
04371               angle = angle * M_PI / 180;
04372               sin_a = sin(angle);
04373               cos_a = cos(angle);
04374               per_char =  add_width || angle ? 1 : 0;
04375        }
04376 
04377        ZEND_FETCH_RESOURCE(f_ind, int *, &fnt, -1, "Type 1 font", le_ps_font);
04378 
04379 #define max(a, b) (a > b ? a : b)
04380 #define min(a, b) (a < b ? a : b)
04381 #define new_x(a, b) (int) ((a) * cos_a - (b) * sin_a)
04382 #define new_y(a, b) (int) ((a) * sin_a + (b) * cos_a)
04383 
04384        if (per_char) {
04385               space += T1_GetCharWidth(*f_ind, ' ');
04386               cur_x = cur_y = 0;
04387 
04388               for (i = 0; i < str_len; i++) {
04389                      if (str[i] == ' ') {
04390                             char_bbox.llx = char_bbox.lly = char_bbox.ury = 0;
04391                             char_bbox.urx = char_width = space;
04392                      } else {
04393                             char_bbox = T1_GetCharBBox(*f_ind, str[i]);
04394                             char_width = T1_GetCharWidth(*f_ind, str[i]);
04395                      }
04396                      amount_kern = i ? T1_GetKerning(*f_ind, str[i - 1], str[i]) : 0;
04397 
04398                      /* Transfer character bounding box to right place */
04399                      x1 = new_x(char_bbox.llx, char_bbox.lly) + cur_x;
04400                      y1 = new_y(char_bbox.llx, char_bbox.lly) + cur_y;
04401                      x2 = new_x(char_bbox.llx, char_bbox.ury) + cur_x;
04402                      y2 = new_y(char_bbox.llx, char_bbox.ury) + cur_y;
04403                      x3 = new_x(char_bbox.urx, char_bbox.ury) + cur_x;
04404                      y3 = new_y(char_bbox.urx, char_bbox.ury) + cur_y;
04405                      x4 = new_x(char_bbox.urx, char_bbox.lly) + cur_x;
04406                      y4 = new_y(char_bbox.urx, char_bbox.lly) + cur_y;
04407 
04408                      /* Find min & max values and compare them with current bounding box */
04409                      str_bbox.llx = min(str_bbox.llx, min(x1, min(x2, min(x3, x4))));
04410                      str_bbox.lly = min(str_bbox.lly, min(y1, min(y2, min(y3, y4))));
04411                      str_bbox.urx = max(str_bbox.urx, max(x1, max(x2, max(x3, x4))));
04412                      str_bbox.ury = max(str_bbox.ury, max(y1, max(y2, max(y3, y4))));
04413 
04414                      /* Move to the next base point */
04415                      dx = new_x(char_width + add_width + amount_kern, 0);
04416                      dy = new_y(char_width + add_width + amount_kern, 0);
04417                      cur_x += dx;
04418                      cur_y += dy;
04419                      /*
04420                      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);
04421                      */
04422               }
04423 
04424        } else {
04425               str_bbox = T1_GetStringBBox(*f_ind, str, str_len, space, T1_KERNING);
04426        }
04427 
04428        if (T1_errno) {
04429               RETURN_FALSE;
04430        }
04431 
04432        array_init(return_value);
04433        /*
04434        printf("%d %d %d %d\n", str_bbox.llx, str_bbox.lly, str_bbox.urx, str_bbox.ury);
04435        */
04436        add_next_index_long(return_value, (int) ceil(((double) str_bbox.llx)*sz/1000));
04437        add_next_index_long(return_value, (int) ceil(((double) str_bbox.lly)*sz/1000));
04438        add_next_index_long(return_value, (int) ceil(((double) str_bbox.urx)*sz/1000));
04439        add_next_index_long(return_value, (int) ceil(((double) str_bbox.ury)*sz/1000));
04440 }
04441 /* }}} */
04442 #endif
04443 
04444 #ifdef HAVE_GD_WBMP
04445 /* {{{ proto bool image2wbmp(resource im [, string filename [, int threshold]])
04446    Output WBMP image to browser or file */
04447 PHP_FUNCTION(image2wbmp)
04448 {
04449        _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_CONVERT_WBM, "WBMP", _php_image_bw_convert);
04450 }
04451 /* }}} */
04452 #endif /* HAVE_GD_WBMP */
04453 
04454 #if defined(HAVE_GD_JPG) && defined(HAVE_GD_WBMP)
04455 /* {{{ proto bool jpeg2wbmp (string f_org, string f_dest, int d_height, int d_width, int threshold)
04456    Convert JPEG image to WBMP image */
04457 PHP_FUNCTION(jpeg2wbmp)
04458 {
04459        _php_image_convert(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_JPG);
04460 }
04461 /* }}} */
04462 #endif
04463 
04464 #if defined(HAVE_GD_PNG) && defined(HAVE_GD_WBMP)
04465 /* {{{ proto bool png2wbmp (string f_org, string f_dest, int d_height, int d_width, int threshold)
04466    Convert PNG image to WBMP image */
04467 PHP_FUNCTION(png2wbmp)
04468 {
04469        _php_image_convert(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_PNG);
04470 }
04471 /* }}} */
04472 #endif
04473 
04474 #ifdef HAVE_GD_WBMP
04475 /* {{{ _php_image_bw_convert
04476  * It converts a gd Image to bw using a threshold value */
04477 static void _php_image_bw_convert(gdImagePtr im_org, gdIOCtx *out, int threshold)
04478 {
04479        gdImagePtr im_dest;
04480        int white, black;
04481        int color, color_org, median;
04482        int dest_height = gdImageSY(im_org);
04483        int dest_width = gdImageSX(im_org);
04484        int x, y;
04485        TSRMLS_FETCH();
04486 
04487        im_dest = gdImageCreate(dest_width, dest_height);
04488        if (im_dest == NULL) {
04489               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to allocate temporary buffer");
04490               return;
04491        }
04492 
04493        white = gdImageColorAllocate(im_dest, 255, 255, 255);
04494        if (white == -1) {
04495               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to allocate the colors for the destination buffer");
04496               return;
04497        }
04498 
04499        black = gdImageColorAllocate(im_dest, 0, 0, 0);
04500        if (black == -1) {
04501               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to allocate the colors for the destination buffer");
04502               return;
04503        }
04504 
04505        if (im_org->trueColor) {
04506               gdImageTrueColorToPalette(im_org, 1, 256);
04507        }
04508 
04509        for (y = 0; y < dest_height; y++) {
04510               for (x = 0; x < dest_width; x++) {
04511                      color_org = gdImageGetPixel(im_org, x, y);
04512                      median = (im_org->red[color_org] + im_org->green[color_org] + im_org->blue[color_org]) / 3;
04513                      if (median < threshold) {
04514                             color = black;
04515                      } else {
04516                             color = white;
04517                      }
04518                      gdImageSetPixel (im_dest, x, y, color);
04519               }
04520        }
04521 #ifdef USE_GD_IOCTX
04522        gdImageWBMPCtx (im_dest, black, out);
04523 #else
04524        gdImageWBMP (im_dest, black, out);
04525 #endif
04526 
04527 }
04528 /* }}} */
04529 
04530 /* {{{ _php_image_convert
04531  * _php_image_convert converts jpeg/png images to wbmp and resizes them as needed  */
04532 static void _php_image_convert(INTERNAL_FUNCTION_PARAMETERS, int image_type )
04533 {
04534        char *f_org, *f_dest;
04535        int f_org_len, f_dest_len;
04536        long height, width, threshold;
04537        gdImagePtr im_org, im_dest, im_tmp;
04538        char *fn_org = NULL;
04539        char *fn_dest = NULL;
04540        FILE *org, *dest;
04541        int dest_height = -1;
04542        int dest_width = -1;
04543        int org_height, org_width;
04544        int white, black;
04545        int color, color_org, median;
04546        int int_threshold;
04547        int x, y;
04548        float x_ratio, y_ratio;
04549 #ifdef HAVE_GD_JPG
04550     long ignore_warning;
04551 #endif
04552        
04553        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sslll", &f_org, &f_org_len, &f_dest, &f_dest_len, &height, &width, &threshold) == FAILURE) {
04554               return;
04555        }
04556 
04557        fn_org  = f_org;
04558        fn_dest = f_dest;
04559        dest_height = height;
04560        dest_width = width;
04561        int_threshold = threshold;
04562 
04563        if (strlen(f_org) != f_org_len) {
04564               RETURN_FALSE;
04565        }
04566 
04567        if (strlen(f_dest) != f_dest_len) {
04568               RETURN_FALSE;
04569        }
04570 
04571        /* Check threshold value */
04572        if (int_threshold < 0 || int_threshold > 8) {
04573               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid threshold value '%d'", int_threshold);
04574               RETURN_FALSE;
04575        }
04576 
04577        /* Check origin file */
04578        PHP_GD_CHECK_OPEN_BASEDIR(fn_org, "Invalid origin filename");
04579 
04580        /* Check destination file */
04581        PHP_GD_CHECK_OPEN_BASEDIR(fn_dest, "Invalid destination filename");
04582 
04583        /* Open origin file */
04584        org = VCWD_FOPEN(fn_org, "rb");
04585        if (!org) {
04586               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open '%s' for reading", fn_org);
04587               RETURN_FALSE;
04588        }
04589 
04590        /* Open destination file */
04591        dest = VCWD_FOPEN(fn_dest, "wb");
04592        if (!dest) {
04593               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open '%s' for writing", fn_dest);
04594               RETURN_FALSE;
04595        }
04596 
04597        switch (image_type) {
04598 #ifdef HAVE_GD_GIF_READ
04599               case PHP_GDIMG_TYPE_GIF:
04600                      im_org = gdImageCreateFromGif(org);
04601                      if (im_org == NULL) {
04602                             php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open '%s' Not a valid GIF file", fn_dest);
04603                             RETURN_FALSE;
04604                      }
04605                      break;
04606 #endif /* HAVE_GD_GIF_READ */
04607 
04608 #ifdef HAVE_GD_JPG
04609               case PHP_GDIMG_TYPE_JPG:
04610                      ignore_warning = INI_INT("gd.jpeg_ignore_warning");
04611 #ifdef HAVE_GD_BUNDLED
04612                      im_org = gdImageCreateFromJpeg(org, ignore_warning);
04613 #else
04614                      im_org = gdImageCreateFromJpeg(org);
04615 #endif
04616                      if (im_org == NULL) {
04617                             php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open '%s' Not a valid JPEG file", fn_dest);
04618                             RETURN_FALSE;
04619                      }
04620                      break;
04621 #endif /* HAVE_GD_JPG */
04622 
04623 
04624 #ifdef HAVE_GD_PNG
04625               case PHP_GDIMG_TYPE_PNG:
04626                      im_org = gdImageCreateFromPng(org);
04627                      if (im_org == NULL) {
04628                             php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open '%s' Not a valid PNG file", fn_dest);
04629                             RETURN_FALSE;
04630                      }
04631                      break;
04632 #endif /* HAVE_GD_PNG */
04633 
04634               default:
04635                      php_error_docref(NULL TSRMLS_CC, E_WARNING, "Format not supported");
04636                      RETURN_FALSE;
04637                      break;
04638        }
04639 
04640        org_width  = gdImageSX (im_org);
04641        org_height = gdImageSY (im_org);
04642 
04643        x_ratio = (float) org_width / (float) dest_width;
04644        y_ratio = (float) org_height / (float) dest_height;
04645 
04646        if (x_ratio > 1 && y_ratio > 1) {
04647               if (y_ratio > x_ratio) {
04648                      x_ratio = y_ratio;
04649               } else {
04650                      y_ratio = x_ratio;
04651               }
04652               dest_width = (int) (org_width / x_ratio);
04653               dest_height = (int) (org_height / y_ratio);
04654        } else {
04655               x_ratio = (float) dest_width / (float) org_width;
04656               y_ratio = (float) dest_height / (float) org_height;
04657 
04658               if (y_ratio < x_ratio) {
04659                      x_ratio = y_ratio;
04660               } else {
04661                      y_ratio = x_ratio;
04662               }
04663               dest_width = (int) (org_width * x_ratio);
04664               dest_height = (int) (org_height * y_ratio);
04665        }
04666 
04667        im_tmp = gdImageCreate (dest_width, dest_height);
04668        if (im_tmp == NULL ) {
04669               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to allocate temporary buffer");
04670               RETURN_FALSE;
04671        }
04672 
04673        gdImageCopyResized (im_tmp, im_org, 0, 0, 0, 0, dest_width, dest_height, org_width, org_height);
04674 
04675        gdImageDestroy(im_org);
04676 
04677        fclose(org);
04678 
04679        im_dest = gdImageCreate(dest_width, dest_height);
04680        if (im_dest == NULL) {
04681               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to allocate destination buffer");
04682               RETURN_FALSE;
04683        }
04684 
04685        white = gdImageColorAllocate(im_dest, 255, 255, 255);
04686        if (white == -1) {
04687               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to allocate the colors for the destination buffer");
04688               RETURN_FALSE;
04689        }
04690 
04691        black = gdImageColorAllocate(im_dest, 0, 0, 0);
04692        if (black == -1) {
04693               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to allocate the colors for the destination buffer");
04694               RETURN_FALSE;
04695        }
04696 
04697        int_threshold = int_threshold * 32;
04698 
04699        for (y = 0; y < dest_height; y++) {
04700               for (x = 0; x < dest_width; x++) {
04701                      color_org = gdImageGetPixel (im_tmp, x, y);
04702                      median = (im_tmp->red[color_org] + im_tmp->green[color_org] + im_tmp->blue[color_org]) / 3;
04703                      if (median < int_threshold) {
04704                             color = black;
04705                      } else {
04706                             color = white;
04707                      }
04708                      gdImageSetPixel (im_dest, x, y, color);
04709               }
04710        }
04711 
04712        gdImageDestroy (im_tmp );
04713 
04714        gdImageWBMP(im_dest, black , dest);
04715 
04716        fflush(dest);
04717        fclose(dest);
04718 
04719        gdImageDestroy(im_dest);
04720 
04721        RETURN_TRUE;
04722 }
04723 /* }}} */
04724 #endif /* HAVE_GD_WBMP */
04725 
04726 #endif /* HAVE_LIBGD */
04727 
04728 /* Section Filters */
04729 #define PHP_GD_SINGLE_RES   \
04730        zval *SIM;    \
04731        gdImagePtr im_src;   \
04732        if (zend_parse_parameters(1 TSRMLS_CC, "r", &SIM) == FAILURE) {       \
04733               RETURN_FALSE; \
04734        }      \
04735        ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);    \
04736        if (im_src == NULL) {       \
04737               RETURN_FALSE; \
04738        }
04739 
04740 static void php_image_filter_negate(INTERNAL_FUNCTION_PARAMETERS)
04741 {
04742        PHP_GD_SINGLE_RES
04743 
04744        if (gdImageNegate(im_src) == 1) {
04745               RETURN_TRUE;
04746        }
04747 
04748        RETURN_FALSE;
04749 }
04750 
04751 static void php_image_filter_grayscale(INTERNAL_FUNCTION_PARAMETERS)
04752 {
04753        PHP_GD_SINGLE_RES
04754 
04755        if (gdImageGrayScale(im_src) == 1) {
04756               RETURN_TRUE;
04757        }
04758 
04759        RETURN_FALSE;
04760 }
04761 
04762 static void php_image_filter_brightness(INTERNAL_FUNCTION_PARAMETERS)
04763 {
04764        zval *SIM;
04765        gdImagePtr im_src;
04766        long brightness, tmp;
04767 
04768        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zll", &SIM, &tmp, &brightness) == FAILURE) {
04769               RETURN_FALSE;
04770        }
04771 
04772        ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
04773 
04774        if (im_src == NULL) {
04775               RETURN_FALSE;
04776        }
04777 
04778        if (gdImageBrightness(im_src, (int)brightness) == 1) {
04779               RETURN_TRUE;
04780        }
04781 
04782        RETURN_FALSE;
04783 }
04784 
04785 static void php_image_filter_contrast(INTERNAL_FUNCTION_PARAMETERS)
04786 {
04787        zval *SIM;
04788        gdImagePtr im_src;
04789        long contrast, tmp;
04790 
04791        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &SIM, &tmp, &contrast) == FAILURE) {
04792               RETURN_FALSE;
04793        }
04794 
04795        ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
04796 
04797        if (im_src == NULL) {
04798               RETURN_FALSE;
04799        }
04800 
04801        if (gdImageContrast(im_src, (int)contrast) == 1) {
04802               RETURN_TRUE;
04803        }
04804 
04805        RETURN_FALSE;
04806 }
04807 
04808 static void php_image_filter_colorize(INTERNAL_FUNCTION_PARAMETERS)
04809 {
04810        zval *SIM;
04811        gdImagePtr im_src;
04812        long r,g,b,tmp;
04813        long a = 0;
04814 
04815        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll|l", &SIM, &tmp, &r, &g, &b, &a) == FAILURE) {
04816               RETURN_FALSE;
04817        }
04818 
04819        ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
04820 
04821        if (im_src == NULL) {
04822               RETURN_FALSE;
04823        }
04824 
04825        if (gdImageColor(im_src, (int) r, (int) g, (int) b, (int) a) == 1) {
04826               RETURN_TRUE;
04827        }
04828 
04829        RETURN_FALSE;
04830 }
04831 
04832 static void php_image_filter_edgedetect(INTERNAL_FUNCTION_PARAMETERS)
04833 {
04834        PHP_GD_SINGLE_RES
04835 
04836        if (gdImageEdgeDetectQuick(im_src) == 1) {
04837               RETURN_TRUE;
04838        }
04839 
04840        RETURN_FALSE;
04841 }
04842 
04843 static void php_image_filter_emboss(INTERNAL_FUNCTION_PARAMETERS)
04844 {
04845        PHP_GD_SINGLE_RES
04846 
04847        if (gdImageEmboss(im_src) == 1) {
04848               RETURN_TRUE;
04849        }
04850 
04851        RETURN_FALSE;
04852 }
04853 
04854 static void php_image_filter_gaussian_blur(INTERNAL_FUNCTION_PARAMETERS)
04855 {
04856        PHP_GD_SINGLE_RES
04857 
04858        if (gdImageGaussianBlur(im_src) == 1) {
04859               RETURN_TRUE;
04860        }
04861 
04862        RETURN_FALSE;
04863 }
04864 
04865 static void php_image_filter_selective_blur(INTERNAL_FUNCTION_PARAMETERS)
04866 {
04867        PHP_GD_SINGLE_RES
04868 
04869        if (gdImageSelectiveBlur(im_src) == 1) {
04870               RETURN_TRUE;
04871        }
04872 
04873        RETURN_FALSE;
04874 }
04875 
04876 static void php_image_filter_mean_removal(INTERNAL_FUNCTION_PARAMETERS)
04877 {
04878        PHP_GD_SINGLE_RES
04879 
04880        if (gdImageMeanRemoval(im_src) == 1) {
04881               RETURN_TRUE;
04882        }
04883 
04884        RETURN_FALSE;
04885 }
04886 
04887 static void php_image_filter_smooth(INTERNAL_FUNCTION_PARAMETERS)
04888 {
04889        zval *SIM;
04890        long tmp;
04891        gdImagePtr im_src;
04892        double weight;
04893 
04894        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rld", &SIM, &tmp, &weight) == FAILURE) {
04895               RETURN_FALSE;
04896        }
04897 
04898        ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
04899 
04900        if (im_src == NULL) {
04901               RETURN_FALSE;
04902        }
04903 
04904        if (gdImageSmooth(im_src, (float)weight)==1) {
04905               RETURN_TRUE;
04906        }
04907 
04908        RETURN_FALSE;
04909 }
04910 
04911 static void php_image_filter_pixelate(INTERNAL_FUNCTION_PARAMETERS)
04912 {
04913        zval *IM;
04914        gdImagePtr im;
04915        long tmp, blocksize;
04916        zend_bool mode = 0;
04917 
04918        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll|b", &IM, &tmp, &blocksize, &mode) == FAILURE) {
04919               RETURN_FALSE;
04920        }
04921 
04922        ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
04923 
04924        if (im == NULL) {
04925               RETURN_FALSE;
04926        }
04927 
04928        if (gdImagePixelate(im, (int) blocksize, (const unsigned int) mode)) {
04929               RETURN_TRUE;
04930        }
04931 
04932        RETURN_FALSE;
04933 }
04934 
04935 /* {{{ proto bool imagefilter(resource src_im, int filtertype, [args] )
04936    Applies Filter an image using a custom angle */
04937 PHP_FUNCTION(imagefilter)
04938 {
04939        zval *tmp;
04940 
04941        typedef void (*image_filter)(INTERNAL_FUNCTION_PARAMETERS);
04942        long filtertype;
04943        image_filter filters[] =
04944        {
04945               php_image_filter_negate ,
04946               php_image_filter_grayscale,
04947               php_image_filter_brightness,
04948               php_image_filter_contrast,
04949               php_image_filter_colorize,
04950               php_image_filter_edgedetect,
04951               php_image_filter_emboss,
04952               php_image_filter_gaussian_blur,
04953               php_image_filter_selective_blur,
04954               php_image_filter_mean_removal,
04955               php_image_filter_smooth,
04956               php_image_filter_pixelate
04957        };
04958 
04959        if (ZEND_NUM_ARGS() < 2 || ZEND_NUM_ARGS() > IMAGE_FILTER_MAX_ARGS) {
04960               WRONG_PARAM_COUNT;
04961        } else if (zend_parse_parameters(2 TSRMLS_CC, "rl", &tmp, &filtertype) == FAILURE) {
04962               return;
04963        }
04964 
04965        if (filtertype >= 0 && filtertype <= IMAGE_FILTER_MAX) {
04966               filters[filtertype](INTERNAL_FUNCTION_PARAM_PASSTHRU);
04967        }
04968 }
04969 /* }}} */
04970 
04971 /* {{{ proto resource imageconvolution(resource src_im, array matrix3x3, double div, double offset)
04972    Apply a 3x3 convolution matrix, using coefficient div and offset */
04973 PHP_FUNCTION(imageconvolution)
04974 {
04975        zval *SIM, *hash_matrix;
04976        zval **var = NULL, **var2 = NULL;
04977        gdImagePtr im_src = NULL;
04978        double div, offset;
04979        int nelem, i, j, res;
04980        float matrix[3][3] = {{0,0,0}, {0,0,0}, {0,0,0}};
04981 
04982        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "radd", &SIM, &hash_matrix, &div, &offset) == FAILURE) {
04983               RETURN_FALSE;
04984        }
04985 
04986        ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
04987 
04988        nelem = zend_hash_num_elements(Z_ARRVAL_P(hash_matrix));
04989        if (nelem != 3) {
04990               php_error_docref(NULL TSRMLS_CC, E_WARNING, "You must have 3x3 array");
04991               RETURN_FALSE;
04992        }
04993 
04994        for (i=0; i<3; i++) {
04995               if (zend_hash_index_find(Z_ARRVAL_P(hash_matrix), (i), (void **) &var) == SUCCESS && Z_TYPE_PP(var) == IS_ARRAY) {
04996                      if (Z_TYPE_PP(var) != IS_ARRAY || zend_hash_num_elements(Z_ARRVAL_PP(var)) != 3 ) {
04997                             php_error_docref(NULL TSRMLS_CC, E_WARNING, "You must have 3x3 array");
04998                             RETURN_FALSE;
04999                      }
05000 
05001                      for (j=0; j<3; j++) {
05002                             if (zend_hash_index_find(Z_ARRVAL_PP(var), (j), (void **) &var2) == SUCCESS) {
05003                                    SEPARATE_ZVAL(var2);
05004                                    convert_to_double(*var2);
05005                                    matrix[i][j] = Z_DVAL_PP(var2);
05006                             } else {
05007                                    php_error_docref(NULL TSRMLS_CC, E_WARNING, "You must have a 3x3 matrix");
05008                                    RETURN_FALSE;
05009                             }
05010                      }
05011               }
05012        }
05013        res = gdImageConvolution(im_src, matrix, div, offset);
05014 
05015        if (res) {
05016               RETURN_TRUE;
05017        } else {
05018               RETURN_FALSE;
05019        }
05020 }
05021 /* }}} */
05022 /* End section: Filters */
05023 
05024 #ifdef HAVE_GD_BUNDLED
05025 /* {{{ proto bool imageantialias(resource im, bool on)
05026    Should antialiased functions used or not*/
05027 PHP_FUNCTION(imageantialias)
05028 {
05029        zval *IM;
05030        zend_bool alias;
05031        gdImagePtr im;
05032 
05033        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rb", &IM, &alias) == FAILURE) {
05034               return;
05035        }
05036 
05037        ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
05038        gdImageAntialias(im, alias);
05039        RETURN_TRUE;
05040 }
05041 /* }}} */
05042 #endif
05043 
05044 /*
05045  * Local variables:
05046  * tab-width: 4
05047  * c-basic-offset: 4
05048  * End:
05049  * vim600: sw=4 ts=4 fdm=marker
05050  * vim<600: sw=4 ts=4
05051  */