Annotation of embedaddon/php/ext/gd/gd.c, revision 1.1.1.2

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>