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