diff options
| author | Mark A. Hershberger <mah@debian.(none)> | 2009-03-25 19:39:21 -0400 |
|---|---|---|
| committer | Mark A. Hershberger <mah@debian.(none)> | 2009-03-25 19:39:21 -0400 |
| commit | 6821b67124604da690c5e9276d5370d679c63ac8 (patch) | |
| tree | befb4ca2520eb577950cef6cb76d10b914cbf67a /ext/gd | |
| parent | cd0b49c72aee33b3e44a9c589fcd93b9e1c7a64f (diff) | |
| download | php-6821b67124604da690c5e9276d5370d679c63ac8.tar.gz | |
Imported Upstream version 5.3.0RC1upstream/5.3.0_RC1upstream/5.3.0RC1
Diffstat (limited to 'ext/gd')
42 files changed, 1462 insertions, 2364 deletions
diff --git a/ext/gd/config.m4 b/ext/gd/config.m4 index 94afc9653..f38aecb48 100644 --- a/ext/gd/config.m4 +++ b/ext/gd/config.m4 @@ -1,5 +1,5 @@ dnl -dnl $Id: config.m4,v 1.154.2.1.2.6 2007/07/03 17:25:33 sniper Exp $ +dnl $Id: config.m4,v 1.154.2.1.2.6.2.2 2009/01/14 19:05:59 tabe Exp $ dnl dnl @@ -28,9 +28,6 @@ fi PHP_ARG_WITH(xpm-dir, for the location of libXpm, [ --with-xpm-dir[=DIR] GD: Set the path to libXpm install prefix], no, no) -PHP_ARG_WITH(ttf, for FreeType 1.x support, -[ --with-ttf[=DIR] GD: Include FreeType 1.x support], no, no) - PHP_ARG_WITH(freetype-dir, for FreeType 2, [ --with-freetype-dir[=DIR] GD: Set the path to FreeType 2 install prefix], no, no) @@ -165,41 +162,6 @@ AC_DEFUN([PHP_GD_XPM],[ fi ]) -AC_DEFUN([PHP_GD_FREETYPE1],[ - if test "$PHP_TTF" != "no"; then - if test "$PHP_FREETYPE_DIR" = "no" || test "$PHP_FREETYPE_DIR" = ""; then - if test -n "$PHP_TTF"; then - for i in $PHP_TTF /usr/local /usr; do - if test -f "$i/include/freetype.h"; then - TTF_DIR=$i - unset TTF_INC_DIR - fi - if test -f "$i/include/freetype/freetype.h"; then - TTF_DIR=$i - TTF_INC_DIR=$i/include/freetype - fi - if test -f "$i/include/freetype1/freetype/freetype.h"; then - TTF_DIR=$i - TTF_INC_DIR=$i/include/freetype1/freetype - fi - test -n "$TTF_DIR" && break - done - fi - if test -n "$TTF_DIR" ; then - AC_DEFINE(HAVE_LIBTTF,1,[ ]) - PHP_ADD_LIBRARY_WITH_PATH(ttf, $TTF_DIR/$PHP_LIBDIR, GD_SHARED_LIBADD) - fi - if test -z "$TTF_INC_DIR"; then - TTF_INC_DIR=$TTF_DIR/include - fi - PHP_ADD_INCLUDE($TTF_INC_DIR) - else - AC_MSG_CHECKING(for FreeType 1 support) - AC_MSG_RESULT([no - FreeType 2.x is to be used instead]) - fi - fi -]) - AC_DEFUN([PHP_GD_FREETYPE2],[ if test "$PHP_FREETYPE_DIR" != "no"; then @@ -306,7 +268,7 @@ if test "$PHP_GD" = "yes"; then libgd/gdxpm.c libgd/gdfontt.c libgd/gdfonts.c libgd/gdfontmb.c libgd/gdfontl.c \ libgd/gdfontg.c libgd/gdtables.c libgd/gdft.c libgd/gdcache.c libgd/gdkanji.c \ libgd/wbmp.c libgd/gd_wbmp.c libgd/gdhelpers.c libgd/gd_topal.c libgd/gd_gif_in.c \ - libgd/xbm.c libgd/gd_gif_out.c libgd/gd_security.c" + libgd/xbm.c libgd/gd_gif_out.c libgd/gd_security.c libgd/gd_pixelate.c" dnl check for fabsf and floorf which are available since C99 AC_CHECK_FUNCS(fabsf floorf) @@ -322,7 +284,6 @@ dnl Various checks for GD features PHP_GD_PNG PHP_GD_XPM PHP_GD_FREETYPE2 - PHP_GD_FREETYPE1 PHP_GD_T1LIB dnl These are always available with bundled library @@ -370,10 +331,6 @@ dnl enable the support in bundled GD library GDLIB_CFLAGS="$GDLIB_CFLAGS -DHAVE_LIBFREETYPE" fi - if test -n "$TTF_DIR"; then - GDLIB_CFLAGS="$GDLIB_CFLAGS -DHAVE_LIBTTF" - fi - if test -n "$USE_GD_JIS_CONV"; then AC_DEFINE(USE_GD_JISX0208, 1, [ ]) GDLIB_CFLAGS="$GDLIB_CFLAGS -DJISX0208" @@ -392,7 +349,6 @@ dnl Various checks for GD features PHP_GD_PNG PHP_GD_XPM PHP_GD_FREETYPE2 - PHP_GD_FREETYPE1 PHP_GD_T1LIB dnl Header path @@ -441,7 +397,7 @@ dnl dnl Common for both builtin and external GD dnl if test "$PHP_GD" != "no"; then - PHP_NEW_EXTENSION(gd, gd.c gdttf.c $extra_sources, $ext_shared,, \\$(GDLIB_CFLAGS)) + PHP_NEW_EXTENSION(gd, gd.c $extra_sources, $ext_shared,, \\$(GDLIB_CFLAGS)) if test "$GD_MODULE_TYPE" = "builtin"; then GDLIB_CFLAGS="-I$ext_srcdir/libgd $GDLIB_CFLAGS" diff --git a/ext/gd/config.w32 b/ext/gd/config.w32 index b842de983..efec610a5 100644 --- a/ext/gd/config.w32 +++ b/ext/gd/config.w32 @@ -1,4 +1,4 @@ -// $Id: config.w32,v 1.10.4.4 2007/04/17 15:31:45 pajoye Exp $ +// $Id: config.w32,v 1.10.4.4.2.9 2009/01/14 19:06:01 tabe Exp $ // vim:ft=javascript ARG_WITH("gd", "Bundled GD support", "yes,shared"); @@ -6,9 +6,14 @@ ARG_WITH("t1lib", "t1lib support", "yes"); if (PHP_GD != "no") { if (CHECK_LIB("libjpeg.lib", "gd", PHP_GD) && - CHECK_LIB("freetype2.lib", "gd", PHP_GD) && - CHECK_LIB("libpng.lib", "gd", PHP_GD) && - CHECK_HEADER_ADD_INCLUDE("gd.h", "CFLAGS_GD", PHP_GD + ";ext\\gd\\libgd") + (CHECK_LIB("freetype_a.lib", "gd", PHP_GD) || CHECK_LIB("freetype2.lib", "gd", PHP_GD) ) && + (CHECK_LIB("libpng_a.lib", "gd", PHP_GD) || CHECK_LIB("libpng.lib", "gd", PHP_GD) ) && + CHECK_HEADER_ADD_INCLUDE("gd.h", "CFLAGS_GD", PHP_GD + ";ext\\gd\\libgd") && + (CHECK_LIB("libiconv_a.lib", "gd", PHP_GD) || CHECK_LIB("libiconv.lib", "gd", PHP_GD) || + CHECK_LIB("iconv_a.lib", "gd", PHP_GD) || CHECK_LIB("iconv.lib", "gd", PHP_GD)) && + CHECK_HEADER_ADD_INCLUDE("iconv.h", "CFLAGS_GD", PHP_GD) && + (((PHP_ZLIB=="no") && (CHECK_LIB("zlib_a.lib", "gd", PHP_GD) || CHECK_LIB("zlib.lib", "gd", PHP_GD))) || + (PHP_ZLIB_SHARED && CHECK_LIB("zlib.lib", "gd", PHP_GD)) || (PHP_ZLIB == "yes" && (!PHP_ZLIB_SHARED))) ) { if (PHP_T1LIB != "no") { if (CHECK_LIB("T1_StaticMD.lib", "gd", PHP_GD) && @@ -20,19 +25,15 @@ if (PHP_GD != "no") { } } - if (PHP_ZLIB == "no" || PHP_ZLIB_SHARED) { - CHECK_LIB("zlib.lib", "gd", PHP_GD); - } - CHECK_LIB("User32.lib", "gd", PHP_GD); CHECK_LIB("Gdi32.lib", "gd", PHP_GD); - EXTENSION("gd", "gd.c gdttf.c", null, "-Iext/gd/libgd", "php_gd2.dll"); + EXTENSION("gd", "gd.c", null, "-Iext/gd/libgd", "php_gd2.dll"); ADD_SOURCES("ext/gd/libgd", "gd2copypal.c gd_arc_f_buggy.c gd.c \ gdcache.c gdfontg.c gdfontl.c gdfontmb.c gdfonts.c gdfontt.c \ gdft.c gd_gd2.c gd_gd.c gd_gif_in.c gd_gif_out.c gdhelpers.c gd_io.c gd_io_dp.c \ gd_io_file.c gd_io_ss.c gd_jpeg.c gdkanji.c gd_png.c gd_ss.c \ - gdtables.c gd_topal.c gd_wbmp.c gdxpm.c wbmp.c xbm.c gd_security.c", "gd"); + gdtables.c gd_topal.c gd_wbmp.c gdxpm.c wbmp.c xbm.c gd_security.c gd_pixelate.c", "gd"); AC_DEFINE('HAVE_LIBGD', 1, 'GD support'); ADD_FLAG("CFLAGS_GD", " \ /D HAVE_GD_DYNAMIC_CTX_EX=1 \ @@ -59,6 +60,7 @@ if (PHP_GD != "no") { /D HAVE_LIBGD204=1 \ /D HAVE_LIBJPEG \ /D HAVE_LIBPNG \ +/D HAVE_COLORCLOSESTHWB \ /D USE_GD_IMGSTRTTF \ /D USE_GD_IOCTX \ /D MSWIN32 \ diff --git a/ext/gd/gd.c b/ext/gd/gd.c index af40a2bb0..0ed331088 100644 --- a/ext/gd/gd.c +++ b/ext/gd/gd.c @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: gd.c,v 1.312.2.20.2.38 2009/01/31 15:28:34 kalle Exp $ */ +/* $Id: gd.c,v 1.312.2.20.2.32.2.31 2009/01/31 15:27:52 kalle Exp $ */ /* gd 1.2 is copyright 1994, 1995, Quest Protein Database Center, Cold Spring Harbor Labs. */ @@ -29,11 +29,6 @@ #include "config.h" #endif -#ifdef HAVE_GD_PNG -/* needs to be first */ -#include <png.h> -#endif - #include "php.h" #include "php_ini.h" #include "ext/standard/head.h" @@ -43,6 +38,7 @@ #include "ext/standard/info.h" #include "php_open_temporary_file.h" + #if HAVE_SYS_WAIT_H # include <sys/wait.h> #endif @@ -73,6 +69,8 @@ static void php_free_ps_enc(zend_rsrc_list_entry *rsrc TSRMLS_DC); #include <gdfontmb.h> /* 3 Medium bold font */ #include <gdfontl.h> /* 4 Large font */ #include <gdfontg.h> /* 5 Giant font */ +#include <gdhelpers.h> + #ifdef HAVE_GD_WBMP #include "libgd/wbmp.h" #endif @@ -80,12 +78,7 @@ static void php_free_ps_enc(zend_rsrc_list_entry *rsrc TSRMLS_DC); # ifdef HAVE_LIBFREETYPE # include <ft2build.h> # include FT_FREETYPE_H -# else -# ifdef HAVE_LIBTTF -# include <freetype.h> -# endif # endif -# include "gdttf.h" #endif #ifndef M_PI @@ -148,8 +141,9 @@ int gdImageColorClosestHWB(gdImagePtr im, int r, int g, int b); #define IMAGE_FILTER_SELECTIVE_BLUR 8 #define IMAGE_FILTER_MEAN_REMOVAL 9 #define IMAGE_FILTER_SMOOTH 10 -#define IMAGE_FILTER_MAX 10 -#define IMAGE_FILTER_MAX_ARGS 5 +#define IMAGE_FILTER_PIXELATE 11 +#define IMAGE_FILTER_MAX 11 +#define IMAGE_FILTER_MAX_ARGS 6 static void php_image_filter_negate(INTERNAL_FUNCTION_PARAMETERS); static void php_image_filter_grayscale(INTERNAL_FUNCTION_PARAMETERS); static void php_image_filter_brightness(INTERNAL_FUNCTION_PARAMETERS); @@ -161,6 +155,7 @@ static void php_image_filter_gaussian_blur(INTERNAL_FUNCTION_PARAMETERS); static void php_image_filter_selective_blur(INTERNAL_FUNCTION_PARAMETERS); static void php_image_filter_mean_removal(INTERNAL_FUNCTION_PARAMETERS); static void php_image_filter_smooth(INTERNAL_FUNCTION_PARAMETERS); +static void php_image_filter_pixelate(INTERNAL_FUNCTION_PARAMETERS); #endif /* End Section filters declarations */ static gdImagePtr _php_image_create_from_string (zval **Data, char *tn, gdImagePtr (*ioctx_func_p)() TSRMLS_DC); @@ -171,57 +166,45 @@ static void _php_image_convert(INTERNAL_FUNCTION_PARAMETERS, int image_type); static void _php_image_bw_convert(gdImagePtr im_org, gdIOCtx *out, int threshold); /* {{{ arginfo */ -static ZEND_BEGIN_ARG_INFO(arginfo_gd_info, 0) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO(arginfo_imageloadfont, 0) ZEND_ARG_INFO(0, filename) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO(arginfo_imagesetstyle, 0) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, styles) /* ARRAY_INFO(0, styles, 0) */ ZEND_END_ARG_INFO() -#if HAVE_LIBGD20 -static ZEND_BEGIN_ARG_INFO(arginfo_imagecreatetruecolor, 0) ZEND_ARG_INFO(0, x_size) ZEND_ARG_INFO(0, y_size) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO(arginfo_imageistruecolor, 0) ZEND_ARG_INFO(0, im) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO(arginfo_imagetruecolortopalette, 0) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, ditherFlag) ZEND_ARG_INFO(0, colorsWanted) ZEND_END_ARG_INFO() -#endif #if HAVE_GD_BUNDLED -static ZEND_BEGIN_ARG_INFO(arginfo_imagecolormatch, 0) ZEND_ARG_INFO(0, im1) ZEND_ARG_INFO(0, im2) ZEND_END_ARG_INFO() #endif -#if HAVE_LIBGD20 -static ZEND_BEGIN_ARG_INFO(arginfo_imagesetthickness, 0) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, thickness) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO(arginfo_imagefilledellipse, 0) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, cx) @@ -231,7 +214,6 @@ ZEND_BEGIN_ARG_INFO(arginfo_imagefilledellipse, 0) ZEND_ARG_INFO(0, color) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO(arginfo_imagefilledarc, 0) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, cx) @@ -244,29 +226,23 @@ ZEND_BEGIN_ARG_INFO(arginfo_imagefilledarc, 0) ZEND_ARG_INFO(0, style) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO(arginfo_imagealphablending, 0) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, blend) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO(arginfo_imagesavealpha, 0) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, save) ZEND_END_ARG_INFO() -#endif #if HAVE_GD_BUNDLED -static ZEND_BEGIN_ARG_INFO(arginfo_imagelayereffect, 0) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, effect) ZEND_END_ARG_INFO() #endif -#if HAVE_LIBGD20 -static ZEND_BEGIN_ARG_INFO(arginfo_imagecolorallocatealpha, 0) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, red) @@ -275,7 +251,6 @@ ZEND_BEGIN_ARG_INFO(arginfo_imagecolorallocatealpha, 0) ZEND_ARG_INFO(0, alpha) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO(arginfo_imagecolorresolvealpha, 0) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, red) @@ -284,7 +259,6 @@ ZEND_BEGIN_ARG_INFO(arginfo_imagecolorresolvealpha, 0) ZEND_ARG_INFO(0, alpha) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO(arginfo_imagecolorclosestalpha, 0) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, red) @@ -293,7 +267,6 @@ ZEND_BEGIN_ARG_INFO(arginfo_imagecolorclosestalpha, 0) ZEND_ARG_INFO(0, alpha) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO(arginfo_imagecolorexactalpha, 0) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, red) @@ -302,7 +275,6 @@ ZEND_BEGIN_ARG_INFO(arginfo_imagecolorexactalpha, 0) ZEND_ARG_INFO(0, alpha) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO(arginfo_imagecopyresampled, 0) ZEND_ARG_INFO(0, dst_im) ZEND_ARG_INFO(0, src_im) @@ -315,22 +287,18 @@ ZEND_BEGIN_ARG_INFO(arginfo_imagecopyresampled, 0) ZEND_ARG_INFO(0, src_w) ZEND_ARG_INFO(0, src_h) ZEND_END_ARG_INFO() -#endif #ifdef PHP_WIN32 -static ZEND_BEGIN_ARG_INFO_EX(arginfo_imagegrabwindow, 0, 0, 1) ZEND_ARG_INFO(0, handle) ZEND_ARG_INFO(0, client_area) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO(arginfo_imagegrabscreen, 0) ZEND_END_ARG_INFO() #endif #ifdef HAVE_GD_BUNDLED -static ZEND_BEGIN_ARG_INFO_EX(arginfo_imagerotate, 0, 0, 3) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, angle) @@ -340,7 +308,6 @@ ZEND_END_ARG_INFO() #endif #if HAVE_GD_IMAGESETTILE -static ZEND_BEGIN_ARG_INFO(arginfo_imagesettile, 0) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, tile) @@ -348,84 +315,71 @@ ZEND_END_ARG_INFO() #endif #if HAVE_GD_IMAGESETBRUSH -static ZEND_BEGIN_ARG_INFO(arginfo_imagesetbrush, 0) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, brush) ZEND_END_ARG_INFO() #endif -static ZEND_BEGIN_ARG_INFO(arginfo_imagecreate, 0) ZEND_ARG_INFO(0, x_size) ZEND_ARG_INFO(0, y_size) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO(arginfo_imagetypes, 0) ZEND_END_ARG_INFO() #if HAVE_LIBGD15 -static ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefromstring, 0) ZEND_ARG_INFO(0, image) ZEND_END_ARG_INFO() #endif #ifdef HAVE_GD_GIF_READ -static ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefromgif, 0) ZEND_ARG_INFO(0, filename) ZEND_END_ARG_INFO() #endif #ifdef HAVE_GD_JPG -static ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefromjpeg, 0) ZEND_ARG_INFO(0, filename) ZEND_END_ARG_INFO() #endif #ifdef HAVE_GD_PNG -static ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefrompng, 0) ZEND_ARG_INFO(0, filename) ZEND_END_ARG_INFO() #endif #ifdef HAVE_GD_XBM -static ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefromxbm, 0) ZEND_ARG_INFO(0, filename) ZEND_END_ARG_INFO() #endif #if defined(HAVE_GD_XPM) && defined(HAVE_GD_BUNDLED) -static ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefromxpm, 0) ZEND_ARG_INFO(0, filename) ZEND_END_ARG_INFO() #endif #ifdef HAVE_GD_WBMP -static ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefromwbmp, 0) ZEND_ARG_INFO(0, filename) ZEND_END_ARG_INFO() #endif -static ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefromgd, 0) ZEND_ARG_INFO(0, filename) ZEND_END_ARG_INFO() #ifdef HAVE_GD_GD2 -static ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefromgd2, 0) ZEND_ARG_INFO(0, filename) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefromgd2part, 0) ZEND_ARG_INFO(0, filename) ZEND_ARG_INFO(0, srcX) @@ -436,7 +390,6 @@ ZEND_END_ARG_INFO() #endif #if HAVE_GD_BUNDLED -static ZEND_BEGIN_ARG_INFO_EX(arginfo_imagexbm, 0, 0, 2) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, filename) @@ -445,7 +398,6 @@ ZEND_END_ARG_INFO() #endif #ifdef HAVE_GD_GIF_CREATE -static ZEND_BEGIN_ARG_INFO_EX(arginfo_imagegif, 0, 0, 1) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, filename) @@ -453,7 +405,6 @@ ZEND_END_ARG_INFO() #endif #ifdef HAVE_GD_PNG -static ZEND_BEGIN_ARG_INFO_EX(arginfo_imagepng, 0, 0, 1) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, filename) @@ -461,7 +412,6 @@ ZEND_END_ARG_INFO() #endif #ifdef HAVE_GD_JPG -static ZEND_BEGIN_ARG_INFO_EX(arginfo_imagejpeg, 0, 0, 1) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, filename) @@ -470,7 +420,6 @@ ZEND_END_ARG_INFO() #endif #ifdef HAVE_GD_WBMP -static ZEND_BEGIN_ARG_INFO_EX(arginfo_imagewbmp, 0, 0, 1) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, filename) @@ -478,14 +427,12 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_imagewbmp, 0, 0, 1) ZEND_END_ARG_INFO() #endif -static ZEND_BEGIN_ARG_INFO_EX(arginfo_imagegd, 0, 0, 1) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, filename) ZEND_END_ARG_INFO() #ifdef HAVE_GD_GD2 -static ZEND_BEGIN_ARG_INFO_EX(arginfo_imagegd2, 0, 0, 1) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, filename) @@ -494,12 +441,10 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_imagegd2, 0, 0, 1) ZEND_END_ARG_INFO() #endif -static ZEND_BEGIN_ARG_INFO(arginfo_imagedestroy, 0) ZEND_ARG_INFO(0, im) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO(arginfo_imagecolorallocate, 0) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, red) @@ -508,21 +453,18 @@ ZEND_BEGIN_ARG_INFO(arginfo_imagecolorallocate, 0) ZEND_END_ARG_INFO() #if HAVE_LIBGD15 -static ZEND_BEGIN_ARG_INFO(arginfo_imagepalettecopy, 0) ZEND_ARG_INFO(0, dst) ZEND_ARG_INFO(0, src) ZEND_END_ARG_INFO() #endif -static ZEND_BEGIN_ARG_INFO(arginfo_imagecolorat, 0) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, x) ZEND_ARG_INFO(0, y) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO(arginfo_imagecolorclosest, 0) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, red) @@ -531,7 +473,6 @@ ZEND_BEGIN_ARG_INFO(arginfo_imagecolorclosest, 0) ZEND_END_ARG_INFO() #if HAVE_COLORCLOSESTHWB -static ZEND_BEGIN_ARG_INFO(arginfo_imagecolorclosesthwb, 0) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, red) @@ -540,13 +481,11 @@ ZEND_BEGIN_ARG_INFO(arginfo_imagecolorclosesthwb, 0) ZEND_END_ARG_INFO() #endif -static ZEND_BEGIN_ARG_INFO(arginfo_imagecolordeallocate, 0) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, index) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO(arginfo_imagecolorresolve, 0) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, red) @@ -554,7 +493,6 @@ ZEND_BEGIN_ARG_INFO(arginfo_imagecolorresolve, 0) ZEND_ARG_INFO(0, blue) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO(arginfo_imagecolorexact, 0) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, red) @@ -562,7 +500,6 @@ ZEND_BEGIN_ARG_INFO(arginfo_imagecolorexact, 0) ZEND_ARG_INFO(0, blue) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO(arginfo_imagecolorset, 0) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, color) @@ -571,20 +508,17 @@ ZEND_BEGIN_ARG_INFO(arginfo_imagecolorset, 0) ZEND_ARG_INFO(0, blue) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO(arginfo_imagecolorsforindex, 0) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, index) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO(arginfo_imagegammacorrect, 0) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, inputgamma) ZEND_ARG_INFO(0, outputgamma) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO(arginfo_imagesetpixel, 0) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, x) @@ -592,7 +526,6 @@ ZEND_BEGIN_ARG_INFO(arginfo_imagesetpixel, 0) ZEND_ARG_INFO(0, col) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO(arginfo_imageline, 0) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, x1) @@ -602,7 +535,6 @@ ZEND_BEGIN_ARG_INFO(arginfo_imageline, 0) ZEND_ARG_INFO(0, col) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO(arginfo_imagedashedline, 0) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, x1) @@ -612,7 +544,6 @@ ZEND_BEGIN_ARG_INFO(arginfo_imagedashedline, 0) ZEND_ARG_INFO(0, col) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO(arginfo_imagerectangle, 0) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, x1) @@ -622,7 +553,6 @@ ZEND_BEGIN_ARG_INFO(arginfo_imagerectangle, 0) ZEND_ARG_INFO(0, col) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO(arginfo_imagefilledrectangle, 0) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, x1) @@ -632,7 +562,6 @@ ZEND_BEGIN_ARG_INFO(arginfo_imagefilledrectangle, 0) ZEND_ARG_INFO(0, col) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO(arginfo_imagearc, 0) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, cx) @@ -644,7 +573,6 @@ ZEND_BEGIN_ARG_INFO(arginfo_imagearc, 0) ZEND_ARG_INFO(0, col) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO(arginfo_imageellipse, 0) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, cx) @@ -654,7 +582,6 @@ ZEND_BEGIN_ARG_INFO(arginfo_imageellipse, 0) ZEND_ARG_INFO(0, color) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO(arginfo_imagefilltoborder, 0) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, x) @@ -663,7 +590,6 @@ ZEND_BEGIN_ARG_INFO(arginfo_imagefilltoborder, 0) ZEND_ARG_INFO(0, col) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO(arginfo_imagefill, 0) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, x) @@ -671,24 +597,20 @@ ZEND_BEGIN_ARG_INFO(arginfo_imagefill, 0) ZEND_ARG_INFO(0, col) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO(arginfo_imagecolorstotal, 0) ZEND_ARG_INFO(0, im) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO_EX(arginfo_imagecolortransparent, 0, 0, 1) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, col) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO_EX(arginfo_imageinterlace, 0, 0, 1) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, interlace) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO(arginfo_imagepolygon, 0) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, points) /* ARRAY_INFO(0, points, 0) */ @@ -696,7 +618,6 @@ ZEND_BEGIN_ARG_INFO(arginfo_imagepolygon, 0) ZEND_ARG_INFO(0, col) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO(arginfo_imagefilledpolygon, 0) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, points) /* ARRAY_INFO(0, points, 0) */ @@ -704,17 +625,14 @@ ZEND_BEGIN_ARG_INFO(arginfo_imagefilledpolygon, 0) ZEND_ARG_INFO(0, col) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO(arginfo_imagefontwidth, 0) ZEND_ARG_INFO(0, font) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO(arginfo_imagefontheight, 0) ZEND_ARG_INFO(0, font) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO(arginfo_imagechar, 0) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, font) @@ -724,7 +642,6 @@ ZEND_BEGIN_ARG_INFO(arginfo_imagechar, 0) ZEND_ARG_INFO(0, col) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO(arginfo_imagecharup, 0) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, font) @@ -734,7 +651,6 @@ ZEND_BEGIN_ARG_INFO(arginfo_imagecharup, 0) ZEND_ARG_INFO(0, col) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO(arginfo_imagestring, 0) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, font) @@ -744,7 +660,6 @@ ZEND_BEGIN_ARG_INFO(arginfo_imagestring, 0) ZEND_ARG_INFO(0, col) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO(arginfo_imagestringup, 0) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, font) @@ -754,7 +669,6 @@ ZEND_BEGIN_ARG_INFO(arginfo_imagestringup, 0) ZEND_ARG_INFO(0, col) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO(arginfo_imagecopy, 0) ZEND_ARG_INFO(0, dst_im) ZEND_ARG_INFO(0, src_im) @@ -767,7 +681,6 @@ ZEND_BEGIN_ARG_INFO(arginfo_imagecopy, 0) ZEND_END_ARG_INFO() #if HAVE_LIBGD15 -static ZEND_BEGIN_ARG_INFO(arginfo_imagecopymerge, 0) ZEND_ARG_INFO(0, src_im) ZEND_ARG_INFO(0, dst_im) @@ -780,7 +693,6 @@ ZEND_BEGIN_ARG_INFO(arginfo_imagecopymerge, 0) ZEND_ARG_INFO(0, pct) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO(arginfo_imagecopymergegray, 0) ZEND_ARG_INFO(0, src_im) ZEND_ARG_INFO(0, dst_im) @@ -794,7 +706,6 @@ ZEND_BEGIN_ARG_INFO(arginfo_imagecopymergegray, 0) ZEND_END_ARG_INFO() #endif -static ZEND_BEGIN_ARG_INFO(arginfo_imagecopyresized, 0) ZEND_ARG_INFO(0, dst_im) ZEND_ARG_INFO(0, src_im) @@ -808,19 +719,16 @@ ZEND_BEGIN_ARG_INFO(arginfo_imagecopyresized, 0) ZEND_ARG_INFO(0, src_h) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO(arginfo_imagesx, 0) ZEND_ARG_INFO(0, im) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO(arginfo_imagesy, 0) ZEND_ARG_INFO(0, im) ZEND_END_ARG_INFO() #ifdef ENABLE_GD_TTF -#if HAVE_LIBGD20 && HAVE_LIBFREETYPE && HAVE_GD_STRINGFTEX -static +#if HAVE_LIBFREETYPE && HAVE_GD_STRINGFTEX ZEND_BEGIN_ARG_INFO_EX(arginfo_imageftbbox, 0, 0, 4) ZEND_ARG_INFO(0, size) ZEND_ARG_INFO(0, angle) @@ -829,7 +737,6 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_imageftbbox, 0, 0, 4) ZEND_ARG_INFO(0, extrainfo) /* ARRAY_INFO(0, extrainfo, 0) */ ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO_EX(arginfo_imagefttext, 0, 0, 8) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, size) @@ -843,7 +750,6 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_imagefttext, 0, 0, 8) ZEND_END_ARG_INFO() #endif -static ZEND_BEGIN_ARG_INFO(arginfo_imagettfbbox, 0) ZEND_ARG_INFO(0, size) ZEND_ARG_INFO(0, angle) @@ -851,7 +757,6 @@ ZEND_BEGIN_ARG_INFO(arginfo_imagettfbbox, 0) ZEND_ARG_INFO(0, text) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO(arginfo_imagettftext, 0) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, size) @@ -865,42 +770,35 @@ ZEND_END_ARG_INFO() #endif #ifdef HAVE_LIBT1 -static ZEND_BEGIN_ARG_INFO(arginfo_imagepsloadfont, 0) ZEND_ARG_INFO(0, pathname) ZEND_END_ARG_INFO() /* -static ZEND_BEGIN_ARG_INFO(arginfo_imagepscopyfont, 0) ZEND_ARG_INFO(0, font_index) ZEND_END_ARG_INFO() */ -static ZEND_BEGIN_ARG_INFO(arginfo_imagepsfreefont, 0) ZEND_ARG_INFO(0, font_index) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO(arginfo_imagepsencodefont, 0) ZEND_ARG_INFO(0, font_index) ZEND_ARG_INFO(0, filename) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO(arginfo_imagepsextendfont, 0) ZEND_ARG_INFO(0, font_index) ZEND_ARG_INFO(0, extend) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO(arginfo_imagepsslantfont, 0) ZEND_ARG_INFO(0, font_index) ZEND_ARG_INFO(0, slant) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO_EX(arginfo_imagepstext, 0, 0, 8) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, text) @@ -916,7 +814,6 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_imagepstext, 0, 0, 8) ZEND_ARG_INFO(0, antialias) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO_EX(arginfo_imagepsbbox, 0, 0, 3) ZEND_ARG_INFO(0, text) ZEND_ARG_INFO(0, font) @@ -928,7 +825,6 @@ ZEND_END_ARG_INFO() #endif #ifdef HAVE_GD_WBMP -static ZEND_BEGIN_ARG_INFO_EX(arginfo_image2wbmp, 0, 0, 1) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, filename) @@ -937,7 +833,6 @@ ZEND_END_ARG_INFO() #endif #if defined(HAVE_GD_JPG) && defined(HAVE_GD_WBMP) -static ZEND_BEGIN_ARG_INFO(arginfo_jpeg2wbmp, 0) ZEND_ARG_INFO(0, f_org) ZEND_ARG_INFO(0, f_dest) @@ -948,7 +843,6 @@ ZEND_END_ARG_INFO() #endif #if defined(HAVE_GD_PNG) && defined(HAVE_GD_WBMP) -static ZEND_BEGIN_ARG_INFO(arginfo_png2wbmp, 0) ZEND_ARG_INFO(0, f_org) ZEND_ARG_INFO(0, f_dest) @@ -959,7 +853,6 @@ ZEND_END_ARG_INFO() #endif #ifdef HAVE_GD_BUNDLED -static ZEND_BEGIN_ARG_INFO_EX(arginfo_imagefilter, 0, 0, 2) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, filtertype) @@ -969,7 +862,6 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_imagefilter, 0, 0, 2) ZEND_ARG_INFO(0, arg4) ZEND_END_ARG_INFO() -static ZEND_BEGIN_ARG_INFO(arginfo_imageconvolution, 0) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, matrix3x3) /* ARRAY_INFO(0, matrix3x3, 0) */ @@ -979,7 +871,6 @@ ZEND_END_ARG_INFO() #endif #ifdef HAVE_GD_BUNDLED -static ZEND_BEGIN_ARG_INFO(arginfo_imageantialias, 0) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, on) @@ -990,7 +881,7 @@ ZEND_END_ARG_INFO() /* {{{ gd_functions[] */ -zend_function_entry gd_functions[] = { +const zend_function_entry gd_functions[] = { PHP_FE(gd_info, arginfo_gd_info) PHP_FE(imagearc, arginfo_imagearc) PHP_FE(imageellipse, arginfo_imageellipse) @@ -1020,7 +911,6 @@ zend_function_entry gd_functions[] = { #endif PHP_FE(imagecopyresized, arginfo_imagecopyresized) PHP_FE(imagecreate, arginfo_imagecreate) -#if HAVE_LIBGD20 PHP_FE(imagecreatetruecolor, arginfo_imagecreatetruecolor) PHP_FE(imageistruecolor, arginfo_imageistruecolor) PHP_FE(imagetruecolortopalette, arginfo_imagetruecolortopalette) @@ -1034,7 +924,6 @@ zend_function_entry gd_functions[] = { PHP_FE(imagecolorclosestalpha, arginfo_imagecolorclosestalpha) PHP_FE(imagecolorexactalpha, arginfo_imagecolorexactalpha) PHP_FE(imagecopyresampled, arginfo_imagecopyresampled) -#endif #ifdef PHP_WIN32 PHP_FE(imagegrabwindow, arginfo_imagegrabwindow) @@ -1119,7 +1008,7 @@ zend_function_entry gd_functions[] = { #ifdef ENABLE_GD_TTF PHP_FE(imagettfbbox, arginfo_imagettfbbox) PHP_FE(imagettftext, arginfo_imagettftext) -#if HAVE_LIBGD20 && HAVE_LIBFREETYPE && HAVE_GD_STRINGFTEX +#if HAVE_LIBFREETYPE && HAVE_GD_STRINGFTEX PHP_FE(imageftbbox, arginfo_imageftbbox) PHP_FE(imagefttext, arginfo_imagefttext) #endif @@ -1174,7 +1063,7 @@ zend_module_entry gd_module_entry = { NULL, #endif NULL, -#if HAVE_LIBGD20 && HAVE_GD_STRINGFT && (HAVE_LIBFREETYPE && (HAVE_GD_FONTCACHESHUTDOWN || HAVE_GD_FREEFONTCACHE)) +#if HAVE_GD_STRINGFT && (HAVE_LIBFREETYPE && (HAVE_GD_FONTCACHESHUTDOWN || HAVE_GD_FREEFONTCACHE)) PHP_RSHUTDOWN(gd), #else NULL, @@ -1228,6 +1117,7 @@ PHP_MSHUTDOWN_FUNCTION(gd) #if HAVE_GD_FONTMUTEX && HAVE_LIBFREETYPE gdFontCacheMutexShutdown(); #endif + UNREGISTER_INI_ENTRIES(); return SUCCESS; } #endif @@ -1268,14 +1158,12 @@ PHP_MINIT_FUNCTION(gd) REGISTER_LONG_CONSTANT("IMG_COLOR_STYLEDBRUSHED", gdStyledBrushed, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("IMG_COLOR_TRANSPARENT", gdTransparent, CONST_CS | CONST_PERSISTENT); #endif -#if HAVE_LIBGD20 /* for imagefilledarc */ REGISTER_LONG_CONSTANT("IMG_ARC_ROUNDED", gdArc, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("IMG_ARC_PIE", gdPie, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("IMG_ARC_CHORD", gdChord, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("IMG_ARC_NOFILL", gdNoFill, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("IMG_ARC_EDGED", gdEdged, CONST_CS | CONST_PERSISTENT); -#endif /* GD2 image format types */ #ifdef GD2_FMT_RAW REGISTER_LONG_CONSTANT("IMG_GD2_RAW", GD2_FMT_RAW, CONST_CS | CONST_PERSISTENT); @@ -1302,6 +1190,7 @@ PHP_MINIT_FUNCTION(gd) REGISTER_LONG_CONSTANT("IMG_FILTER_EMBOSS", IMAGE_FILTER_EMBOSS, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("IMG_FILTER_MEAN_REMOVAL", IMAGE_FILTER_MEAN_REMOVAL, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("IMG_FILTER_SMOOTH", IMAGE_FILTER_SMOOTH, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("IMG_FILTER_PIXELATE", IMAGE_FILTER_PIXELATE, CONST_CS | CONST_PERSISTENT); /* End Section Filters */ #else REGISTER_LONG_CONSTANT("GD_BUNDLED", 0, CONST_CS | CONST_PERSISTENT); @@ -1340,7 +1229,7 @@ PHP_MINIT_FUNCTION(gd) /* {{{ PHP_RSHUTDOWN_FUNCTION */ -#if HAVE_LIBGD20 && HAVE_GD_STRINGFT && (HAVE_LIBFREETYPE && (HAVE_GD_FONTCACHESHUTDOWN || HAVE_GD_FREEFONTCACHE)) +#if HAVE_GD_STRINGFT && (HAVE_LIBFREETYPE && (HAVE_GD_FONTCACHESHUTDOWN || HAVE_GD_FREEFONTCACHE)) PHP_RSHUTDOWN_FUNCTION(gd) { #if HAVE_GD_FONTCACHESHUTDOWN @@ -1355,14 +1244,8 @@ PHP_RSHUTDOWN_FUNCTION(gd) #if HAVE_GD_BUNDLED #define PHP_GD_VERSION_STRING "bundled (2.0.34 compatible)" -#elif HAVE_LIBGD20 -#define PHP_GD_VERSION_STRING "2.0 or higher" -#elif HAVE_GDIMAGECOLORRESOLVE -#define PHP_GD_VERSION_STRING "1.6.2 or higher" -#elif HAVE_LIBGD13 -#define PHP_GD_VERSION_STRING "between 1.3 and 1.6.1" #else -#define PHP_GD_VERSION_STRING "1.2" +#define PHP_GD_VERSION_STRING "2.0" #endif /* {{{ PHP_MINFO_FUNCTION @@ -1391,13 +1274,6 @@ PHP_MINFO_FUNCTION(gd) #endif php_info_print_table_row(2, "FreeType Version", tmp); } -#elif HAVE_LIBTTF - php_info_print_table_row(2, "FreeType Linkage", "with TTF library"); - { - char tmp[256]; - snprintf(tmp, sizeof(tmp), "%d.%d", TT_FREETYPE_MAJOR, TT_FREETYPE_MINOR); - php_info_print_table_row(2, "FreeType Version", tmp); - } #else php_info_print_table_row(2, "FreeType Linkage", "with unknown library"); #endif @@ -1416,10 +1292,17 @@ PHP_MINFO_FUNCTION(gd) php_info_print_table_row(2, "GIF Create Support", "enabled"); #endif #ifdef HAVE_GD_JPG - php_info_print_table_row(2, "JPG Support", "enabled"); + { + char tmp[12]; + snprintf(tmp, sizeof(tmp), "%d", gdJpegGetVersionInt()); + php_info_print_table_row(2, "JPG Support", "enabled"); + php_info_print_table_row(2, "libJPEG Version", tmp); + } #endif + #ifdef HAVE_GD_PNG php_info_print_table_row(2, "PNG Support", "enabled"); + php_info_print_table_row(2, "libPNG Version", gdPngGetVersionString()); #endif #ifdef HAVE_GD_WBMP php_info_print_table_row(2, "WBMP Support", "enabled"); @@ -1434,6 +1317,7 @@ PHP_MINFO_FUNCTION(gd) php_info_print_table_row(2, "JIS-mapped Japanese Font Support", "enabled"); #endif php_info_print_table_end(); + DISPLAY_INI_ENTRIES(); } /* }}} */ @@ -1441,8 +1325,7 @@ PHP_MINFO_FUNCTION(gd) */ PHP_FUNCTION(gd_info) { - if (ZEND_NUM_ARGS() != 0) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters_none() == FAILURE) { RETURN_FALSE; } @@ -1454,8 +1337,6 @@ PHP_FUNCTION(gd_info) add_assoc_bool(return_value, "FreeType Support", 1); #if HAVE_LIBFREETYPE add_assoc_string(return_value, "FreeType Linkage", "with freetype", 1); -#elif HAVE_LIBTTF - add_assoc_string(return_value, "FreeType Linkage", "with TTF library", 1); #else add_assoc_string(return_value, "FreeType Linkage", "with unknown library", 1); #endif @@ -1580,19 +1461,17 @@ int gdImageColorResolve(gdImagePtr im, int r, int g, int b) Load a new font */ PHP_FUNCTION(imageloadfont) { - zval **file; - int hdr_size = sizeof(gdFont) - sizeof(char *); + char *file; + int file_name, hdr_size = sizeof(gdFont) - sizeof(char *); int ind, body_size, n = 0, b, i, body_size_check; gdFontPtr font; php_stream *stream; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &file) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_name) == FAILURE) { + return; } - convert_to_string_ex(file); - - stream = php_stream_open_wrapper(Z_STRVAL_PP(file), "rb", ENFORCE_SAFE_MODE | IGNORE_PATH | IGNORE_URL_WIN | REPORT_ERRORS, NULL); + stream = php_stream_open_wrapper(file, "rb", ENFORCE_SAFE_MODE | IGNORE_PATH | IGNORE_URL_WIN | REPORT_ERRORS, NULL); if (stream == NULL) { RETURN_FALSE; } @@ -1637,7 +1516,7 @@ PHP_FUNCTION(imageloadfont) font->nchars = FLIPWORD(font->nchars); body_size = font->w * font->h * font->nchars; } - + if (overflow2(font->nchars, font->h)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error reading font, invalid font header"); efree(font); @@ -1651,9 +1530,6 @@ PHP_FUNCTION(imageloadfont) RETURN_FALSE; } - - - if (body_size != body_size_check) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error reading font"); efree(font); @@ -1694,29 +1570,27 @@ PHP_FUNCTION(imageloadfont) Set the line drawing styles for use with imageline and IMG_COLOR_STYLED. */ PHP_FUNCTION(imagesetstyle) { - zval **IM, **styles; + zval *IM, *styles; gdImagePtr im; int * stylearr; int index; HashPosition pos; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &IM, &styles) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ra", &IM, &styles) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); - - convert_to_array_ex(styles); + ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd); /* copy the style values in the stylearr */ - stylearr = safe_emalloc(sizeof(int), zend_hash_num_elements(HASH_OF(*styles)), 0); + stylearr = safe_emalloc(sizeof(int), zend_hash_num_elements(HASH_OF(styles)), 0); - zend_hash_internal_pointer_reset_ex(HASH_OF(*styles), &pos); + zend_hash_internal_pointer_reset_ex(HASH_OF(styles), &pos); - for (index = 0;; zend_hash_move_forward_ex(HASH_OF(*styles), &pos)) { + for (index = 0;; zend_hash_move_forward_ex(HASH_OF(styles), &pos)) { zval ** item; - if (zend_hash_get_current_data_ex(HASH_OF(*styles), (void **) &item, &pos) == FAILURE) { + if (zend_hash_get_current_data_ex(HASH_OF(styles), (void **) &item, &pos) == FAILURE) { break; } @@ -1733,29 +1607,23 @@ PHP_FUNCTION(imagesetstyle) } /* }}} */ -#if HAVE_LIBGD20 /* {{{ proto resource imagecreatetruecolor(int x_size, int y_size) Create a new true color image */ PHP_FUNCTION(imagecreatetruecolor) { - zval **x_size, **y_size; + long x_size, y_size; gdImagePtr im; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &x_size, &y_size) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &x_size, &y_size) == FAILURE) { + return; } - convert_to_long_ex(x_size); - convert_to_long_ex(y_size); - - if (Z_LVAL_PP(x_size) <= 0 || Z_LVAL_PP(y_size) <= 0 || - Z_LVAL_PP(x_size) >= INT_MAX || Z_LVAL_PP(y_size) >= INT_MAX - ) { + if (x_size <= 0 || y_size <= 0 || x_size >= INT_MAX || y_size >= INT_MAX) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid image dimensions"); RETURN_FALSE; } - im = gdImageCreateTrueColor(Z_LVAL_PP(x_size), Z_LVAL_PP(y_size)); + im = gdImageCreateTrueColor(x_size, y_size); if (!im) { RETURN_FALSE; @@ -1769,14 +1637,14 @@ PHP_FUNCTION(imagecreatetruecolor) return true if the image uses truecolor */ PHP_FUNCTION(imageistruecolor) { - zval **IM; + zval *IM; gdImagePtr im; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &IM) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &IM) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); + ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd); RETURN_BOOL(im->trueColor); } @@ -1786,23 +1654,22 @@ PHP_FUNCTION(imageistruecolor) Convert a true colour image to a palette based image with a number of colours, optionally using dithering. */ PHP_FUNCTION(imagetruecolortopalette) { - zval **IM, **dither, **ncolors; + zval *IM; + zend_bool dither; + long ncolors; gdImagePtr im; - if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &IM, &dither, &ncolors) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rbl", &IM, &dither, &ncolors) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); - - convert_to_boolean_ex(dither); - convert_to_long_ex(ncolors); + ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd); - if (Z_LVAL_PP(ncolors) <= 0) { + if (ncolors <= 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Number of colors has to be greater than zero"); RETURN_FALSE; } - gdImageTrueColorToPalette(im, Z_LVAL_PP(dither), Z_LVAL_PP(ncolors)); + gdImageTrueColorToPalette(im, dither, ncolors); RETURN_TRUE; } @@ -1813,16 +1680,16 @@ PHP_FUNCTION(imagetruecolortopalette) Makes the colors of the palette version of an image more closely match the true color version */ PHP_FUNCTION(imagecolormatch) { - zval **IM1, **IM2; + zval *IM1, *IM2; gdImagePtr im1, im2; int result; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &IM1, &IM2 ) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr", &IM1, &IM2) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(im1, gdImagePtr, IM1, -1, "Image", le_gd); - ZEND_FETCH_RESOURCE(im2, gdImagePtr, IM2, -1, "Image", le_gd); + ZEND_FETCH_RESOURCE(im1, gdImagePtr, &IM1, -1, "Image", le_gd); + ZEND_FETCH_RESOURCE(im2, gdImagePtr, &IM2, -1, "Image", le_gd); result = gdImageColorMatch(im1, im2); switch (result) { @@ -1853,17 +1720,17 @@ PHP_FUNCTION(imagecolormatch) Set line thickness for drawing lines, ellipses, rectangles, polygons etc. */ PHP_FUNCTION(imagesetthickness) { - zval **IM, **thick; + zval *IM; + long thick; gdImagePtr im; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &IM, &thick) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &IM, &thick) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); - convert_to_long_ex(thick); + ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd); - gdImageSetThickness(im, Z_LVAL_PP(thick)); + gdImageSetThickness(im, thick); RETURN_TRUE; } @@ -1873,22 +1740,17 @@ PHP_FUNCTION(imagesetthickness) Draw an ellipse */ PHP_FUNCTION(imagefilledellipse) { - zval **IM, **cx, **cy, **w, **h, **color; + zval *IM; + long cx, cy, w, h, color; gdImagePtr im; - if (ZEND_NUM_ARGS() != 6 || zend_get_parameters_ex(6, &IM, &cx, &cy, &w, &h, &color) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllll", &IM, &cx, &cy, &w, &h, &color) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); - - convert_to_long_ex(cx); - convert_to_long_ex(cy); - convert_to_long_ex(w); - convert_to_long_ex(h); - convert_to_long_ex(color); + ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd); - gdImageFilledEllipse(im, Z_LVAL_PP(cx), Z_LVAL_PP(cy), Z_LVAL_PP(w), Z_LVAL_PP(h), Z_LVAL_PP(color)); + gdImageFilledEllipse(im, cx, cy, w, h, color); RETURN_TRUE; } @@ -1898,36 +1760,28 @@ PHP_FUNCTION(imagefilledellipse) Draw a filled partial ellipse */ PHP_FUNCTION(imagefilledarc) { - zval **IM, **cx, **cy, **w, **h, **ST, **E, **col, **style; + zval *IM; + long cx, cy, w, h, ST, E, col, style; gdImagePtr im; int e, st; - - if (ZEND_NUM_ARGS() != 9 || zend_get_parameters_ex(9, &IM, &cx, &cy, &w, &h, &ST, &E, &col, &style) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllllllll", &IM, &cx, &cy, &w, &h, &ST, &E, &col, &style) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); - - convert_to_long_ex(cx); - convert_to_long_ex(cy); - convert_to_long_ex(w); - convert_to_long_ex(h); - convert_to_long_ex(ST); - convert_to_long_ex(E); - convert_to_long_ex(col); - convert_to_long_ex(style); + ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd); - e = Z_LVAL_PP(E); + e = E; if (e < 0) { e %= 360; } - st = Z_LVAL_PP(ST); + st = ST; if (st < 0) { st %= 360; } - gdImageFilledArc(im, Z_LVAL_PP(cx), Z_LVAL_PP(cy), Z_LVAL_PP(w), Z_LVAL_PP(h), st, e, Z_LVAL_PP(col), Z_LVAL_PP(style)); + gdImageFilledArc(im, cx, cy, w, h, st, e, col, style); RETURN_TRUE; } @@ -1937,60 +1791,58 @@ PHP_FUNCTION(imagefilledarc) Turn alpha blending mode on or off for the given image */ PHP_FUNCTION(imagealphablending) { - zval **IM, **blend; + zval *IM; + zend_bool blend; gdImagePtr im; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &IM, &blend) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rb", &IM, &blend) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); - convert_to_boolean_ex(blend); + ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd); - gdImageAlphaBlending(im, Z_LVAL_PP(blend)); + gdImageAlphaBlending(im, blend); RETURN_TRUE; } /* }}} */ -#if HAVE_LIBGD20 /* {{{ proto bool imagesavealpha(resource im, bool on) Include alpha channel to a saved image */ PHP_FUNCTION(imagesavealpha) { - zval **IM, **save; + zval *IM; + zend_bool save; gdImagePtr im; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &IM, &save) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rb", &IM, &save) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); - convert_to_boolean_ex(save); + ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd); - gdImageSaveAlpha(im, Z_LVAL_PP(save)); + gdImageSaveAlpha(im, save); RETURN_TRUE; } /* }}} */ -#endif #if HAVE_GD_BUNDLED /* {{{ proto bool imagelayereffect(resource im, int effect) Set the alpha blending flag to use the bundled libgd layering effects */ PHP_FUNCTION(imagelayereffect) { - zval **IM, **effect; + zval *IM; + long effect; gdImagePtr im; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &IM, &effect) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &IM, &effect) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); - convert_to_long_ex(effect); + ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd); - gdImageAlphaBlending(im, Z_LVAL_PP(effect) ); + gdImageAlphaBlending(im, effect); RETURN_TRUE; } @@ -2006,7 +1858,7 @@ PHP_FUNCTION(imagecolorallocatealpha) gdImagePtr im; int ct = (-1); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zllll", &IM, &red, &green, &blue, &alpha) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll", &IM, &red, &green, &blue, &alpha) == FAILURE) { RETURN_FALSE; } @@ -2025,21 +1877,17 @@ PHP_FUNCTION(imagecolorallocatealpha) Resolve/Allocate a colour with an alpha level. Works for true colour and palette based images */ PHP_FUNCTION(imagecolorresolvealpha) { - zval **IM, ** red, **green, **blue, **alpha; + zval *IM; + long red, green, blue, alpha; gdImagePtr im; - if (ZEND_NUM_ARGS() != 5 || zend_get_parameters_ex(5, &IM, &red, &green, &blue, &alpha) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll", &IM, &red, &green, &blue, &alpha) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); - - convert_to_long_ex(red); - convert_to_long_ex(green); - convert_to_long_ex(blue); - convert_to_long_ex(alpha); + ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd); - RETURN_LONG(gdImageColorResolveAlpha(im, Z_LVAL_PP(red), Z_LVAL_PP(green), Z_LVAL_PP(blue), Z_LVAL_PP(alpha))); + RETURN_LONG(gdImageColorResolveAlpha(im, red, green, blue, alpha)); } /* }}} */ @@ -2047,21 +1895,17 @@ PHP_FUNCTION(imagecolorresolvealpha) Find the closest matching colour with alpha transparency */ PHP_FUNCTION(imagecolorclosestalpha) { - zval **IM, ** red, **green, **blue, **alpha; + zval *IM; + long red, green, blue, alpha; gdImagePtr im; - if (ZEND_NUM_ARGS() != 5 || zend_get_parameters_ex(5, &IM, &red, &green, &blue, &alpha) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll", &IM, &red, &green, &blue, &alpha) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); - - convert_to_long_ex(red); - convert_to_long_ex(green); - convert_to_long_ex(blue); - convert_to_long_ex(alpha); + ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd); - RETURN_LONG(gdImageColorClosestAlpha(im, Z_LVAL_PP(red), Z_LVAL_PP(green), Z_LVAL_PP(blue), Z_LVAL_PP(alpha))); + RETURN_LONG(gdImageColorClosestAlpha(im, red, green, blue, alpha)); } /* }}} */ @@ -2069,21 +1913,17 @@ PHP_FUNCTION(imagecolorclosestalpha) Find exact match for colour with transparency */ PHP_FUNCTION(imagecolorexactalpha) { - zval **IM, **red, **green, **blue, **alpha; + zval *IM; + long red, green, blue, alpha; gdImagePtr im; - if (ZEND_NUM_ARGS() != 5 || zend_get_parameters_ex(5, &IM, &red, &green, &blue, &alpha) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll", &IM, &red, &green, &blue, &alpha) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); - - convert_to_long_ex(red); - convert_to_long_ex(green); - convert_to_long_ex(blue); - convert_to_long_ex(alpha); + ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd); - RETURN_LONG(gdImageColorExactAlpha(im, Z_LVAL_PP(red), Z_LVAL_PP(green), Z_LVAL_PP(blue), Z_LVAL_PP(alpha))); + RETURN_LONG(gdImageColorExactAlpha(im, red, green, blue, alpha)); } /* }}} */ @@ -2091,41 +1931,32 @@ PHP_FUNCTION(imagecolorexactalpha) Copy and resize part of an image using resampling to help ensure clarity */ PHP_FUNCTION(imagecopyresampled) { - zval **SIM, **DIM, **SX, **SY, **SW, **SH, **DX, **DY, **DW, **DH; + zval *SIM, *DIM; + long SX, SY, SW, SH, DX, DY, DW, DH; gdImagePtr im_dst, im_src; int srcH, srcW, dstH, dstW, srcY, srcX, dstY, dstX; - if (ZEND_NUM_ARGS() != 10 || zend_get_parameters_ex(10, &DIM, &SIM, &DX, &DY, &SX, &SY, &DW, &DH, &SW, &SH) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrllllllll", &DIM, &SIM, &DX, &DY, &SX, &SY, &DW, &DH, &SW, &SH) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(im_dst, gdImagePtr, DIM, -1, "Image", le_gd); - ZEND_FETCH_RESOURCE(im_src, gdImagePtr, SIM, -1, "Image", le_gd); - - convert_to_long_ex(SX); - convert_to_long_ex(SY); - convert_to_long_ex(SW); - convert_to_long_ex(SH); - convert_to_long_ex(DX); - convert_to_long_ex(DY); - convert_to_long_ex(DW); - convert_to_long_ex(DH); + ZEND_FETCH_RESOURCE(im_dst, gdImagePtr, &DIM, -1, "Image", le_gd); + ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd); - srcX = Z_LVAL_PP(SX); - srcY = Z_LVAL_PP(SY); - srcH = Z_LVAL_PP(SH); - srcW = Z_LVAL_PP(SW); - dstX = Z_LVAL_PP(DX); - dstY = Z_LVAL_PP(DY); - dstH = Z_LVAL_PP(DH); - dstW = Z_LVAL_PP(DW); + srcX = SX; + srcY = SY; + srcH = SH; + srcW = SW; + dstX = DX; + dstY = DY; + dstH = DH; + dstW = DW; gdImageCopyResampled(im_dst, im_src, dstX, dstY, srcX, srcY, dstW, dstH, srcW, srcH); RETURN_TRUE; } /* }}} */ -#endif #ifdef PHP_WIN32 /* {{{ proto resource imagegrabwindow(int window_handle [, int client_area]) @@ -2229,13 +2060,15 @@ PHP_FUNCTION(imagegrabscreen) HDC memDC; HBITMAP memBM; HBITMAP hOld; - HINSTANCE handle; - long lwindow_handle; typedef BOOL (WINAPI *tPrintWindow)(HWND, HDC,UINT); tPrintWindow pPrintWindow = 0; gdImagePtr im; hdc = GetDC(0); + if (zend_parse_parameters_none() == FAILURE) { + return; + } + if (!hdc) { RETURN_FALSE; } @@ -2309,15 +2142,15 @@ PHP_FUNCTION(imagerotate) Set the tile image to $tile when filling $image with the "IMG_COLOR_TILED" color */ PHP_FUNCTION(imagesettile) { - zval **IM, **TILE; + zval *IM, *TILE; gdImagePtr im, tile; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &IM, &TILE) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr", &IM, &TILE) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); - ZEND_FETCH_RESOURCE(tile, gdImagePtr, TILE, -1, "Image", le_gd); + ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd); + ZEND_FETCH_RESOURCE(tile, gdImagePtr, &TILE, -1, "Image", le_gd); gdImageSetTile(im, tile); @@ -2331,15 +2164,15 @@ PHP_FUNCTION(imagesettile) Set the brush image to $brush when filling $image with the "IMG_COLOR_BRUSHED" color */ PHP_FUNCTION(imagesetbrush) { - zval **IM, **TILE; + zval *IM, *TILE; gdImagePtr im, tile; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &IM, &TILE) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr", &IM, &TILE) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); - ZEND_FETCH_RESOURCE(tile, gdImagePtr, TILE, -1, "Image", le_gd); + ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd); + ZEND_FETCH_RESOURCE(tile, gdImagePtr, &TILE, -1, "Image", le_gd); gdImageSetBrush(im, tile); @@ -2352,24 +2185,19 @@ PHP_FUNCTION(imagesetbrush) Create a new image */ PHP_FUNCTION(imagecreate) { - zval **x_size, **y_size; + long x_size, y_size; gdImagePtr im; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &x_size, &y_size) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &x_size, &y_size) == FAILURE) { + return; } - convert_to_long_ex(x_size); - convert_to_long_ex(y_size); - - if (Z_LVAL_PP(x_size) <= 0 || Z_LVAL_PP(y_size) <= 0 || - Z_LVAL_PP(x_size) >= INT_MAX || Z_LVAL_PP(y_size) >= INT_MAX - ) { + if (x_size <= 0 || y_size <= 0 || x_size >= INT_MAX || y_size >= INT_MAX) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid image dimensions"); RETURN_FALSE; } - im = gdImageCreate(Z_LVAL_PP(x_size), Z_LVAL_PP(y_size)); + im = gdImageCreate(x_size, y_size); if (!im) { RETURN_FALSE; @@ -2400,8 +2228,8 @@ PHP_FUNCTION(imagetypes) ret |= 16; #endif - if (ZEND_NUM_ARGS() != 0) { - WRONG_PARAM_COUNT; + if (zend_parse_parameters_none() == FAILURE) { + return; } RETURN_LONG(ret); @@ -2503,8 +2331,8 @@ PHP_FUNCTION(imagecreatefromstring) int imtype; char sig[8]; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &data) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &data) == FAILURE) { + return; } convert_to_string_ex(data); @@ -2582,35 +2410,30 @@ PHP_FUNCTION(imagecreatefromstring) */ static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, gdImagePtr (*func_p)(), gdImagePtr (*ioctx_func_p)()) { - zval **file, **srcx, **srcy, **width, **height; + char *file; + int file_len; + long srcx, srcy, width, height; gdImagePtr im = NULL; - char *fn=NULL; php_stream *stream; FILE * fp = NULL; - int argc=ZEND_NUM_ARGS(); #ifdef HAVE_GD_JPG long ignore_warning; #endif - - if ((image_type == PHP_GDIMG_TYPE_GD2PART && argc != 5) || - (image_type != PHP_GDIMG_TYPE_GD2PART && argc != 1) || - zend_get_parameters_ex(argc, &file, &srcx, &srcy, &width, &height) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } - - convert_to_string_ex(file); - - if (argc == 5 && image_type == PHP_GDIMG_TYPE_GD2PART) { - multi_convert_to_long_ex(4, srcx, srcy, width, height); - if (Z_LVAL_PP(width) < 1 || Z_LVAL_PP(height) < 1) { - php_error_docref(NULL TSRMLS_CC, E_WARNING,"Zero width or height not allowed"); + if (image_type == PHP_GDIMG_TYPE_GD2PART) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sllll", &file, &file_len, &srcx, &srcy, &width, &height) == FAILURE) { + return; + } + if (width < 1 || height < 1) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Zero width or height not allowed"); RETURN_FALSE; } + } else { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_len) == FAILURE) { + return; + } } - fn = Z_STRVAL_PP(file); - - stream = php_stream_open_wrapper(fn, "rb", ENFORCE_SAFE_MODE|REPORT_ERRORS|IGNORE_PATH|IGNORE_URL_WIN, NULL); + stream = php_stream_open_wrapper(file, "rb", ENFORCE_SAFE_MODE|REPORT_ERRORS|IGNORE_PATH|IGNORE_URL_WIN, NULL); if (stream == NULL) { RETURN_FALSE; } @@ -2647,7 +2470,7 @@ static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type, } if (image_type == PHP_GDIMG_TYPE_GD2PART) { - im = (*ioctx_func_p)(io_ctx, Z_LVAL_PP(srcx), Z_LVAL_PP(srcy), Z_LVAL_PP(width), Z_LVAL_PP(height)); + im = (*ioctx_func_p)(io_ctx, srcx, srcy, width, height); } else { im = (*ioctx_func_p)(io_ctx); } @@ -2669,11 +2492,11 @@ static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type, if (!im && fp) { switch (image_type) { case PHP_GDIMG_TYPE_GD2PART: - im = (*func_p)(fp, Z_LVAL_PP(srcx), Z_LVAL_PP(srcy), Z_LVAL_PP(width), Z_LVAL_PP(height)); + im = (*func_p)(fp, srcx, srcy, width, height); break; #if defined(HAVE_GD_XPM) && defined(HAVE_GD_BUNDLED) case PHP_GDIMG_TYPE_XPM: - im = gdImageCreateFromXpm(fn); + im = gdImageCreateFromXpm(file); break; #endif @@ -2702,7 +2525,7 @@ static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type, return; } - php_error_docref(NULL TSRMLS_CC, E_WARNING, "'%s' is not a valid %s file", fn, tn); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "'%s' is not a valid %s file", file, tn); out_err: php_stream_close(stream); RETURN_FALSE; @@ -2800,37 +2623,36 @@ PHP_FUNCTION(imagecreatefromgd2part) */ static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, void (*func_p)()) { - zval **imgind, **file, **quality, **type; + zval *imgind; + char *file = NULL; + long quality = 0, type = 0; gdImagePtr im; char *fn = NULL; FILE *fp; - int argc = ZEND_NUM_ARGS(); + int file_len = 0, argc = ZEND_NUM_ARGS(); int q = -1, i, t = 1; /* The quality parameter for Wbmp stands for the threshold when called from image2wbmp() */ /* When called from imagewbmp() the quality parameter stands for the foreground color. Default: black. */ /* The quality parameter for gd2 stands for chunk size */ - if (argc < 1 || argc > 4 || zend_get_parameters_ex(argc, &imgind, &file, &quality, &type) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(argc TSRMLS_CC, "r|sll", &imgind, &file, &file_len, &quality, &type) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(im, gdImagePtr, imgind, -1, "Image", le_gd); + ZEND_FETCH_RESOURCE(im, gdImagePtr, &imgind, -1, "Image", le_gd); if (argc > 1) { - convert_to_string_ex(file); - fn = Z_STRVAL_PP(file); + fn = file; if (argc == 3) { - convert_to_long_ex(quality); - q = Z_LVAL_PP(quality); + q = quality; } if (argc == 4) { - convert_to_long_ex(type); - t = Z_LVAL_PP(type); + t = type; } } - if (argc >= 2 && Z_STRLEN_PP(file)) { + if (argc >= 2 && file_len) { PHP_GD_CHECK_OPEN_BASEDIR(fn, "Invalid filename"); fp = VCWD_FOPEN(fn, "wb"); @@ -2860,14 +2682,12 @@ static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type, char } (*func_p)(im, i, fp); break; -#if HAVE_LIBGD20 case PHP_GDIMG_TYPE_GD: if (im->trueColor){ gdImageTrueColorToPalette(im,1,256); } (*func_p)(im, fp); break; -#endif #ifdef HAVE_GD_GD2 case PHP_GDIMG_TYPE_GD2: if (q == -1) { @@ -2920,14 +2740,12 @@ static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type, char } (*func_p)(im, q, tmp); break; -#if HAVE_LIBGD20 case PHP_GDIMG_TYPE_GD: if (im->trueColor) { gdImageTrueColorToPalette(im,1,256); } (*func_p)(im, tmp); break; -#endif #ifdef HAVE_GD_GD2 case PHP_GDIMG_TYPE_GD2: if (q == -1) { @@ -3049,16 +2867,16 @@ PHP_FUNCTION(imagegd2) Destroy an image */ PHP_FUNCTION(imagedestroy) { - zval **IM; + zval *IM; gdImagePtr im; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &IM) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &IM) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); + ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd); - zend_list_delete(Z_LVAL_PP(IM)); + zend_list_delete(Z_LVAL_P(IM)); RETURN_TRUE; } @@ -3069,20 +2887,18 @@ PHP_FUNCTION(imagedestroy) Allocate a color for an image */ PHP_FUNCTION(imagecolorallocate) { - zval **IM, **red, **green, **blue; + zval *IM; + long red, green, blue; gdImagePtr im; int ct = (-1); - if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &IM, &red, &green, &blue) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlll", &IM, &red, &green, &blue) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); + ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd); - convert_to_long_ex(red); - convert_to_long_ex(green); - convert_to_long_ex(blue); - ct = gdImageColorAllocate(im, Z_LVAL_PP(red), Z_LVAL_PP(green), Z_LVAL_PP(blue)); + ct = gdImageColorAllocate(im, red, green, blue); if (ct < 0) { RETURN_FALSE; } @@ -3095,15 +2911,15 @@ PHP_FUNCTION(imagecolorallocate) Copy the palette from the src image onto the dst image */ PHP_FUNCTION(imagepalettecopy) { - zval **dstim, **srcim; + zval *dstim, *srcim; gdImagePtr dst, src; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &dstim, &srcim) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr", &dstim, &srcim) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(dst, gdImagePtr, dstim, -1, "Image", le_gd); - ZEND_FETCH_RESOURCE(src, gdImagePtr, srcim, -1, "Image", le_gd); + ZEND_FETCH_RESOURCE(dst, gdImagePtr, &dstim, -1, "Image", le_gd); + ZEND_FETCH_RESOURCE(src, gdImagePtr, &srcim, -1, "Image", le_gd); gdImagePaletteCopy(dst, src); } @@ -3114,41 +2930,31 @@ PHP_FUNCTION(imagepalettecopy) Get the index of the color of a pixel */ PHP_FUNCTION(imagecolorat) { - zval **IM, **x, **y; + zval *IM; + long x, y; gdImagePtr im; - if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &IM, &x, &y) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &IM, &x, &y) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); - - convert_to_long_ex(x); - convert_to_long_ex(y); + ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd); -#if HAVE_LIBGD20 if (gdImageTrueColor(im)) { - if (im->tpixels && gdImageBoundsSafe(im, Z_LVAL_PP(x), Z_LVAL_PP(y))) { - RETURN_LONG(gdImageTrueColorPixel(im, Z_LVAL_PP(x), Z_LVAL_PP(y))); + if (im->tpixels && gdImageBoundsSafe(im, x, y)) { + RETURN_LONG(gdImageTrueColorPixel(im, x, y)); } else { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "%ld,%ld is out of bounds", Z_LVAL_PP(x), Z_LVAL_PP(y)); + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "%ld,%ld is out of bounds", x, y); RETURN_FALSE; } } else { -#endif - if (im->pixels && gdImageBoundsSafe(im, Z_LVAL_PP(x), Z_LVAL_PP(y))) { -#if HAVE_LIBGD13 - RETURN_LONG(im->pixels[Z_LVAL_PP(y)][Z_LVAL_PP(x)]); -#else - RETURN_LONG(im->pixels[Z_LVAL_PP(x)][Z_LVAL_PP(y)]); -#endif + if (im->pixels && gdImageBoundsSafe(im, x, y)) { + RETURN_LONG(im->pixels[y][x]); } else { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "%ld,%ld is out of bounds", Z_LVAL_PP(x), Z_LVAL_PP(y)); + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "%ld,%ld is out of bounds", x, y); RETURN_FALSE; } -#if HAVE_LIBGD20 } -#endif } /* }}} */ @@ -3156,20 +2962,17 @@ PHP_FUNCTION(imagecolorat) Get the index of the closest color to the specified color */ PHP_FUNCTION(imagecolorclosest) { - zval **IM, **red, **green, **blue; + zval *IM; + long red, green, blue; gdImagePtr im; - if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &IM, &red, &green, &blue) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlll", &IM, &red, &green, &blue) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); - - convert_to_long_ex(red); - convert_to_long_ex(green); - convert_to_long_ex(blue); + ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd); - RETURN_LONG(gdImageColorClosest(im, Z_LVAL_PP(red), Z_LVAL_PP(green), Z_LVAL_PP(blue))); + RETURN_LONG(gdImageColorClosest(im, red, green, blue)); } /* }}} */ @@ -3178,20 +2981,17 @@ PHP_FUNCTION(imagecolorclosest) Get the index of the color which has the hue, white and blackness nearest to the given color */ PHP_FUNCTION(imagecolorclosesthwb) { - zval **IM, **red, **green, **blue; + zval *IM; + long red, green, blue; gdImagePtr im; - if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &IM, &red, &green, &blue) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlll", &IM, &red, &green, &blue) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); - - convert_to_long_ex(red); - convert_to_long_ex(green); - convert_to_long_ex(blue); + ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd); - RETURN_LONG(gdImageColorClosestHWB(im, Z_LVAL_PP(red), Z_LVAL_PP(green), Z_LVAL_PP(blue))); + RETURN_LONG(gdImageColorClosestHWB(im, red, green, blue)); } /* }}} */ #endif @@ -3200,25 +3000,23 @@ PHP_FUNCTION(imagecolorclosesthwb) De-allocate a color for an image */ PHP_FUNCTION(imagecolordeallocate) { - zval **IM, **index; + zval *IM; + long index; int col; gdImagePtr im; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &IM, &index) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &IM, &index) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); + ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd); -#if HAVE_LIBGD20 /* We can return right away for a truecolor image as deallocating colours is meaningless here */ if (gdImageTrueColor(im)) { RETURN_TRUE; } -#endif - convert_to_long_ex(index); - col = Z_LVAL_PP(index); + col = index; if (col >= 0 && col < gdImageColorsTotal(im)) { gdImageColorDeallocate(im, col); @@ -3234,20 +3032,17 @@ PHP_FUNCTION(imagecolordeallocate) Get the index of the specified color or its closest possible alternative */ PHP_FUNCTION(imagecolorresolve) { - zval **IM, **red, **green, **blue; + zval *IM; + long red, green, blue; gdImagePtr im; - if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &IM, &red, &green, &blue) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlll", &IM, &red, &green, &blue) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); - - convert_to_long_ex(red); - convert_to_long_ex(green); - convert_to_long_ex(blue); + ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd); - RETURN_LONG(gdImageColorResolve(im, Z_LVAL_PP(red), Z_LVAL_PP(green), Z_LVAL_PP(blue))); + RETURN_LONG(gdImageColorResolve(im, red, green, blue)); } /* }}} */ @@ -3255,20 +3050,17 @@ PHP_FUNCTION(imagecolorresolve) Get the index of the specified color */ PHP_FUNCTION(imagecolorexact) { - zval **IM, **red, **green, **blue; + zval *IM; + long red, green, blue; gdImagePtr im; - if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &IM, &red, &green, &blue) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlll", &IM, &red, &green, &blue) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); - - convert_to_long_ex(red); - convert_to_long_ex(green); - convert_to_long_ex(blue); + ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd); - RETURN_LONG(gdImageColorExact(im, Z_LVAL_PP(red), Z_LVAL_PP(green), Z_LVAL_PP(blue))); + RETURN_LONG(gdImageColorExact(im, red, green, blue)); } /* }}} */ @@ -3276,27 +3068,23 @@ PHP_FUNCTION(imagecolorexact) Set the color for the specified palette index */ PHP_FUNCTION(imagecolorset) { - zval **IM, **color, **red, **green, **blue; + zval *IM; + long color, red, green, blue; int col; gdImagePtr im; - if (ZEND_NUM_ARGS() != 5 || zend_get_parameters_ex(5, &IM, &color, &red, &green, &blue) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll", &IM, &color, &red, &green, &blue) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); - - convert_to_long_ex(color); - convert_to_long_ex(red); - convert_to_long_ex(green); - convert_to_long_ex(blue); + ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd); - col = Z_LVAL_PP(color); + col = color; if (col >= 0 && col < gdImageColorsTotal(im)) { - im->red[col] = Z_LVAL_PP(red); - im->green[col] = Z_LVAL_PP(green); - im->blue[col] = Z_LVAL_PP(blue); + im->red[col] = red; + im->green[col] = green; + im->blue[col] = blue; } else { RETURN_FALSE; } @@ -3307,19 +3095,19 @@ PHP_FUNCTION(imagecolorset) Get the colors for an index */ PHP_FUNCTION(imagecolorsforindex) { - zval **IM, **index; + zval *IM; + long index; int col; gdImagePtr im; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &IM, &index) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &IM, &index) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); + ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd); + + col = index; - convert_to_long_ex(index); - col = Z_LVAL_PP(index); -#if HAVE_LIBGD20 if ((col >= 0 && gdImageTrueColor(im)) || (!gdImageTrueColor(im) && col >= 0 && col < gdImageColorsTotal(im))) { array_init(return_value); @@ -3327,17 +3115,7 @@ PHP_FUNCTION(imagecolorsforindex) add_assoc_long(return_value,"green", gdImageGreen(im,col)); add_assoc_long(return_value,"blue", gdImageBlue(im,col)); add_assoc_long(return_value,"alpha", gdImageAlpha(im,col)); - } -#else - if (col >= 0 && col < gdImageColorsTotal(im)) { - array_init(return_value); - - add_assoc_long(return_value,"red", im->red[col]); - add_assoc_long(return_value,"green", im->green[col]); - add_assoc_long(return_value,"blue", im->blue[col]); - } -#endif - else { + } else { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Color index %d out of range", col); RETURN_FALSE; } @@ -3348,24 +3126,17 @@ PHP_FUNCTION(imagecolorsforindex) Apply a gamma correction to a GD image */ PHP_FUNCTION(imagegammacorrect) { - zval **IM, **inputgamma, **outputgamma; + zval *IM; gdImagePtr im; int i; double input, output; - if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &IM, &inputgamma, &outputgamma) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rdd", &IM, &input, &output) == FAILURE) { + return; } - convert_to_double_ex(inputgamma); - convert_to_double_ex(outputgamma); - - input = Z_DVAL_PP(inputgamma); - output = Z_DVAL_PP(outputgamma); - - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); + ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd); -#if HAVE_LIBGD20 if (gdImageTrueColor(im)) { int x, y, c; @@ -3383,7 +3154,7 @@ PHP_FUNCTION(imagegammacorrect) } RETURN_TRUE; } -#endif + for (i = 0; i < gdImageColorsTotal(im); i++) { im->red[i] = (int)((pow((pow((im->red[i] / 255.0), input)), 1.0 / output) * 255) + .5); im->green[i] = (int)((pow((pow((im->green[i] / 255.0), input)), 1.0 / output) * 255) + .5); @@ -3398,20 +3169,17 @@ PHP_FUNCTION(imagegammacorrect) Set a single pixel */ PHP_FUNCTION(imagesetpixel) { - zval **IM, **x, **y, **col; + zval *IM; + long x, y, col; gdImagePtr im; - if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &IM, &x, &y, &col) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlll", &IM, &x, &y, &col) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); - - convert_to_long_ex(x); - convert_to_long_ex(y); - convert_to_long_ex(col); + ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd); - gdImageSetPixel(im, Z_LVAL_PP(x), Z_LVAL_PP(y), Z_LVAL_PP(col)); + gdImageSetPixel(im, x, y, col); RETURN_TRUE; } @@ -3421,28 +3189,23 @@ PHP_FUNCTION(imagesetpixel) Draw a line */ PHP_FUNCTION(imageline) { - zval **IM, **x1, **y1, **x2, **y2, **col; + zval *IM; + long x1, y1, x2, y2, col; gdImagePtr im; - if (ZEND_NUM_ARGS() != 6 || zend_get_parameters_ex(6, &IM, &x1, &y1, &x2, &y2, &col) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllll", &IM, &x1, &y1, &x2, &y2, &col) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); - - convert_to_long_ex(x1); - convert_to_long_ex(y1); - convert_to_long_ex(x2); - convert_to_long_ex(y2); - convert_to_long_ex(col); + ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd); #ifdef HAVE_GD_BUNDLED if (im->antialias) { - gdImageAALine(im, Z_LVAL_PP(x1), Z_LVAL_PP(y1), Z_LVAL_PP(x2), Z_LVAL_PP(y2), Z_LVAL_PP(col)); + gdImageAALine(im, x1, y1, x2, y2, col); } else #endif { - gdImageLine(im, Z_LVAL_PP(x1), Z_LVAL_PP(y1), Z_LVAL_PP(x2), Z_LVAL_PP(y2), Z_LVAL_PP(col)); + gdImageLine(im, x1, y1, x2, y2, col); } RETURN_TRUE; } @@ -3452,22 +3215,17 @@ PHP_FUNCTION(imageline) Draw a dashed line */ PHP_FUNCTION(imagedashedline) { - zval **IM, **x1, **y1, **x2, **y2, **col; + zval *IM; + long x1, y1, x2, y2, col; gdImagePtr im; - if (ZEND_NUM_ARGS() != 6 || zend_get_parameters_ex(6, &IM, &x1, &y1, &x2, &y2, &col) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllll", &IM, &x1, &y1, &x2, &y2, &col) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); - - convert_to_long_ex(x1); - convert_to_long_ex(y1); - convert_to_long_ex(x2); - convert_to_long_ex(y2); - convert_to_long_ex(col); + ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd); - gdImageDashedLine(im, Z_LVAL_PP(x1), Z_LVAL_PP(y1), Z_LVAL_PP(x2), Z_LVAL_PP(y2), Z_LVAL_PP(col)); + gdImageDashedLine(im, x1, y1, x2, y2, col); RETURN_TRUE; } /* }}} */ @@ -3476,22 +3234,17 @@ PHP_FUNCTION(imagedashedline) Draw a rectangle */ PHP_FUNCTION(imagerectangle) { - zval **IM, **x1, **y1, **x2, **y2, **col; + zval *IM; + long x1, y1, x2, y2, col; gdImagePtr im; - if (ZEND_NUM_ARGS() != 6 || zend_get_parameters_ex(6, &IM, &x1, &y1, &x2, &y2, &col) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllll", &IM, &x1, &y1, &x2, &y2, &col) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); - - convert_to_long_ex(x1); - convert_to_long_ex(y1); - convert_to_long_ex(x2); - convert_to_long_ex(y2); - convert_to_long_ex(col); + ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd); - gdImageRectangle(im, Z_LVAL_PP(x1), Z_LVAL_PP(y1), Z_LVAL_PP(x2), Z_LVAL_PP(y2), Z_LVAL_PP(col)); + gdImageRectangle(im, x1, y1, x2, y2, col); RETURN_TRUE; } /* }}} */ @@ -3500,22 +3253,17 @@ PHP_FUNCTION(imagerectangle) Draw a filled rectangle */ PHP_FUNCTION(imagefilledrectangle) { - zval **IM, **x1, **y1, **x2, **y2, **col; + zval *IM; + long x1, y1, x2, y2, col; gdImagePtr im; - if (ZEND_NUM_ARGS() != 6 || zend_get_parameters_ex(6, &IM, &x1, &y1, &x2, &y2, &col) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllll", &IM, &x1, &y1, &x2, &y2, &col) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); - - convert_to_long_ex(x1); - convert_to_long_ex(y1); - convert_to_long_ex(x2); - convert_to_long_ex(y2); - convert_to_long_ex(col); + ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd); - gdImageFilledRectangle(im, Z_LVAL_PP(x1), Z_LVAL_PP(y1), Z_LVAL_PP(x2), Z_LVAL_PP(y2), Z_LVAL_PP(col)); + gdImageFilledRectangle(im, x1, y1, x2, y2, col); RETURN_TRUE; } /* }}} */ @@ -3524,35 +3272,28 @@ PHP_FUNCTION(imagefilledrectangle) Draw a partial ellipse */ PHP_FUNCTION(imagearc) { - zval **IM, **cx, **cy, **w, **h, **ST, **E, **col; + zval *IM; + long cx, cy, w, h, ST, E, col; gdImagePtr im; int e, st; - if (ZEND_NUM_ARGS() != 8 || zend_get_parameters_ex(8, &IM, &cx, &cy, &w, &h, &ST, &E, &col) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllllll", &IM, &cx, &cy, &w, &h, &ST, &E, &col) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); - - convert_to_long_ex(cx); - convert_to_long_ex(cy); - convert_to_long_ex(w); - convert_to_long_ex(h); - convert_to_long_ex(ST); - convert_to_long_ex(E); - convert_to_long_ex(col); + ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd); - e = Z_LVAL_PP(E); + e = E; if (e < 0) { e %= 360; } - st = Z_LVAL_PP(ST); + st = ST; if (st < 0) { st %= 360; } - gdImageArc(im, Z_LVAL_PP(cx), Z_LVAL_PP(cy), Z_LVAL_PP(w), Z_LVAL_PP(h), st, e, Z_LVAL_PP(col)); + gdImageArc(im, cx, cy, w, h, st, e, col); RETURN_TRUE; } /* }}} */ @@ -3561,25 +3302,20 @@ PHP_FUNCTION(imagearc) Draw an ellipse */ PHP_FUNCTION(imageellipse) { - zval **IM, **cx, **cy, **w, **h, **color; + zval *IM; + long cx, cy, w, h, color; gdImagePtr im; - if (ZEND_NUM_ARGS() != 6 || zend_get_parameters_ex(6, &IM, &cx, &cy, &w, &h, &color) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllll", &IM, &cx, &cy, &w, &h, &color) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); - - convert_to_long_ex(cx); - convert_to_long_ex(cy); - convert_to_long_ex(w); - convert_to_long_ex(h); - convert_to_long_ex(color); + ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd); #ifdef HAVE_GD_IMAGEELLIPSE /* this function is missing from GD 2.0.1 */ - gdImageEllipse(im, Z_LVAL_PP(cx), Z_LVAL_PP(cy), Z_LVAL_PP(w), Z_LVAL_PP(h), Z_LVAL_PP(color)); + gdImageEllipse(im, cx, cy, w, h, color); #else - gdImageArc(im, Z_LVAL_PP(cx), Z_LVAL_PP(cy), Z_LVAL_PP(w), Z_LVAL_PP(h), 0, 360, Z_LVAL_PP(color)); + gdImageArc(im, cx, cy, w, h, 0, 360, color); #endif RETURN_TRUE; @@ -3590,21 +3326,17 @@ PHP_FUNCTION(imageellipse) Flood fill to specific color */ PHP_FUNCTION(imagefilltoborder) { - zval **IM, **x, **y, **border, **col; + zval *IM; + long x, y, border, col; gdImagePtr im; - if (ZEND_NUM_ARGS() != 5 || zend_get_parameters_ex(5, &IM, &x, &y, &border, &col) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll", &IM, &x, &y, &border, &col) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); - - convert_to_long_ex(x); - convert_to_long_ex(y); - convert_to_long_ex(border); - convert_to_long_ex(col); + ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd); - gdImageFillToBorder(im, Z_LVAL_PP(x), Z_LVAL_PP(y), Z_LVAL_PP(border), Z_LVAL_PP(col)); + gdImageFillToBorder(im, x, y, border, col); RETURN_TRUE; } /* }}} */ @@ -3613,20 +3345,17 @@ PHP_FUNCTION(imagefilltoborder) Flood fill */ PHP_FUNCTION(imagefill) { - zval **IM, **x, **y, **col; + zval *IM; + long x, y, col; gdImagePtr im; - if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &IM, &x, &y, &col) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlll", &IM, &x, &y, &col) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); - - convert_to_long_ex(x); - convert_to_long_ex(y); - convert_to_long_ex(col); + ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd); - gdImageFill(im, Z_LVAL_PP(x), Z_LVAL_PP(y), Z_LVAL_PP(col)); + gdImageFill(im, x, y, col); RETURN_TRUE; } /* }}} */ @@ -3635,14 +3364,14 @@ PHP_FUNCTION(imagefill) Find out the number of colors in an image's palette */ PHP_FUNCTION(imagecolorstotal) { - zval **IM; + zval *IM; gdImagePtr im; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &IM) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &IM) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); + ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd); RETURN_LONG(gdImageColorsTotal(im)); } @@ -3652,29 +3381,19 @@ PHP_FUNCTION(imagecolorstotal) Define a color as transparent */ PHP_FUNCTION(imagecolortransparent) { - zval **IM, **COL; + zval *IM; + long COL = 0; gdImagePtr im; + int argc = ZEND_NUM_ARGS(); - switch (ZEND_NUM_ARGS()) { - case 1: - if (zend_get_parameters_ex(1, &IM) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } - break; - case 2: - if (zend_get_parameters_ex(2, &IM, &COL) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } - convert_to_long_ex(COL); - break; - default: - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(argc TSRMLS_CC, "r|l", &IM, &COL) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); + ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd); - if (ZEND_NUM_ARGS() > 1) { - gdImageColorTransparent(im, Z_LVAL_PP(COL)); + if (argc > 1) { + gdImageColorTransparent(im, COL); } RETURN_LONG(gdImageGetTransparent(im)); @@ -3685,29 +3404,19 @@ PHP_FUNCTION(imagecolortransparent) Enable or disable interlace */ PHP_FUNCTION(imageinterlace) { - zval **IM, **INT; + zval *IM; + int argc = ZEND_NUM_ARGS(); + long INT = 0; gdImagePtr im; - switch (ZEND_NUM_ARGS()) { - case 1: - if (zend_get_parameters_ex(1, &IM) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } - break; - case 2: - if (zend_get_parameters_ex(2, &IM, &INT) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } - convert_to_long_ex(INT); - break; - default: - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(argc TSRMLS_CC, "r|l", &IM, &INT) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); + ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd); - if (ZEND_NUM_ARGS() > 1) { - gdImageInterlace(im, Z_LVAL_PP(INT)); + if (argc > 1) { + gdImageInterlace(im, INT); } RETURN_LONG(gdImageGetInterlaced(im)); @@ -3720,30 +3429,23 @@ PHP_FUNCTION(imageinterlace) /* im, points, num_points, col */ static void php_imagepolygon(INTERNAL_FUNCTION_PARAMETERS, int filled) { - zval **IM, **POINTS, **NPOINTS, **COL; + zval *IM, *POINTS; + long NPOINTS, COL; zval **var = NULL; gdImagePtr im; gdPointPtr points; int npoints, col, nelem, i; - if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &IM, &POINTS, &NPOINTS, &COL) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rall", &IM, &POINTS, &NPOINTS, &COL) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); - - convert_to_long_ex(NPOINTS); - convert_to_long_ex(COL); - - npoints = Z_LVAL_PP(NPOINTS); - col = Z_LVAL_PP(COL); + ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd); - if (Z_TYPE_PP(POINTS) != IS_ARRAY) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "2nd argument to imagepolygon not an array"); - RETURN_FALSE; - } + npoints = NPOINTS; + col = COL; - nelem = zend_hash_num_elements(Z_ARRVAL_PP(POINTS)); + nelem = zend_hash_num_elements(Z_ARRVAL_P(POINTS)); if (nelem < 6) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "You must have at least 3 points in your array"); RETURN_FALSE; @@ -3757,12 +3459,12 @@ static void php_imagepolygon(INTERNAL_FUNCTION_PARAMETERS, int filled) points = (gdPointPtr) safe_emalloc(npoints, sizeof(gdPoint), 0); for (i = 0; i < npoints; i++) { - if (zend_hash_index_find(Z_ARRVAL_PP(POINTS), (i * 2), (void **) &var) == SUCCESS) { + if (zend_hash_index_find(Z_ARRVAL_P(POINTS), (i * 2), (void **) &var) == SUCCESS) { SEPARATE_ZVAL((var)); convert_to_long(*var); points[i].x = Z_LVAL_PP(var); } - if (zend_hash_index_find(Z_ARRVAL_PP(POINTS), (i * 2) + 1, (void **) &var) == SUCCESS) { + if (zend_hash_index_find(Z_ARRVAL_P(POINTS), (i * 2) + 1, (void **) &var) == SUCCESS) { SEPARATE_ZVAL(var); convert_to_long(*var); points[i].y = Z_LVAL_PP(var); @@ -3841,16 +3543,14 @@ static gdFontPtr php_find_gd_font(int size TSRMLS_DC) */ static void php_imagefontsize(INTERNAL_FUNCTION_PARAMETERS, int arg) { - zval **SIZE; + long SIZE; gdFontPtr font; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &SIZE) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &SIZE) == FAILURE) { + return; } - convert_to_long_ex(SIZE); - - font = php_find_gd_font(Z_LVAL_PP(SIZE) TSRMLS_CC); + font = php_find_gd_font(SIZE TSRMLS_CC); RETURN_LONG(arg ? font->h : font->w); } /* }}} */ @@ -3905,36 +3605,33 @@ static void php_gdimagecharup(gdImagePtr im, gdFontPtr f, int x, int y, int c, i */ static void php_imagechar(INTERNAL_FUNCTION_PARAMETERS, int mode) { - zval **IM, **SIZE, **X, **Y, **C, **COL; + zval *IM; + long SIZE, X, Y, COL; + char *C; + int C_len; gdImagePtr im; int ch = 0, col, x, y, size, i, l = 0; unsigned char *str = NULL; gdFontPtr font; - if (ZEND_NUM_ARGS() != 6 || zend_get_parameters_ex(6, &IM, &SIZE, &X, &Y, &C, &COL) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllsl", &IM, &SIZE, &X, &Y, &C, &C_len, &COL) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); - - convert_to_long_ex(SIZE); - convert_to_long_ex(X); - convert_to_long_ex(Y); - convert_to_string_ex(C); - convert_to_long_ex(COL); + ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd); - col = Z_LVAL_PP(COL); + col = COL; if (mode < 2) { - ch = (int)((unsigned char)*(Z_STRVAL_PP(C))); + ch = (int)((unsigned char)*C); } else { - str = (unsigned char *) estrndup(Z_STRVAL_PP(C), Z_STRLEN_PP(C)); + str = (unsigned char *) estrndup(C, C_len); l = strlen((char *)str); } - y = Z_LVAL_PP(Y); - x = Z_LVAL_PP(X); - size = Z_LVAL_PP(SIZE); + y = Y; + x = X; + size = SIZE; font = php_find_gd_font(size TSRMLS_CC); @@ -4003,30 +3700,24 @@ PHP_FUNCTION(imagestringup) Copy part of an image */ PHP_FUNCTION(imagecopy) { - zval **SIM, **DIM, **SX, **SY, **SW, **SH, **DX, **DY; + zval *SIM, *DIM; + long SX, SY, SW, SH, DX, DY; gdImagePtr im_dst, im_src; int srcH, srcW, srcY, srcX, dstY, dstX; - if (ZEND_NUM_ARGS() != 8 || zend_get_parameters_ex(8, &DIM, &SIM, &DX, &DY, &SX, &SY, &SW, &SH) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrllllll", &DIM, &SIM, &DX, &DY, &SX, &SY, &SW, &SH) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(im_src, gdImagePtr, SIM, -1, "Image", le_gd); - ZEND_FETCH_RESOURCE(im_dst, gdImagePtr, DIM, -1, "Image", le_gd); - - convert_to_long_ex(SX); - convert_to_long_ex(SY); - convert_to_long_ex(SW); - convert_to_long_ex(SH); - convert_to_long_ex(DX); - convert_to_long_ex(DY); + ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd); + ZEND_FETCH_RESOURCE(im_dst, gdImagePtr, &DIM, -1, "Image", le_gd); - srcX = Z_LVAL_PP(SX); - srcY = Z_LVAL_PP(SY); - srcH = Z_LVAL_PP(SH); - srcW = Z_LVAL_PP(SW); - dstX = Z_LVAL_PP(DX); - dstY = Z_LVAL_PP(DY); + srcX = SX; + srcY = SY; + srcH = SH; + srcW = SW; + dstX = DX; + dstY = DY; gdImageCopy(im_dst, im_src, dstX, dstY, srcX, srcY, srcW, srcH); RETURN_TRUE; @@ -4038,32 +3729,25 @@ PHP_FUNCTION(imagecopy) Merge one part of an image with another */ PHP_FUNCTION(imagecopymerge) { - zval **SIM, **DIM, **SX, **SY, **SW, **SH, **DX, **DY, **PCT; + zval *SIM, *DIM; + long SX, SY, SW, SH, DX, DY, PCT; gdImagePtr im_dst, im_src; int srcH, srcW, srcY, srcX, dstY, dstX, pct; - if (ZEND_NUM_ARGS() != 9 || zend_get_parameters_ex(9, &DIM, &SIM, &DX, &DY, &SX, &SY, &SW, &SH, &PCT) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrlllllll", &DIM, &SIM, &DX, &DY, &SX, &SY, &SW, &SH, &PCT) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(im_src, gdImagePtr, SIM, -1, "Image", le_gd); - ZEND_FETCH_RESOURCE(im_dst, gdImagePtr, DIM, -1, "Image", le_gd); - - convert_to_long_ex(SX); - convert_to_long_ex(SY); - convert_to_long_ex(SW); - convert_to_long_ex(SH); - convert_to_long_ex(DX); - convert_to_long_ex(DY); - convert_to_long_ex(PCT); + ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd); + ZEND_FETCH_RESOURCE(im_dst, gdImagePtr, &DIM, -1, "Image", le_gd); - srcX = Z_LVAL_PP(SX); - srcY = Z_LVAL_PP(SY); - srcH = Z_LVAL_PP(SH); - srcW = Z_LVAL_PP(SW); - dstX = Z_LVAL_PP(DX); - dstY = Z_LVAL_PP(DY); - pct = Z_LVAL_PP(PCT); + srcX = SX; + srcY = SY; + srcH = SH; + srcW = SW; + dstX = DX; + dstY = DY; + pct = PCT; gdImageCopyMerge(im_dst, im_src, dstX, dstY, srcX, srcY, srcW, srcH, pct); RETURN_TRUE; @@ -4074,32 +3758,25 @@ PHP_FUNCTION(imagecopymerge) Merge one part of an image with another */ PHP_FUNCTION(imagecopymergegray) { - zval **SIM, **DIM, **SX, **SY, **SW, **SH, **DX, **DY, **PCT; + zval *SIM, *DIM; + long SX, SY, SW, SH, DX, DY, PCT; gdImagePtr im_dst, im_src; int srcH, srcW, srcY, srcX, dstY, dstX, pct; - if (ZEND_NUM_ARGS() != 9 || zend_get_parameters_ex(9, &DIM, &SIM, &DX, &DY, &SX, &SY, &SW, &SH, &PCT) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrlllllll", &DIM, &SIM, &DX, &DY, &SX, &SY, &SW, &SH, &PCT) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(im_src, gdImagePtr, SIM, -1, "Image", le_gd); - ZEND_FETCH_RESOURCE(im_dst, gdImagePtr, DIM, -1, "Image", le_gd); - - convert_to_long_ex(SX); - convert_to_long_ex(SY); - convert_to_long_ex(SW); - convert_to_long_ex(SH); - convert_to_long_ex(DX); - convert_to_long_ex(DY); - convert_to_long_ex(PCT); + ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd); + ZEND_FETCH_RESOURCE(im_dst, gdImagePtr, &DIM, -1, "Image", le_gd); - srcX = Z_LVAL_PP(SX); - srcY = Z_LVAL_PP(SY); - srcH = Z_LVAL_PP(SH); - srcW = Z_LVAL_PP(SW); - dstX = Z_LVAL_PP(DX); - dstY = Z_LVAL_PP(DY); - pct = Z_LVAL_PP(PCT); + srcX = SX; + srcY = SY; + srcH = SH; + srcW = SW; + dstX = DX; + dstY = DY; + pct = PCT; gdImageCopyMergeGray(im_dst, im_src, dstX, dstY, srcX, srcY, srcW, srcH, pct); RETURN_TRUE; @@ -4111,34 +3788,26 @@ PHP_FUNCTION(imagecopymergegray) Copy and resize part of an image */ PHP_FUNCTION(imagecopyresized) { - zval **SIM, **DIM, **SX, **SY, **SW, **SH, **DX, **DY, **DW, **DH; + zval *SIM, *DIM; + long SX, SY, SW, SH, DX, DY, DW, DH; gdImagePtr im_dst, im_src; int srcH, srcW, dstH, dstW, srcY, srcX, dstY, dstX; - if (ZEND_NUM_ARGS() != 10 || zend_get_parameters_ex(10, &DIM, &SIM, &DX, &DY, &SX, &SY, &DW, &DH, &SW, &SH) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrllllllll", &DIM, &SIM, &DX, &DY, &SX, &SY, &DW, &DH, &SW, &SH) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(im_dst, gdImagePtr, DIM, -1, "Image", le_gd); - ZEND_FETCH_RESOURCE(im_src, gdImagePtr, SIM, -1, "Image", le_gd); - - convert_to_long_ex(SX); - convert_to_long_ex(SY); - convert_to_long_ex(SW); - convert_to_long_ex(SH); - convert_to_long_ex(DX); - convert_to_long_ex(DY); - convert_to_long_ex(DW); - convert_to_long_ex(DH); + ZEND_FETCH_RESOURCE(im_dst, gdImagePtr, &DIM, -1, "Image", le_gd); + ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd); - srcX = Z_LVAL_PP(SX); - srcY = Z_LVAL_PP(SY); - srcH = Z_LVAL_PP(SH); - srcW = Z_LVAL_PP(SW); - dstX = Z_LVAL_PP(DX); - dstY = Z_LVAL_PP(DY); - dstH = Z_LVAL_PP(DH); - dstW = Z_LVAL_PP(DW); + srcX = SX; + srcY = SY; + srcH = SH; + srcW = SW; + dstX = DX; + dstY = DY; + dstH = DH; + dstW = DW; if (dstW <= 0 || dstH <= 0 || srcW <= 0 || srcH <= 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid image dimensions"); @@ -4154,14 +3823,14 @@ PHP_FUNCTION(imagecopyresized) Get image width */ PHP_FUNCTION(imagesx) { - zval **IM; + zval *IM; gdImagePtr im; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &IM) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &IM) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); + ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd); RETURN_LONG(gdImageSX(im)); } @@ -4171,14 +3840,14 @@ PHP_FUNCTION(imagesx) Get image height */ PHP_FUNCTION(imagesy) { - zval **IM; + zval *IM; gdImagePtr im; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &IM) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &IM) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); + ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd); RETURN_LONG(gdImageSY(im)); } @@ -4191,7 +3860,7 @@ PHP_FUNCTION(imagesy) #ifdef ENABLE_GD_TTF -#if HAVE_LIBGD20 && HAVE_LIBFREETYPE && HAVE_GD_STRINGFTEX +#if HAVE_LIBFREETYPE && HAVE_GD_STRINGFTEX /* {{{ proto array imageftbbox(float size, float angle, string font_file, string text [, array extrainfo]) Give the bounding box of a text using fonts via freetype2 */ PHP_FUNCTION(imageftbbox) @@ -4322,8 +3991,6 @@ static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int mode, int error = gdImageStringTTF(im, brect, col, fontname, ptsize, angle, x, y, str); # endif -#else /* !USE_GD_IMGSTRTTF */ - error = gdttf(im, brect, col, fontname, ptsize, angle, x, y, str); #endif if (error) { @@ -4368,26 +4035,24 @@ static void php_free_ps_enc(zend_rsrc_list_entry *rsrc TSRMLS_DC) Load a new font from specified file */ PHP_FUNCTION(imagepsloadfont) { - zval **file; - int f_ind, *font; + char *file; + int file_len, f_ind, *font; #ifdef PHP_WIN32 struct stat st; #endif - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &file) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_len) == FAILURE) { + return; } - convert_to_string_ex(file); - #ifdef PHP_WIN32 - if (VCWD_STAT(Z_STRVAL_PP(file), &st) < 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Font file not found (%s)", Z_STRVAL_PP(file)); + if (VCWD_STAT(file, &st) < 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Font file not found (%s)", file); RETURN_FALSE; } #endif - f_ind = T1_AddFont(Z_STRVAL_PP(file)); + f_ind = T1_AddFont(file); if (f_ind < 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "T1Lib Error (%i): %s", f_ind, T1_StrError(f_ind)); @@ -4410,20 +4075,18 @@ PHP_FUNCTION(imagepsloadfont) /* The function in t1lib which this function uses seem to be buggy... PHP_FUNCTION(imagepscopyfont) { - zval **fnt; int l_ind, type; gd_ps_font *nf_ind, *of_ind; + long fnt; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &fnt) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &fnt) == FAILURE) { + return; } - convert_to_long_ex(fnt); - - of_ind = zend_list_find(Z_LVAL_PP(fnt), &type); + of_ind = zend_list_find(fnt, &type); if (type != le_ps_font) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%ld is not a Type 1 font index", Z_LVAL_PP(fnt)); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "%ld is not a Type 1 font index", fnt); RETURN_FALSE; } @@ -4464,16 +4127,16 @@ PHP_FUNCTION(imagepscopyfont) Free memory used by a font */ PHP_FUNCTION(imagepsfreefont) { - zval **fnt; + zval *fnt; int *f_ind; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &fnt) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &fnt) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(f_ind, int *, fnt, -1, "Type 1 font", le_ps_font); + ZEND_FETCH_RESOURCE(f_ind, int *, &fnt, -1, "Type 1 font", le_ps_font); - zend_list_delete(Z_LVAL_PP(fnt)); + zend_list_delete(Z_LVAL_P(fnt)); RETURN_TRUE; } /* }}} */ @@ -4482,20 +4145,18 @@ PHP_FUNCTION(imagepsfreefont) To change a fonts character encoding vector */ PHP_FUNCTION(imagepsencodefont) { - zval **fnt, **enc; - char **enc_vector; - int *f_ind; + zval *fnt; + char *enc, **enc_vector; + int enc_len, *f_ind; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &fnt, &enc) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &fnt, &enc, &enc_len) == FAILURE) { + return; } - convert_to_string_ex(enc); - - ZEND_FETCH_RESOURCE(f_ind, int *, fnt, -1, "Type 1 font", le_ps_font); + ZEND_FETCH_RESOURCE(f_ind, int *, &fnt, -1, "Type 1 font", le_ps_font); - if ((enc_vector = T1_LoadEncoding(Z_STRVAL_PP(enc))) == NULL) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't load encoding vector from %s", Z_STRVAL_PP(enc)); + if ((enc_vector = T1_LoadEncoding(enc)) == NULL) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't load encoding vector from %s", enc); RETURN_FALSE; } @@ -4516,25 +4177,24 @@ PHP_FUNCTION(imagepsencodefont) Extend or or condense (if extend < 1) a font */ PHP_FUNCTION(imagepsextendfont) { - zval **fnt, **ext; + zval *fnt; + double ext; int *f_ind; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &fnt, &ext) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rd", &fnt, &ext) == FAILURE) { + return; } - convert_to_double_ex(ext); - - ZEND_FETCH_RESOURCE(f_ind, int *, fnt, -1, "Type 1 font", le_ps_font); + ZEND_FETCH_RESOURCE(f_ind, int *, &fnt, -1, "Type 1 font", le_ps_font); T1_DeleteAllSizes(*f_ind); - if (Z_DVAL_PP(ext) <= 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Second parameter %F out of range (must be > 0)", Z_DVAL_PP(ext)); + if (ext <= 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Second parameter %F out of range (must be > 0)", ext); RETURN_FALSE; } - if (T1_ExtendFont(*f_ind, Z_DVAL_PP(ext)) != 0) { + if (T1_ExtendFont(*f_ind, ext) != 0) { RETURN_FALSE; } @@ -4546,18 +4206,17 @@ PHP_FUNCTION(imagepsextendfont) Slant a font */ PHP_FUNCTION(imagepsslantfont) { - zval **fnt, **slt; + zval *fnt; + double slt; int *f_ind; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &fnt, &slt) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rd", &fnt, &slt) == FAILURE) { + return; } - convert_to_double_ex(slt); - - ZEND_FETCH_RESOURCE(f_ind, int *, fnt, -1, "Type 1 font", le_ps_font); + ZEND_FETCH_RESOURCE(f_ind, int *, &fnt, -1, "Type 1 font", le_ps_font); - if (T1_SlantFont(*f_ind, Z_DVAL_PP(slt)) != 0) { + if (T1_SlantFont(*f_ind, slt) != 0) { RETURN_FALSE; } @@ -4565,7 +4224,7 @@ PHP_FUNCTION(imagepsslantfont) } /* }}} */ -/* {{{ 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]]]]) +/* {{{ 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]) Rasterize a string over an image */ PHP_FUNCTION(imagepstext) { @@ -4575,9 +4234,7 @@ PHP_FUNCTION(imagepstext) int *f_ind; int h_lines, v_lines, c_ind; int rd, gr, bl, fg_rd, fg_gr, fg_bl, bg_rd, bg_gr, bg_bl; -#if HAVE_LIBGD20 int fg_al, bg_al, al; -#endif int aa[16]; int amount_kern, add_width; double angle = 0.0, extend; @@ -4597,20 +4254,12 @@ PHP_FUNCTION(imagepstext) ZEND_FETCH_RESOURCE(f_ind, int *, &fnt, -1, "Type 1 font", le_ps_font); /* Ensure that the provided colors are valid */ -#if HAVE_LIBGD20 if (_fg < 0 || (!gdImageTrueColor(bg_img) && _fg > gdImageColorsTotal(bg_img))) { -#else - if (_fg < 0 || _fg > gdImageColorsTotal(bg_img)) { -#endif php_error_docref(NULL TSRMLS_CC, E_WARNING, "Foreground color index %ld out of range", _fg); RETURN_FALSE; } -#if HAVE_LIBGD20 if (_bg < 0 || (!gdImageTrueColor(bg_img) && _fg > gdImageColorsTotal(bg_img))) { -#else - if (_bg < 0 || _bg > gdImageColorsTotal(bg_img)) { -#endif php_error_docref(NULL TSRMLS_CC, E_WARNING, "Background color index %ld out of range", _bg); RETURN_FALSE; } @@ -4618,27 +4267,19 @@ PHP_FUNCTION(imagepstext) fg_rd = gdImageRed (bg_img, _fg); fg_gr = gdImageGreen(bg_img, _fg); fg_bl = gdImageBlue (bg_img, _fg); -#if HAVE_LIBGD20 fg_al = gdImageAlpha(bg_img, _fg); -#endif bg_rd = gdImageRed (bg_img, _bg); bg_gr = gdImageGreen(bg_img, _bg); bg_bl = gdImageBlue (bg_img, _bg); -#if HAVE_LIBGD20 bg_al = gdImageAlpha(bg_img, _bg); -#endif for (i = 0; i < aa_steps; i++) { rd = bg_rd + (double) (fg_rd - bg_rd) / aa_steps * (i + 1); gr = bg_gr + (double) (fg_gr - bg_gr) / aa_steps * (i + 1); bl = bg_bl + (double) (fg_bl - bg_bl) / aa_steps * (i + 1); -#if HAVE_LIBGD20 al = bg_al + (double) (fg_al - bg_al) / aa_steps * (i + 1); aa[i] = gdImageColorResolveAlpha(bg_img, rd, gr, bl, al); -#else - aa[i] = gdImageColorResolve(bg_img, rd, gr, bl); -#endif } T1_AASetBitsPerPixel(8); @@ -4717,48 +4358,40 @@ PHP_FUNCTION(imagepstext) } /* }}} */ -/* {{{ proto array imagepsbbox(string text, resource font, int size [, int space, int tightness, int angle]) +/* {{{ proto array imagepsbbox(string text, resource font, int size [, int space, int tightness, float angle]) Return the bounding box needed by a string if rasterized */ PHP_FUNCTION(imagepsbbox) { - zval **str, **fnt, **sz, **sp, **wd, **ang; - int i, space, add_width = 0, char_width, amount_kern; + zval *fnt; + long sz = 0, sp = 0, wd = 0; + char *str; + int i, space = 0, add_width = 0, char_width, amount_kern; int cur_x, cur_y, dx, dy; int x1, y1, x2, y2, x3, y3, x4, y4; int *f_ind; - int per_char = 0; - double angle, sin_a = 0, cos_a = 0; + int str_len, per_char = 0; + int argc = ZEND_NUM_ARGS(); + double angle = 0, sin_a = 0, cos_a = 0; BBox char_bbox, str_bbox = {0, 0, 0, 0}; - switch (ZEND_NUM_ARGS()) { - case 3: - if (zend_get_parameters_ex(3, &str, &fnt, &sz) == FAILURE) { - RETURN_FALSE; - } - space = 0; - break; - case 6: - if (zend_get_parameters_ex(6, &str, &fnt, &sz, &sp, &wd, &ang) == FAILURE) { - RETURN_FALSE; - } - convert_to_long_ex(sp); - convert_to_long_ex(wd); - convert_to_double_ex(ang); - space = Z_LVAL_PP(sp); - add_width = Z_LVAL_PP(wd); - angle = Z_DVAL_PP(ang) * M_PI / 180; - sin_a = sin(angle); - cos_a = cos(angle); - per_char = add_width || angle ? 1 : 0; - break; - default: - ZEND_WRONG_PARAM_COUNT(); + if (argc != 3 && argc != 6) { + ZEND_WRONG_PARAM_COUNT(); + } + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "srl|lld", &str, &str_len, &fnt, &sz, &sp, &wd, &angle) == FAILURE) { + return; + } + + if (argc == 6) { + space = sp; + add_width = wd; + angle = angle * M_PI / 180; + sin_a = sin(angle); + cos_a = cos(angle); + per_char = add_width || angle ? 1 : 0; } - ZEND_FETCH_RESOURCE(f_ind, int *, fnt, -1, "Type 1 font", le_ps_font); - - convert_to_string_ex(str); - convert_to_long_ex(sz); + ZEND_FETCH_RESOURCE(f_ind, int *, &fnt, -1, "Type 1 font", le_ps_font); #define max(a, b) (a > b ? a : b) #define min(a, b) (a < b ? a : b) @@ -4769,15 +4402,15 @@ PHP_FUNCTION(imagepsbbox) space += T1_GetCharWidth(*f_ind, ' '); cur_x = cur_y = 0; - for (i = 0; i < Z_STRLEN_PP(str); i++) { - if (Z_STRVAL_PP(str)[i] == ' ') { + for (i = 0; i < str_len; i++) { + if (str[i] == ' ') { char_bbox.llx = char_bbox.lly = char_bbox.ury = 0; char_bbox.urx = char_width = space; } else { - char_bbox = T1_GetCharBBox(*f_ind, Z_STRVAL_PP(str)[i]); - char_width = T1_GetCharWidth(*f_ind, Z_STRVAL_PP(str)[i]); + char_bbox = T1_GetCharBBox(*f_ind, str[i]); + char_width = T1_GetCharWidth(*f_ind, str[i]); } - amount_kern = i ? T1_GetKerning(*f_ind, Z_STRVAL_PP(str)[i - 1], Z_STRVAL_PP(str)[i]) : 0; + amount_kern = i ? T1_GetKerning(*f_ind, str[i - 1], str[i]) : 0; /* Transfer character bounding box to right place */ x1 = new_x(char_bbox.llx, char_bbox.lly) + cur_x; @@ -4806,7 +4439,7 @@ PHP_FUNCTION(imagepsbbox) } } else { - str_bbox = T1_GetStringBBox(*f_ind, Z_STRVAL_PP(str), Z_STRLEN_PP(str), space, T1_KERNING); + str_bbox = T1_GetStringBBox(*f_ind, str, str_len, space, T1_KERNING); } if (T1_errno) { @@ -4817,10 +4450,10 @@ PHP_FUNCTION(imagepsbbox) /* printf("%d %d %d %d\n", str_bbox.llx, str_bbox.lly, str_bbox.urx, str_bbox.ury); */ - add_next_index_long(return_value, (int) ceil(((double) str_bbox.llx)*Z_LVAL_PP(sz)/1000)); - add_next_index_long(return_value, (int) ceil(((double) str_bbox.lly)*Z_LVAL_PP(sz)/1000)); - add_next_index_long(return_value, (int) ceil(((double) str_bbox.urx)*Z_LVAL_PP(sz)/1000)); - add_next_index_long(return_value, (int) ceil(((double) str_bbox.ury)*Z_LVAL_PP(sz)/1000)); + add_next_index_long(return_value, (int) ceil(((double) str_bbox.llx)*sz/1000)); + add_next_index_long(return_value, (int) ceil(((double) str_bbox.lly)*sz/1000)); + add_next_index_long(return_value, (int) ceil(((double) str_bbox.urx)*sz/1000)); + add_next_index_long(return_value, (int) ceil(((double) str_bbox.ury)*sz/1000)); } /* }}} */ #endif @@ -4886,11 +4519,9 @@ static void _php_image_bw_convert(gdImagePtr im_org, gdIOCtx *out, int threshold return; } -#if HAVE_LIBGD20 if (im_org->trueColor) { gdImageTrueColorToPalette(im_org, 1, 256); } -#endif for (y = 0; y < dest_height; y++) { for (x = 0; x < dest_width; x++) { @@ -4917,12 +4548,13 @@ static void _php_image_bw_convert(gdImagePtr im_org, gdIOCtx *out, int threshold * _php_image_convert converts jpeg/png images to wbmp and resizes them as needed */ static void _php_image_convert(INTERNAL_FUNCTION_PARAMETERS, int image_type ) { - zval **f_org, **f_dest, **height, **width, **threshold; + char *f_org, *f_dest; + int f_org_len, f_dest_len; + long height, width, threshold; gdImagePtr im_org, im_dest, im_tmp; char *fn_org = NULL; char *fn_dest = NULL; FILE *org, *dest; - int argc = ZEND_NUM_ARGS(); int dest_height = -1; int dest_width = -1; int org_height, org_width; @@ -4935,21 +4567,15 @@ static void _php_image_convert(INTERNAL_FUNCTION_PARAMETERS, int image_type ) long ignore_warning; #endif - if (argc != 5 || zend_get_parameters_ex(argc, &f_org, &f_dest, &height, &width, &threshold) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sslll", &f_org, &f_org_len, &f_dest, &f_dest_len, &height, &width, &threshold) == FAILURE) { + return; } - convert_to_string_ex(f_org); - convert_to_string_ex(f_dest); - convert_to_long_ex(height); - convert_to_long_ex(width); - convert_to_long_ex(threshold); - - fn_org = Z_STRVAL_PP(f_org); - fn_dest = Z_STRVAL_PP(f_dest); - dest_height = Z_LVAL_PP(height); - dest_width = Z_LVAL_PP(width); - int_threshold = Z_LVAL_PP(threshold); + fn_org = f_org; + fn_dest = f_dest; + dest_height = height; + dest_width = width; + int_threshold = threshold; /* Check threshold value */ if (int_threshold < 0 || int_threshold > 8) { @@ -5112,12 +4738,12 @@ static void _php_image_convert(INTERNAL_FUNCTION_PARAMETERS, int image_type ) #ifdef HAVE_GD_BUNDLED #define PHP_GD_SINGLE_RES \ - zval **SIM; \ + zval *SIM; \ gdImagePtr im_src; \ - if (zend_get_parameters_ex(1, &SIM) == FAILURE) { \ + if (zend_parse_parameters(1 TSRMLS_CC, "r", &SIM) == FAILURE) { \ RETURN_FALSE; \ } \ - ZEND_FETCH_RESOURCE(im_src, gdImagePtr, SIM, -1, "Image", le_gd); \ + ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd); \ if (im_src == NULL) { \ RETURN_FALSE; \ } @@ -5293,6 +4919,30 @@ static void php_image_filter_smooth(INTERNAL_FUNCTION_PARAMETERS) RETURN_FALSE; } +static void php_image_filter_pixelate(INTERNAL_FUNCTION_PARAMETERS) +{ + zval *IM; + gdImagePtr im; + long tmp, blocksize; + zend_bool mode = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll|b", &IM, &tmp, &blocksize, &mode) == FAILURE) { + RETURN_FALSE; + } + + ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd); + + if (im == NULL) { + RETURN_FALSE; + } + + if (gdImagePixelate(im, (int) blocksize, (const unsigned int) mode)) { + RETURN_TRUE; + } + + RETURN_FALSE; +} + /* {{{ proto bool imagefilter(resource src_im, int filtertype, [args] ) Applies Filter an image using a custom angle */ PHP_FUNCTION(imagefilter) @@ -5313,10 +4963,11 @@ PHP_FUNCTION(imagefilter) php_image_filter_gaussian_blur, php_image_filter_selective_blur, php_image_filter_mean_removal, - php_image_filter_smooth + php_image_filter_smooth, + php_image_filter_pixelate }; - if (ZEND_NUM_ARGS() < 2 || ZEND_NUM_ARGS() > 6) { + if (ZEND_NUM_ARGS() < 2 || ZEND_NUM_ARGS() > IMAGE_FILTER_MAX_ARGS) { WRONG_PARAM_COUNT; } else if (zend_parse_parameters(2 TSRMLS_CC, "rl", &tmp, &filtertype) == FAILURE) { return; @@ -5386,17 +5037,17 @@ PHP_FUNCTION(imageconvolution) Should antialiased functions used or not*/ PHP_FUNCTION(imageantialias) { - zval **IM, **alias; + zval *IM; + zend_bool alias; gdImagePtr im; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &IM, &alias) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rb", &IM, &alias) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); + ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd); - convert_to_boolean_ex(alias); - gdImageAntialias(im, Z_LVAL_PP(alias)); + gdImageAntialias(im, alias); RETURN_TRUE; } diff --git a/ext/gd/gd_ctx.c b/ext/gd/gd_ctx.c index bf47911b8..464f07705 100644 --- a/ext/gd/gd_ctx.c +++ b/ext/gd/gd_ctx.c @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: gd_ctx.c,v 1.22.2.5.2.5 2008/12/31 11:17:37 sebastian Exp $ */ +/* $Id: gd_ctx.c,v 1.22.2.5.2.3.2.3 2008/12/31 11:15:37 sebastian Exp $ */ #include "php_gd.h" @@ -49,9 +49,11 @@ static void _php_image_output_ctxfree(struct gdIOCtx *ctx) /* {{{ _php_image_output_ctx */ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, void (*func_p)()) { - zval **imgind, **file, **quality, **basefilter; + zval *imgind; + char *file = NULL; + int file_len = 0; + long quality, basefilter; gdImagePtr im; - char *fn = NULL; FILE *fp = NULL; int argc = ZEND_NUM_ARGS(); int q = -1, i; @@ -63,39 +65,37 @@ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type, * from imagey<type>(). */ - if (argc < 2 && image_type == PHP_GDIMG_TYPE_XBM) { - WRONG_PARAM_COUNT; - } - - if (argc < 1 || argc > 4 || zend_get_parameters_ex(argc, &imgind, &file, &quality, &basefilter) == FAILURE) - { - WRONG_PARAM_COUNT; + if (image_type == PHP_GDIMG_TYPE_XBM) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs!|ll", &imgind, &file, &file_len, &quality, &basefilter) == FAILURE) { + return; + } + } else { + /* PHP_GDIMG_TYPE_GIF + * PHP_GDIMG_TYPE_PNG + * PHP_GDIMG_TYPE_JPG + * PHP_GDIMG_TYPE_WBM */ + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|s!ll", &imgind, &file, &file_len, &quality, &basefilter) == FAILURE) { + return; + } } - ZEND_FETCH_RESOURCE(im, gdImagePtr, imgind, -1, "Image", phpi_get_le_gd()); + ZEND_FETCH_RESOURCE(im, gdImagePtr, &imgind, -1, "Image", phpi_get_le_gd()); if (argc > 1) { - if (argc >= 2 && Z_TYPE_PP(file) != IS_NULL) { - convert_to_string_ex(file); - } - fn = Z_STRVAL_PP(file); if (argc >= 3) { - convert_to_long_ex(quality); - q = Z_LVAL_PP(quality);/* or colorindex for foreground of BW images (defaults to black) */ + q = quality; /* or colorindex for foreground of BW images (defaults to black) */ if (argc == 4) { - convert_to_long_ex(basefilter); - f = Z_LVAL_PP(basefilter); + f = basefilter; } } } - if (argc > 1 && (Z_TYPE_PP(file) != IS_NULL && ((argc == 2) || (argc > 2 && Z_STRLEN_PP(file))))) { - - PHP_GD_CHECK_OPEN_BASEDIR(fn, "Invalid filename"); + if (argc > 1 && file_len) { + PHP_GD_CHECK_OPEN_BASEDIR(file, "Invalid filename"); - fp = VCWD_FOPEN(fn, "wb"); + fp = VCWD_FOPEN(file, "wb"); if (!fp) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open '%s' for writing: %s", fn, strerror(errno)); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open '%s' for writing: %s", file, strerror(errno)); RETURN_FALSE; } @@ -137,7 +137,7 @@ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type, q = i; } if (image_type == PHP_GDIMG_TYPE_XBM) { - (*func_p)(im, fn, q, ctx); + (*func_p)(im, file, q, ctx); } else { (*func_p)(im, q, ctx); } diff --git a/ext/gd/gdcache.c b/ext/gd/gdcache.c index a703f9f73..598ec811d 100644 --- a/ext/gd/gdcache.c +++ b/ext/gd/gdcache.c @@ -1,5 +1,5 @@ /* - * $Id: gdcache.c,v 1.10 2005/01/09 21:05:05 sniper Exp $ + * $Id: gdcache.c,v 1.10.6.1 2008/07/18 01:16:25 scottmac Exp $ * * Caches of pointers to user structs in which the least-recently-used * element is replaced in the event of a cache miss after the cache has @@ -44,7 +44,7 @@ #else #include <php_config.h> #endif -#if (HAVE_LIBTTF | HAVE_LIBFREETYPE) && !defined(HAVE_GD_CACHE_CREATE) +#if HAVE_LIBFREETYPE && !defined(HAVE_GD_CACHE_CREATE) #include "gdcache.h" diff --git a/ext/gd/gdttf.c b/ext/gd/gdttf.c deleted file mode 100644 index 7a3daa644..000000000 --- a/ext/gd/gdttf.c +++ /dev/null @@ -1,845 +0,0 @@ -/* gd interface to freetype library */ -/* */ -/* John Ellson ellson@lucent.com */ - -/* $Id: gdttf.c,v 1.21 2005/01/09 21:05:05 sniper Exp $ */ - -#include "php.h" - -#if PHP_WIN32 -#include "config.w32.h" -#else -#include <php_config.h> -#endif -#if HAVE_LIBTTF && !defined(USE_GD_IMGSTRTTF) -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <math.h> -#include <gd.h> -#include "gdttf.h" -#include "gdcache.h" -#include <freetype.h> - -#ifndef HAVE_GDIMAGECOLORRESOLVE -extern int gdImageColorResolve(gdImagePtr, int, int, int); -#endif - -/* number of fonts cached before least recently used is replaced */ -#define FONTCACHESIZE 6 - -/* number of character glyphs cached per font before - least-recently-used is replaced */ -#define GLYPHCACHESIZE 120 - -/* number of bitmaps cached per glyph before - least-recently-used is replaced */ -#define BITMAPCACHESIZE 8 - -/* number of antialias color lookups cached */ -#define TWEENCOLORCACHESIZE 32 - -/* ptsize below which anti-aliasing is ineffective */ -#define MINANTIALIASPTSIZE 0 - -/* display resolution - (Not really. This has to be 72 or hinting is wrong) */ -#define RESOLUTION 72 - -/* Number of colors used for anti-aliasing */ -#undef NUMCOLORS -#define NUMCOLORS 4 - -/* Line separation as a factor of font height. - No space between if LINESPACE = 1.00 - Line separation will be rounded up to next pixel row*/ -#define LINESPACE 1.05 - -#ifndef TRUE -#define FALSE 0 -#define TRUE !FALSE -#endif - -#ifndef MAX -#define MAX(a, b) ((a)>(b)?(a):(b)) -#endif -#ifndef MIN -#define MIN(a, b) ((a)<(b)?(a):(b)) -#endif - -typedef struct { - char *fontname; /* key */ - double ptsize; /* key */ - double angle; /* key */ - double sin_a, cos_a; - TT_Engine *engine; - TT_Face face; - TT_Face_Properties properties; - TT_Instance instance; - TT_CharMap char_map_Unicode; - TT_CharMap char_map_Big5; - TT_CharMap char_map_Roman; - int have_char_map_Unicode; - int have_char_map_Big5; - int have_char_map_Roman; - TT_Matrix matrix; - TT_Instance_Metrics imetrics; - gdCache_head_t *glyphCache; -} font_t; - -typedef struct { - char *fontname; /* key */ - double ptsize; /* key */ - double angle; /* key */ - TT_Engine *engine; -} fontkey_t; - -typedef struct { - int character; /* key */ - int hinting; /* key */ - TT_Glyph glyph; - TT_Glyph_Metrics metrics; - TT_Outline outline; - TT_Pos oldx, oldy; - TT_Raster_Map Bit; - int gray_render; - int xmin, xmax, ymin, ymax; - gdCache_head_t *bitmapCache; -} glyph_t; - -typedef struct { - int character; /* key */ - int hinting; /* key */ - int gray_render; - font_t *font; -} glyphkey_t; - -typedef struct { - int xoffset; /* key */ - int yoffset; /* key */ - char *bitmap; -} bitmap_t; - -typedef struct { - int xoffset; /* key */ - int yoffset; /* key */ - glyph_t *glyph; -} bitmapkey_t; - -typedef struct { - unsigned char pixel; /* key */ - unsigned char bgcolor; /* key */ - int fgcolor; /* key */ /* -ve means no antialias */ - gdImagePtr im; /* key */ - unsigned char tweencolor; -} tweencolor_t; - -typedef struct { - unsigned char pixel; /* key */ - unsigned char bgcolor; /* key */ - int fgcolor; /* key */ /* -ve means no antialias */ - gdImagePtr im; /* key */ -} tweencolorkey_t; - -/* forward declarations so that glyphCache can be initialized by font code */ -static int glyphTest ( void *element, void *key ); -static void *glyphFetch ( char **error, void *key ); -static void glyphRelease( void *element ); - -/* forward declarations so that bitmapCache can be initialized by glyph code */ -static int bitmapTest ( void *element, void *key ); -static void *bitmapFetch ( char **error, void *key ); -static void bitmapRelease( void *element ); - -/* local prototype */ -char *gdttfchar(gdImage *im, int fg, font_t *font, int x, int y, TT_F26Dot6 x1, TT_F26Dot6 y1, TT_F26Dot6 *advance, TT_BBox **bbox, char **next); - - - -/******************************************************************** - * gdTcl_UtfToUniChar is borrowed from ... - */ -/* - * tclUtf.c -- - * - * Routines for manipulating UTF-8 strings. - * - * Copyright (c) 1997-1998 Sun Microsystems, Inc. - * - * See the file "license.terms" for information on usage and redistribution - * of this file, and for a DISCLAIMER OF ALL WARRANTIES. - * - * SCCS: @(#) tclUtf.c 1.25 98/01/28 18:02:43 - */ - -/* - *--------------------------------------------------------------------------- - * - * gdTcl_UtfToUniChar -- - * - * Extract the Tcl_UniChar represented by the UTF-8 string. Bad - * UTF-8 sequences are converted to valid Tcl_UniChars and processing - * continues. Equivalent to Plan 9 chartorune(). - * - * The caller must ensure that the source buffer is long enough that - * this routine does not run off the end and dereference non-existent - * memory looking for trail bytes. If the source buffer is known to - * be '\0' terminated, this cannot happen. Otherwise, the caller - * should call Tcl_UtfCharComplete() before calling this routine to - * ensure that enough bytes remain in the string. - * - * Results: - * *chPtr is filled with the Tcl_UniChar, and the return value is the - * number of bytes from the UTF-8 string that were consumed. - * - * Side effects: - * None. - * - *--------------------------------------------------------------------------- - */ - -#ifndef CHARSET_EBCDIC -#define ASC(ch) (ch) -#else /*CHARSET_EBCDIC*/ -#define ASC(ch) os_toascii[(unsigned char) (ch)] -#endif /*CHARSET_EBCDIC*/ - -#define Tcl_UniChar int -#define TCL_UTF_MAX 3 -static int gdTcl_UtfToUniChar(char *str, Tcl_UniChar *chPtr) -/* str is the UTF8 next character pointer */ -/* chPtr is the int for the result */ -{ - int byte; - - /* HTML4.0 entities in decimal form, e.g. Å */ - byte = *((unsigned char *) str); - if (byte == '&') { - int i, n = 0; - - byte = *((unsigned char *) (str+1)); - if (byte == '#') { - for (i = 2; i < 8; i++) { - byte = *((unsigned char *) (str+i)); - if (byte >= '0' && byte <= '9') { - n = (n * 10) + (byte - '0'); - } else { - break; - } - } - if (byte == ';') { - *chPtr = (Tcl_UniChar) n; - return ++i; - } - } - } - - /* Unroll 1 to 3 byte UTF-8 sequences, use loop to handle longer ones. */ - - byte = ASC(*((unsigned char *) str)); - if (byte < 0xC0) { - /* - * Handles properly formed UTF-8 characters between 0x01 and 0x7F. - * Also treats \0 and naked trail bytes 0x80 to 0xBF as valid - * characters representing themselves. - */ - - *chPtr = (Tcl_UniChar) byte; - return 1; - } else if (byte < 0xE0) { - if ((ASC(str[1]) & 0xC0) == 0x80) { - /* Two-byte-character lead-byte followed by a trail-byte. */ - - *chPtr = (Tcl_UniChar) (((byte & 0x1F) << 6) | (ASC(str[1]) & 0x3F)); - return 2; - } - /* - * A two-byte-character lead-byte not followed by trail-byte - * represents itself. - */ - - *chPtr = (Tcl_UniChar) byte; - return 1; - } else if (byte < 0xF0) { - if (((ASC(str[1]) & 0xC0) == 0x80) && ((ASC(str[2]) & 0xC0) == 0x80)) { - /* Three-byte-character lead byte followed by two trail bytes. */ - - *chPtr = (Tcl_UniChar) (((byte & 0x0F) << 12) | ((ASC(str[1]) & 0x3F) << 6) | (ASC(str[2]) & 0x3F)); - return 3; - } - /* A three-byte-character lead-byte not followed by two trail-bytes represents itself. */ - - *chPtr = (Tcl_UniChar) byte; - return 1; - } -#if TCL_UTF_MAX > 3 - else { - int ch, total, trail; - - total = totalBytes[byte]; - trail = total - 1; - if (trail > 0) { - ch = byte & (0x3F >> trail); - do { - str++; - if ((ASC(*str) & 0xC0) != 0x80) { - *chPtr = byte; - return 1; - } - ch <<= 6; - ch |= (ASC(*str) & 0x3F); - trail--; - } while (trail > 0); - *chPtr = ch; - return total; - } - } -#endif - - *chPtr = (Tcl_UniChar) byte; - return 1; -} - -/********************************************************************/ -/* font cache functions */ - -static int fontTest ( void *element, void *key ) -{ - font_t *a = (font_t *)element; - fontkey_t *b = (fontkey_t *)key; - - return (strcmp(a->fontname, b->fontname) == 0 && a->ptsize == b->ptsize && a->angle == b->angle); -} - -static void * fontFetch ( char **error, void *key ) -{ - TT_Error err; - font_t *a; - fontkey_t *b = (fontkey_t *)key; - int i, n, map_found; - short platform, encoding; - TSRMLS_FETCH(); - - a = (font_t *)pemalloc(sizeof(font_t), 1); -#ifdef VIRTUAL_DIR - /* a->fontname will be freed in fontRelease() later on */ - if (virtual_filepath(b->fontname, &a->fontname TSRMLS_CC)) { - *error = "Could not find/open font"; - pefree(a, 1); - return NULL; - } -#else - a->fontname = (char *)pemalloc(strlen(b->fontname) + 1, 1); - strcpy(a->fontname, b->fontname); -#endif - a->ptsize = b->ptsize; - a->angle = b->angle; - a->sin_a = sin(a->angle); - a->cos_a = cos(a->angle); - a->engine = b->engine; - if ((err = TT_Open_Face(*b->engine, a->fontname, &a->face))) { - if (err == TT_Err_Could_Not_Open_File) { - *error = "Could not find/open font"; - } else { - *error = "Could not read font"; - } - pefree(a, 1); - return NULL; - } - /* get face properties and allocate preload arrays */ - TT_Get_Face_Properties(a->face, &a->properties); - - /* create instance */ - if (TT_New_Instance(a->face, &a->instance)) { - *error = "Could not create face instance"; - pefree(a, 1); - return NULL; - } - - if (TT_Set_Instance_Resolutions(a->instance, RESOLUTION, RESOLUTION)) { - *error = "Could not set device resolutions"; - pefree(a, 1); - return NULL; - } - - if (TT_Set_Instance_CharSize(a->instance, (TT_F26Dot6)(a->ptsize*64))) { - *error = "Could not set character size"; - pefree(a, 1); - return NULL; - } - - TT_Get_Instance_Metrics(a->instance, &a->imetrics); - - /* First, look for a Unicode charmap */ - n = TT_Get_CharMap_Count(a->face); - - for (i = 0; i < n; i++) { - TT_Get_CharMap_ID(a->face, i, &platform, &encoding); - if ((platform == 3 && encoding == 1) /* Windows Unicode */ - || (platform == 2 && encoding == 1) - || (platform == 0)) { /* ?? Unicode */ - TT_Get_CharMap(a->face, i, &a->char_map_Unicode); - a->have_char_map_Unicode = 1; - map_found++; - } else if (platform == 3 && encoding == 4) { /* Windows Big5 */ - TT_Get_CharMap(a->face, i, &a->char_map_Big5); - a->have_char_map_Big5 = 1; - map_found++; - } else if (platform == 1 && encoding == 0) { /* Apple Roman */ - TT_Get_CharMap(a->face, i, &a->char_map_Roman); - a->have_char_map_Roman = 1; - map_found++; - } - } - - if (!map_found) { - *error = "Unable to find a CharMap that I can handle"; - pefree(a, 1); - return NULL; - } - - a->matrix.xx = (TT_Fixed) (a->cos_a * (1<<16)); - a->matrix.yx = (TT_Fixed) (a->sin_a * (1<<16)); - a->matrix.xy = - a->matrix.yx; - a->matrix.yy = a->matrix.xx; - - a->glyphCache = gdCacheCreate(GLYPHCACHESIZE, glyphTest, glyphFetch, glyphRelease); - - return (void *)a; -} - -static void fontRelease( void *element ) -{ - font_t *a = (font_t *)element; - - gdCacheDelete(a->glyphCache); - TT_Done_Instance(a->instance); - TT_Close_Face(a->face); - pefree(a->fontname, 1); - pefree((char *)element, 1); -} - -/********************************************************************/ -/* glyph cache functions */ - -static int glyphTest ( void *element, void *key ) -{ - glyph_t *a = (glyph_t *)element; - glyphkey_t *b = (glyphkey_t *)key; - - return (a->character == b->character && a->hinting == b->hinting && a->gray_render == b->gray_render); -} - -static void * glyphFetch ( char **error, void *key ) -{ - glyph_t *a; - glyphkey_t *b = (glyphkey_t *)key; - short glyph_code; - int flags, err; - int crect[8], xmin, xmax, ymin, ymax; - double cos_a, sin_a; - - a = (glyph_t *)pemalloc(sizeof(glyph_t), 1); - a->character = b->character; - a->hinting = b->hinting; - a->gray_render = b->gray_render; - a->oldx = a->oldy = 0; - - /* create glyph container */ - if ((TT_New_Glyph(b->font->face, &a->glyph))) { - *error = "Could not create glyph container"; - pefree(a, 1); - return NULL; - } - - flags = TTLOAD_SCALE_GLYPH; - if (a->hinting && b->font->angle == 0.0) { - flags |= TTLOAD_HINT_GLYPH; - } - if (b->font->have_char_map_Unicode) { - glyph_code = TT_Char_Index(b->font->char_map_Unicode, a->character); - } else if (a->character < 161 && b->font->have_char_map_Roman) { - glyph_code = TT_Char_Index(b->font->char_map_Roman, a->character); - } else if ( b->font->have_char_map_Big5) { - glyph_code = TT_Char_Index(b->font->char_map_Big5, a->character); - } - if ((err=TT_Load_Glyph(b->font->instance, a->glyph, glyph_code, flags))) { - *error = "TT_Load_Glyph problem"; - pefree(a, 1); - return NULL; - } - - TT_Get_Glyph_Metrics(a->glyph, &a->metrics); - if (b->font->angle != 0.0) { - TT_Get_Glyph_Outline(a->glyph, &a->outline); - TT_Transform_Outline(&a->outline, &b->font->matrix); - } - - /* calculate bitmap size */ - xmin = a->metrics.bbox.xMin -64; - ymin = a->metrics.bbox.yMin -64; - xmax = a->metrics.bbox.xMax +64; - ymax = a->metrics.bbox.yMax +64; - - cos_a = b->font->cos_a; - sin_a = b->font->sin_a; - crect[0] = (int)(xmin * cos_a - ymin * sin_a); - crect[1] = (int)(xmin * sin_a + ymin * cos_a); - crect[2] = (int)(xmax * cos_a - ymin * sin_a); - crect[3] = (int)(xmax * sin_a + ymin * cos_a); - crect[4] = (int)(xmax * cos_a - ymax * sin_a); - crect[5] = (int)(xmax * sin_a + ymax * cos_a); - crect[6] = (int)(xmin * cos_a - ymax * sin_a); - crect[7] = (int)(xmin * sin_a + ymax * cos_a); - a->xmin = MIN(MIN(crect[0], crect[2]), MIN(crect[4], crect[6])); - a->xmax = MAX(MAX(crect[0], crect[2]), MAX(crect[4], crect[6])); - a->ymin = MIN(MIN(crect[1], crect[3]), MIN(crect[5], crect[7])); - a->ymax = MAX(MAX(crect[1], crect[3]), MAX(crect[5], crect[7])); - - /* allocate bitmap large enough for character */ - a->Bit.rows = (a->ymax - a->ymin + 32 + 64) / 64; - a->Bit.width = (a->xmax - a->xmin + 32 + 64) / 64; - a->Bit.flow = TT_Flow_Up; - if (a->gray_render) { - a->Bit.cols = a->Bit.width; /* 1 byte per pixel */ - } else { - a->Bit.cols = (a->Bit.width + 7) / 8; /* 1 bit per pixel */ - } - a->Bit.cols = (a->Bit.cols + 3) & ~3; /* pad to 32 bits */ - a->Bit.size = a->Bit.rows * a->Bit.cols; /* # of bytes in buffer */ - a->Bit.bitmap = NULL; - - a->bitmapCache = gdCacheCreate(BITMAPCACHESIZE, bitmapTest, bitmapFetch, bitmapRelease); - - return (void *)a; -} - -static void glyphRelease( void *element ) -{ - glyph_t *a = (glyph_t *)element; - - gdCacheDelete(a->bitmapCache); - TT_Done_Glyph(a->glyph); - pefree((char *)element, 1); -} - -/********************************************************************/ -/* bitmap cache functions */ - -static int bitmapTest ( void *element, void *key ) -{ - bitmap_t *a = (bitmap_t *)element; - bitmapkey_t *b = (bitmapkey_t *)key; - - if (a->xoffset == b->xoffset && a->yoffset == b->yoffset) { - b->glyph->Bit.bitmap = a->bitmap; - return TRUE; - } - return FALSE; -} - -static void * bitmapFetch ( char **error, void *key ) -{ - bitmap_t *a; - bitmapkey_t *b = (bitmapkey_t *)key; - - a = (bitmap_t *)pemalloc(sizeof(bitmap_t), 1); - a->xoffset = b->xoffset; - a->yoffset = b->yoffset; - - b->glyph->Bit.bitmap = a->bitmap = (char *)pemalloc(b->glyph->Bit.size, 1); - memset(a->bitmap, 0, b->glyph->Bit.size); - /* render glyph */ - if (b->glyph->gray_render) { - TT_Get_Glyph_Pixmap(b->glyph->glyph, &b->glyph->Bit, a->xoffset, a->yoffset); - } else { - TT_Get_Glyph_Bitmap(b->glyph->glyph, &b->glyph->Bit, a->xoffset, a->yoffset); - } - return (void *)a; -} - -static void bitmapRelease( void *element ) -{ - bitmap_t *a = (bitmap_t *)element; - - pefree(a->bitmap, 1); - pefree((char *)element, 1); -} - -/********************************************************************/ -/* tweencolor cache functions */ - -static int tweenColorTest (void *element, void *key) -{ - tweencolor_t *a = (tweencolor_t *)element; - tweencolorkey_t *b = (tweencolorkey_t *)key; - - return (a->pixel == b->pixel && a->bgcolor == b->bgcolor && a->fgcolor == b->fgcolor && a->im == b->im); -} - -static void * tweenColorFetch (char **error, void *key) -{ - tweencolor_t *a; - tweencolorkey_t *b = (tweencolorkey_t *)key; - int pixel, npixel, bg, fg; - gdImagePtr im; - - a = (tweencolor_t *)pemalloc(sizeof(tweencolor_t), 1); - pixel = a->pixel = b->pixel; - bg = a->bgcolor = b->bgcolor; - fg = a->fgcolor = b->fgcolor; - im = b->im; - - /* if fg is specified by a negative color idx, then don't antialias */ - if (fg < 0) { - a->tweencolor = -fg; - } else { - npixel = NUMCOLORS - pixel; - a->tweencolor = gdImageColorResolve(im, - (pixel * im->red [fg] + npixel * im->red [bg]) / NUMCOLORS, - (pixel * im->green[fg] + npixel * im->green[bg]) / NUMCOLORS, - (pixel * im->blue [fg] + npixel * im->blue [bg]) / NUMCOLORS); - } - *error = NULL; - return (void *)a; -} - -static void tweenColorRelease(void *element) -{ - pefree((char *)element, 1); -} - -/********************************************************************/ -/* gdttfchar - render one character onto a gd image */ - -static int OneTime = 0; -static gdCache_head_t *tweenColorCache; - -char * -gdttfchar(gdImage *im, int fg, font_t *font, - int x, int y, /* string start pos in pixels */ - TT_F26Dot6 x1, TT_F26Dot6 y1, /* char start offset (*64) from x,y */ - TT_F26Dot6 *advance, - TT_BBox **bbox, - char **next) -{ - int pc, ch, len; - int row, col; - int x2, y2; /* char start pos in pixels */ - int x3, y3; /* current pixel pos */ - unsigned char *pixel; - - glyph_t *glyph; - glyphkey_t glyphkey; - bitmapkey_t bitmapkey; - tweencolor_t *tweencolor; - tweencolorkey_t tweencolorkey; - - /****** set up tweenColorCache on first call ************/ - if (!OneTime) { - tweenColorCache = gdCacheCreate(TWEENCOLORCACHESIZE, tweenColorTest, tweenColorFetch, tweenColorRelease); - OneTime++; - } - /**************/ - - if (font->have_char_map_Unicode) { /* use UTF-8 mapping from ASCII */ - len = gdTcl_UtfToUniChar(*next, &ch); - *next += len; - } else { - /* - * Big 5 mapping: - * use "JIS-8 half-width katakana" coding from 8-bit characters. Ref: - * ftp://ftp.ora.com/pub/examples/nutshell/ujip/doc/japan.inf-032092.sjs - */ - ch = (**next) & 255; /* don't extend sign */ - (*next)++; - if (ch >= 161 /* first code of JIS-8 pair */ - && **next) { /* don't advance past '\0' */ - ch = (ch * 256) + **next; - (*next)++; - } - } - - glyphkey.character = ch; - glyphkey.hinting = 1; - /* if fg is specified by a negative color idx, then don't antialias */ - glyphkey.gray_render = ((font->ptsize < MINANTIALIASPTSIZE) || (fg < 0)) ? FALSE : TRUE; - glyphkey.font = font; - glyph = (glyph_t *)gdCacheGet(font->glyphCache, &glyphkey); - if (!glyph) { - return font->glyphCache->error; - } - - *bbox = &glyph->metrics.bbox; - *advance = glyph->metrics.advance; - - /* if null *im, or invalid color, then assume user just wants brect */ - if (!im || fg > 255 || fg < -255) { - return (char *)NULL; - } - - /* render (via cache) a bitmap for the current fractional offset */ - bitmapkey.xoffset = ((x1+32) & 63) - 32 - ((glyph->xmin+32) & -64); - bitmapkey.yoffset = ((y1+32) & 63) - 32 - ((glyph->ymin+32) & -64); - bitmapkey.glyph = glyph; - gdCacheGet(glyph->bitmapCache, &bitmapkey); - - /* copy to gif, mapping colors */ - x2 = x + (((glyph->xmin+32) & -64) + ((x1+32) & -64)) / 64; - y2 = y - (((glyph->ymin+32) & -64) + ((y1+32) & -64)) / 64; - tweencolorkey.fgcolor = fg; - tweencolorkey.im = im; - for (row = 0; row < glyph->Bit.rows; row++) { - if (glyph->gray_render) { - pc = row * glyph->Bit.cols; - } else { - pc = row * glyph->Bit.cols * 8; - } - y3 = y2 - row; - if (y3 >= im->sy || y3 < 0) { - continue; - } - for (col = 0; col < glyph->Bit.width; col++, pc++) { - if (glyph->gray_render) { - tweencolorkey.pixel = *((unsigned char *)(glyph->Bit.bitmap) + pc); - } else { - tweencolorkey.pixel = (((*((unsigned char *)(glyph->Bit.bitmap) + pc/8)) << (pc%8))&128)?4:0; - } - /* if not background */ - if (tweencolorkey.pixel > 0) { - x3 = x2 + col; - if (x3 >= im->sx || x3 < 0) { - continue; - } -#if HAVE_LIBGD20 - if (im->trueColor) { - pixel = &im->tpixels[y3][x3]; - } else -#endif - { -#if HAVE_LIBGD13 - pixel = &im->pixels[y3][x3]; -#else - pixel = &im->pixels[x3][y3]; -#endif - } - tweencolorkey.bgcolor = *pixel; - tweencolor = (tweencolor_t *)gdCacheGet(tweenColorCache, &tweencolorkey); - *pixel = tweencolor->tweencolor; - } - } - } - return (char *)NULL; -} - -/********************************************************************/ -/* gdttf - render a utf8 string onto a gd image */ - -char * gdttf(gdImage *im, int *brect, int fg, char *fontname, double ptsize, double angle, int x, int y, char *str) -{ - TT_F26Dot6 ur_x = 0, ur_y = 0, ll_x = 0, ll_y = 0; - TT_F26Dot6 advance_x, advance_y, advance, x1, y1; - TT_BBox *bbox; - double sin_a, cos_a; - int i=0, ch; - font_t *font; - fontkey_t fontkey; - char *error, *next; - - /****** initialize font engine on first call ************/ - static gdCache_head_t *fontCache; - static TT_Engine engine; - - if (!fontCache) { - if (TT_Init_FreeType(&engine)) { - return "Failure to initialize font engine"; - } - fontCache = gdCacheCreate(FONTCACHESIZE, fontTest, fontFetch, fontRelease); - } - /**************/ - - /* get the font (via font cache) */ - fontkey.fontname = fontname; - fontkey.ptsize = ptsize; - fontkey.angle = angle; - fontkey.engine = &engine; - font = (font_t *)gdCacheGet(fontCache, &fontkey); - if (!font) { - return fontCache->error; - } - sin_a = font->sin_a; - cos_a = font->cos_a; - advance_x = advance_y = 0; - - next = str; - while (*next) { - ch = *next; - - /* carriage returns */ - if (ch == '\r') { - advance_x = 0; - next++; - continue; - } - /* newlines */ - if (ch == '\n') { - advance_y -= (TT_F26Dot6)(font->imetrics.y_ppem * LINESPACE * 64); - advance_y = (advance_y-32) & -64; /* round to next pixel row */ - next++; - continue; - } - - x1 = (TT_F26Dot6)(advance_x * cos_a - advance_y * sin_a); - y1 = (TT_F26Dot6)(advance_x * sin_a + advance_y * cos_a); - - if ((error = gdttfchar(im, fg, font, x, y, x1, y1, &advance, &bbox, &next))) { - return error; - } - - if (!i++) { /* if first character, init BB corner values */ - ll_x = bbox->xMin; - ll_y = bbox->yMin; - ur_x = bbox->xMax; - ur_y = bbox->yMax; - } else { - if (!advance_x) { - ll_x = MIN(bbox->xMin, ll_x); - } - ll_y = MIN(advance_y + bbox->yMin, ll_y); - ur_x = MAX(advance_x + bbox->xMax, ur_x); - if (!advance_y) { - ur_y = MAX(bbox->yMax, ur_y); - } - } - advance_x += advance; - } - - /* rotate bounding rectangle */ - brect[0] = (int)(ll_x * cos_a - ll_y * sin_a); - brect[1] = (int)(ll_x * sin_a + ll_y * cos_a); - brect[2] = (int)(ur_x * cos_a - ll_y * sin_a); - brect[3] = (int)(ur_x * sin_a + ll_y * cos_a); - brect[4] = (int)(ur_x * cos_a - ur_y * sin_a); - brect[5] = (int)(ur_x * sin_a + ur_y * cos_a); - brect[6] = (int)(ll_x * cos_a - ur_y * sin_a); - brect[7] = (int)(ll_x * sin_a + ur_y * cos_a); - - /* scale, round and offset brect */ - i = 0; - while (i < 8) { - brect[i] = x + (brect[i] + 32) / 64; - i++; - brect[i] = y - (brect[i] + 32) / 64; - i++; - } - - return (char *)NULL; -} - -#endif /* HAVE_LIBTTF */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/ext/gd/gdttf.h b/ext/gd/gdttf.h deleted file mode 100644 index 4977b3eca..000000000 --- a/ext/gd/gdttf.h +++ /dev/null @@ -1,16 +0,0 @@ -/* $Id: gdttf.h,v 1.3 2000/02/26 03:20:50 zeev Exp $ */ - -#ifdef _OSD_POSIX -#ifndef APACHE -#error On this EBCDIC platform, PHP is only supported as an Apache module. -#else /*APACHE*/ -#ifndef CHARSET_EBCDIC -#define CHARSET_EBCDIC /* this machine uses EBCDIC, not ASCII! */ -#endif -#include "ebcdic.h" -#endif /*APACHE*/ -#endif /*_OSD_POSIX*/ - -char * gdttf(gdImage *im, int *brect, int fg, char *fontname, - double ptsize, double angle, int x, int y, char *str); - diff --git a/ext/gd/libgd/gd.c b/ext/gd/libgd/gd.c index a2677c11d..7760fecf2 100644 --- a/ext/gd/libgd/gd.c +++ b/ext/gd/libgd/gd.c @@ -613,8 +613,8 @@ void gdImagePaletteCopy (gdImagePtr to, gdImagePtr from) xlate[i] = -1; } - for (x = 0; x < to->sx; x++) { - for (y = 0; y < to->sy; y++) { + for (y = 0; y < to->sy; y++) { + for (x = 0; x < to->sx; x++) { p = gdImageGetPixel(to, x, y); if (xlate[p] == -1) { /* This ought to use HWB, but we don't have an alpha-aware version of that yet. */ @@ -860,23 +860,27 @@ static void gdImageBrushApply (gdImagePtr im, int x, int y) static void gdImageTileApply (gdImagePtr im, int x, int y) { + gdImagePtr tile = im->tile; int srcx, srcy; int p; - if (!im->tile) { + if (!tile) { return; } - srcx = x % gdImageSX(im->tile); - srcy = y % gdImageSY(im->tile); + srcx = x % gdImageSX(tile); + srcy = y % gdImageSY(tile); if (im->trueColor) { - p = gdImageGetTrueColorPixel(im->tile, srcx, srcy); - if (p != gdImageGetTransparent (im->tile)) { + p = gdImageGetPixel(tile, srcx, srcy); + if (p != gdImageGetTransparent (tile)) { + if (!tile->trueColor) { + p = gdTrueColorAlpha(tile->red[p], tile->green[p], tile->blue[p], tile->alpha[p]); + } gdImageSetPixel(im, x, y, p); } } else { - p = gdImageGetPixel(im->tile, srcx, srcy); + p = gdImageGetPixel(tile, srcx, srcy); /* Allow for transparency */ - if (p != gdImageGetTransparent(im->tile)) { - if (im->tile->trueColor) { + if (p != gdImageGetTransparent(tile)) { + if (tile->trueColor) { /* Truecolor tile. Very slow on a palette destination. */ gdImageSetPixel(im, x, y, gdImageColorResolveAlpha(im, gdTrueColorGetRed(p), @@ -1804,7 +1808,9 @@ void gdImageFilledEllipse (gdImagePtr im, int mx, int my, int w, int h, int c) a=w>>1; b=h>>1; - gdImageLine(im, mx-a, my, mx+a, my, c); + for (x = mx-a; x <= mx+a; x++) { + gdImageSetPixel(im, x, my, c); + } mx1 = mx-a;my1 = my; mx2 = mx+a;my2 = my; diff --git a/ext/gd/libgd/gd.h b/ext/gd/libgd/gd.h index 7ef2caa48..77c98903a 100644 --- a/ext/gd/libgd/gd.h +++ b/ext/gd/libgd/gd.h @@ -250,6 +250,8 @@ gdImagePtr gdImageCreateFromWBMPCtx(gdIOCtx *infile); gdImagePtr gdImageCreateFromJpeg(FILE *infile, int ignore_warning); gdImagePtr gdImageCreateFromJpegCtx(gdIOCtx *infile, int ignore_warning); +int gdJpegGetVersionInt(); +const char * gdPngGetVersionString(); /* A custom data source. */ /* The source function must return -1 on error, otherwise the number of bytes fetched. 0 is EOF, not an error! */ @@ -578,6 +580,13 @@ void gdImageAlphaBlending(gdImagePtr im, int alphaBlendingArg); void gdImageAntialias(gdImagePtr im, int antialias); void gdImageSaveAlpha(gdImagePtr im, int saveAlphaArg); +enum gdPixelateMode { + GD_PIXELATE_UPPERLEFT, + GD_PIXELATE_AVERAGE +}; + +int gdImagePixelate(gdImagePtr im, int block_size, const unsigned int mode); + /* Macros to access information about images. */ /* Returns nonzero if the image is a truecolor image, diff --git a/ext/gd/libgd/gd_jpeg.c b/ext/gd/libgd/gd_jpeg.c index 9573c1cf6..a71469137 100644 --- a/ext/gd/libgd/gd_jpeg.c +++ b/ext/gd/libgd/gd_jpeg.c @@ -102,6 +102,11 @@ static void fatal_jpeg_error (j_common_ptr cinfo) exit (99); } +int gdJpegGetVersionInt() +{ + return JPEG_LIB_VERSION; +} + /* * Write IM to OUTFILE as a JFIF-formatted JPEG image, using quality * QUALITY. If QUALITY is in the range 0-100, increasing values diff --git a/ext/gd/libgd/gd_pixelate.c b/ext/gd/libgd/gd_pixelate.c new file mode 100644 index 000000000..3808a6e55 --- /dev/null +++ b/ext/gd/libgd/gd_pixelate.c @@ -0,0 +1,57 @@ +#include "gd.h" + +int gdImagePixelate(gdImagePtr im, int block_size, const unsigned int mode) +{ + int x, y; + + if (block_size <= 0) { + return 0; + } else if (block_size == 1) { + return 1; + } + switch (mode) { + case GD_PIXELATE_UPPERLEFT: + for (y = 0; y < im->sy; y += block_size) { + for (x = 0; x < im->sx; x += block_size) { + if (gdImageBoundsSafe(im, x, y)) { + int c = gdImageGetPixel(im, x, y); + gdImageFilledRectangle(im, x, y, x + block_size - 1, y + block_size - 1, c); + } + } + } + break; + case GD_PIXELATE_AVERAGE: + for (y = 0; y < im->sy; y += block_size) { + for (x = 0; x < im->sx; x += block_size) { + int a, r, g, b, c; + int total; + int cx, cy; + + a = r = g = b = c = total = 0; + /* sampling */ + for (cy = 0; cy < block_size; cy++) { + for (cx = 0; cx < block_size; cx++) { + if (!gdImageBoundsSafe(im, x + cx, y + cy)) { + continue; + } + c = gdImageGetPixel(im, x + cx, y + cy); + a += gdImageAlpha(im, c); + r += gdImageRed(im, c); + g += gdImageGreen(im, c); + b += gdImageBlue(im, c); + total++; + } + } + /* drawing */ + if (total > 0) { + c = gdImageColorResolveAlpha(im, r / total, g / total, b / total, a / total); + gdImageFilledRectangle(im, x, y, x + block_size - 1, y + block_size - 1, c); + } + } + } + break; + default: + return 0; + } + return 1; +} diff --git a/ext/gd/libgd/gd_png.c b/ext/gd/libgd/gd_png.c index 7591dc0c6..6b9c81ec9 100644 --- a/ext/gd/libgd/gd_png.c +++ b/ext/gd/libgd/gd_png.c @@ -36,6 +36,11 @@ ---------------------------------------------------------------------------*/ +const char * gdPngGetVersionString() +{ + return PNG_LIBPNG_VER_STRING; +} + #ifndef PNG_SETJMP_NOT_SUPPORTED typedef struct _jmpbuf_wrapper { @@ -184,7 +189,8 @@ gdImagePtr gdImageCreateFromPngCtx (gdIOCtx * infile) png_read_info(png_ptr, info_ptr); /* read all PNG info up to image data */ png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, NULL, NULL); - if ((color_type == PNG_COLOR_TYPE_RGB) || (color_type == PNG_COLOR_TYPE_RGB_ALPHA)) { + if ((color_type == PNG_COLOR_TYPE_RGB) || (color_type == PNG_COLOR_TYPE_RGB_ALPHA) + || color_type == PNG_COLOR_TYPE_GRAY_ALPHA) { im = gdImageCreateTrueColor((int) width, (int) height); } else { im = gdImageCreate((int) width, (int) height); @@ -220,7 +226,6 @@ gdImagePtr gdImageCreateFromPngCtx (gdIOCtx * infile) } #endif - switch (color_type) { case PNG_COLOR_TYPE_PALETTE: png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette); @@ -246,7 +251,6 @@ gdImagePtr gdImageCreateFromPngCtx (gdIOCtx * infile) } break; case PNG_COLOR_TYPE_GRAY: - case PNG_COLOR_TYPE_GRAY_ALPHA: /* create a fake palette and check for single-shade transparency */ if ((palette = (png_colorp) gdMalloc (256 * sizeof (png_color))) == NULL) { php_gd_error("gd-png error: cannot allocate gray palette"); @@ -288,6 +292,9 @@ gdImagePtr gdImageCreateFromPngCtx (gdIOCtx * infile) } break; + case PNG_COLOR_TYPE_GRAY_ALPHA: + png_set_gray_to_rgb(png_ptr); + case PNG_COLOR_TYPE_RGB: case PNG_COLOR_TYPE_RGB_ALPHA: /* gd 2.0: we now support truecolor. See the comment above @@ -360,6 +367,7 @@ gdImagePtr gdImageCreateFromPngCtx (gdIOCtx * infile) } break; + case PNG_COLOR_TYPE_GRAY_ALPHA: case PNG_COLOR_TYPE_RGB_ALPHA: for (h = 0; h < height; h++) { int boffset = 0; @@ -535,6 +543,10 @@ void gdImagePngCtxEx (gdImagePtr im, gdIOCtx * outfile, int level, int basefilte ++colors; } } + if (colors == 0) { + php_gd_error("gd-png error: no colors in palette"); + goto bail; + } if (colors < im->colorsTotal) { remap = TRUE; } @@ -732,6 +744,7 @@ void gdImagePngCtxEx (gdImagePtr im, gdIOCtx * outfile, int level, int basefilte } } /* 1.6.3: maybe we should give that memory BACK! TBB */ + bail: png_destroy_write_struct(&png_ptr, &info_ptr); } diff --git a/ext/gd/libgd/gdcache.c b/ext/gd/libgd/gdcache.c index a6e507a4b..73786f0bf 100644 --- a/ext/gd/libgd/gdcache.c +++ b/ext/gd/libgd/gdcache.c @@ -1,13 +1,9 @@ #include "gd.h" #include "gdhelpers.h" -#ifdef HAVE_LIBTTF -#define NEED_CACHE 1 -#else #ifdef HAVE_LIBFREETYPE #define NEED_CACHE 1 #endif -#endif #ifdef NEED_CACHE @@ -211,4 +207,4 @@ main (char *argv[], int argc) } #endif /* TEST */ -#endif /* HAVE_LIBTTF */ +#endif /* HAVE_NEECACHE */ diff --git a/ext/gd/libgd/gdft.c b/ext/gd/libgd/gdft.c index e543f2fe2..9c4b9b529 100644 --- a/ext/gd/libgd/gdft.c +++ b/ext/gd/libgd/gdft.c @@ -1108,15 +1108,23 @@ gdImageStringFTEx (gdImage * im, int *brect, int fg, char *fontlist, double ptsi double d1 = sin (angle + 0.78539816339744830962); double d2 = sin (angle - 0.78539816339744830962); + /* make the center of rotation at (0, 0) */ + FT_BBox normbox; + + normbox.xMin = 0; + normbox.yMin = 0; + normbox.xMax = bbox.xMax - bbox.xMin; + normbox.yMax = bbox.yMax - bbox.yMin; + /* rotate bounding rectangle */ - brect[0] = (int) (bbox.xMin * cos_a - bbox.yMin * sin_a); - brect[1] = (int) (bbox.xMin * sin_a + bbox.yMin * cos_a); - brect[2] = (int) (bbox.xMax * cos_a - bbox.yMin * sin_a); - brect[3] = (int) (bbox.xMax * sin_a + bbox.yMin * cos_a); - brect[4] = (int) (bbox.xMax * cos_a - bbox.yMax * sin_a); - brect[5] = (int) (bbox.xMax * sin_a + bbox.yMax * cos_a); - brect[6] = (int) (bbox.xMin * cos_a - bbox.yMax * sin_a); - brect[7] = (int) (bbox.xMin * sin_a + bbox.yMax * cos_a); + brect[0] = (int) (normbox.xMin * cos_a - normbox.yMin * sin_a); + brect[1] = (int) (normbox.xMin * sin_a + normbox.yMin * cos_a); + brect[2] = (int) (normbox.xMax * cos_a - normbox.yMin * sin_a); + brect[3] = (int) (normbox.xMax * sin_a + normbox.yMin * cos_a); + brect[4] = (int) (normbox.xMax * cos_a - normbox.yMax * sin_a); + brect[5] = (int) (normbox.xMax * sin_a + normbox.yMax * cos_a); + brect[6] = (int) (normbox.xMin * cos_a - normbox.yMax * sin_a); + brect[7] = (int) (normbox.xMin * sin_a + normbox.yMax * cos_a); /* scale, round and offset brect */ brect[0] = x + gdroundupdown(brect[0], d2 > 0); diff --git a/ext/gd/libgd/gdparttopng.c b/ext/gd/libgd/gdparttopng.c index 677a0b571..a82925b0e 100644 --- a/ext/gd/libgd/gdparttopng.c +++ b/ext/gd/libgd/gdparttopng.c @@ -37,7 +37,7 @@ main (int argc, char **argv) fclose (in); if (!im) { - fprintf (stderr, "Input is not in PNG format!\n"); + fprintf (stderr, "Input is not in GD2 format!\n"); exit (1); } out = fopen (argv[2], "wb"); diff --git a/ext/gd/libgd/gdtopng.c b/ext/gd/libgd/gdtopng.c index 9de34990a..9670b1019 100644 --- a/ext/gd/libgd/gdtopng.c +++ b/ext/gd/libgd/gdtopng.c @@ -26,7 +26,7 @@ main (int argc, char **argv) fclose (in); if (!im) { - fprintf (stderr, "Input is not in PNG format!\n"); + fprintf (stderr, "Input is not in GD format!\n"); exit (1); } out = fopen (argv[2], "wb"); diff --git a/ext/gd/libgd/gdxpm.c b/ext/gd/libgd/gdxpm.c index 785afb368..73f86e5df 100644 --- a/ext/gd/libgd/gdxpm.c +++ b/ext/gd/libgd/gdxpm.c @@ -22,7 +22,6 @@ gdImagePtr gdImageCreateFromXpm (char *filename) int i, j, k, number; char buf[5]; gdImagePtr im = 0; - char *apixel; int *pointer; int red = 0, green = 0, blue = 0; int *colors; @@ -34,7 +33,7 @@ gdImagePtr gdImageCreateFromXpm (char *filename) } if (!(im = gdImageCreate(image.width, image.height))) { - return 0; + goto done; } number = image.ncolors; @@ -116,14 +115,8 @@ gdImagePtr gdImageCreateFromXpm (char *filename) colors[i] = gdImageColorResolve(im, red, green, blue); - if (colors[i] == -1) { - php_gd_error("ARRRGH"); - } } - apixel = (char *) gdMalloc(image.cpp + 1); - apixel[image.cpp] = '\0'; - pointer = (int *) image.data; for (i = 0; i < image.height; i++) { for (j = 0; j < image.width; j++) { @@ -132,8 +125,10 @@ gdImagePtr gdImageCreateFromXpm (char *filename) } } - gdFree(apixel); gdFree(colors); + done: + XpmFreeXpmImage(&image); + XpmFreeXpmInfo(&info); return im; } #endif diff --git a/ext/gd/libgd/xbm.c b/ext/gd/libgd/xbm.c index 23d36886f..4be7ec8c1 100644 --- a/ext/gd/libgd/xbm.c +++ b/ext/gd/libgd/xbm.c @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: xbm.c,v 1.7.2.2.2.4 2008/12/31 11:17:38 sebastian Exp $ */ +/* $Id: xbm.c,v 1.7.2.2.2.2.2.2 2008/12/31 11:15:37 sebastian Exp $ */ #include <stdio.h> #include <math.h> diff --git a/ext/gd/php_gd.h b/ext/gd/php_gd.h index 406252b6c..99922067a 100644 --- a/ext/gd/php_gd.h +++ b/ext/gd/php_gd.h @@ -17,14 +17,14 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_gd.h,v 1.59.2.3.2.7 2008/12/31 11:17:37 sebastian Exp $ */ +/* $Id: php_gd.h,v 1.59.2.3.2.5.2.5 2008/12/31 11:15:37 sebastian Exp $ */ #ifndef PHP_GD_H #define PHP_GD_H #define HAVE_GDIMAGECREATEFROMPNG 1 -#if HAVE_LIBTTF|HAVE_LIBFREETYPE +#if HAVE_LIBFREETYPE #define ENABLE_GD_TTF #endif @@ -51,9 +51,11 @@ #define PHP_GDIMG_TYPE_GD2PART 10 #ifdef PHP_WIN32 -#define PHP_GD_API __declspec(dllexport) +# define PHP_GD_API __declspec(dllexport) +#elif defined(__GNUC__) && __GNUC__ >= 4 +# define PHP_GD_API __attribute__ ((visibility("default"))) #else -#define PHP_GD_API +# define PHP_GD_API #endif PHPAPI extern const char php_sig_gif[3]; @@ -69,7 +71,7 @@ PHP_MINIT_FUNCTION(gd); #if HAVE_LIBT1 || HAVE_GD_FONTMUTEX PHP_MSHUTDOWN_FUNCTION(gd); #endif -#if HAVE_LIBGD20 && HAVE_GD_STRINGFT +#if HAVE_GD_STRINGFT PHP_RSHUTDOWN_FUNCTION(gd); #endif @@ -99,7 +101,6 @@ PHP_FUNCTION(imagecreate); PHP_FUNCTION(imageftbbox); PHP_FUNCTION(imagefttext); -#ifdef HAVE_LIBGD20 PHP_FUNCTION(imagecreatetruecolor); PHP_FUNCTION(imagetruecolortopalette); PHP_FUNCTION(imagesetthickness); @@ -112,7 +113,6 @@ PHP_FUNCTION(imagecolorresolvealpha); PHP_FUNCTION(imagecolorclosestalpha); PHP_FUNCTION(imagecolorexactalpha); PHP_FUNCTION(imagecopyresampled); -#endif #ifdef PHP_WIN32 PHP_FUNCTION(imagegrabwindow); diff --git a/ext/gd/tests/bug38212.phpt b/ext/gd/tests/bug38212.phpt index 04c89fece..7548008a6 100644 --- a/ext/gd/tests/bug38212.phpt +++ b/ext/gd/tests/bug38212.phpt @@ -1,5 +1,5 @@ --TEST-- -Bzg #38212 (Seg Fault on invalid imagecreatefromgd2part() parameters) +Bug #38212 (Seg Fault on invalid imagecreatefromgd2part() parameters) --SKIPIF-- <?php if (!function_exists('imagecopy')) die("skip gd extension not available\n"); diff --git a/ext/gd/tests/bug44849.phpt b/ext/gd/tests/bug44849.phpt new file mode 100644 index 000000000..a6d162c3d --- /dev/null +++ b/ext/gd/tests/bug44849.phpt @@ -0,0 +1,12 @@ +--TEST-- +Bug #44849 (imagecolorclosesthwb is not available on Windows) +--SKIPIF-- +<?php + if(!extension_loaded('gd')){ die('skip gd extension not available'); } +?> +--FILE-- +<?php + var_dump(function_exists('imagecolorclosesthwb')); +?> +--EXPECTF-- +bool(true) diff --git a/ext/gd/tests/bug45799.phpt b/ext/gd/tests/bug45799.phpt new file mode 100644 index 000000000..a28f940b7 --- /dev/null +++ b/ext/gd/tests/bug45799.phpt @@ -0,0 +1,15 @@ +--TEST-- +Bug #45799 (imagepng() crashes on empty image). +--SKIPIF-- +<?php + if (!extension_loaded('gd')) die("skip gd extension not available\n"); +?> +--FILE-- +<?php +$img = imagecreate(500,500); +imagepng($img); +imagedestroy($img); +?> +--EXPECTF-- + +Warning: imagepng(): gd-png error: no colors in palette in %s on line %d diff --git a/ext/gd/tests/gd_info_error.phpt b/ext/gd/tests/gd_info_error.phpt index 514530c21..07cabdf52 100644 --- a/ext/gd/tests/gd_info_error.phpt +++ b/ext/gd/tests/gd_info_error.phpt @@ -1,38 +1,38 @@ ---TEST-- -Test gd_info() function : error conditions - with more than expected number of arguments ---SKIPIF-- -<?php -if(!extension_loaded('gd')) { - die('skip gd extension is not loaded'); -} -if(!function_exists('gd_info')) { - die('skip gd_info function is not available'); -} -?> ---FILE-- -<?php -/* Prototype : array gd_info() - * Description: Retrieve information about the currently installed GD library - * Source code: ext/gd/gd.c - */ -$extra_arg_number = 10; -$extra_arg_string = "Hello"; - -echo "*** Testing gd_info() : error conditions ***\n"; - -echo "\n-- Testing gd_info() function with more than expected number of arguments --\n"; -var_dump(gd_info($extra_arg_number)); -var_dump(gd_info($extra_arg_string, $extra_arg_number)); -?> -===DONE=== ---EXPECTF-- -*** Testing gd_info() : error conditions *** - --- Testing gd_info() function with more than expected number of arguments -- - -Warning: Wrong parameter count for gd_info() in %s on line %d -NULL - -Warning: Wrong parameter count for gd_info() in %s on line %d -NULL +--TEST--
+Test gd_info() function : error conditions - with more than expected number of arguments
+--SKIPIF--
+<?php
+if(!extension_loaded('gd')) {
+ die('skip gd extension is not loaded');
+}
+if(!function_exists('gd_info')) {
+ die('skip gd_info function is not available');
+}
+?>
+--FILE--
+<?php
+/* Prototype : array gd_info()
+ * Description: Retrieve information about the currently installed GD library
+ * Source code: ext/gd/gd.c
+ */
+$extra_arg_number = 10;
+$extra_arg_string = "Hello";
+
+echo "*** Testing gd_info() : error conditions ***\n";
+
+echo "\n-- Testing gd_info() function with more than expected number of arguments --\n";
+var_dump(gd_info($extra_arg_number));
+var_dump(gd_info($extra_arg_string, $extra_arg_number));
+?>
+===DONE===
+--EXPECTF--
+*** Testing gd_info() : error conditions ***
+
+-- Testing gd_info() function with more than expected number of arguments --
+
+Warning: gd_info() expects exactly 0 parameters, 1 given in %s on line %d
+bool(false)
+
+Warning: gd_info() expects exactly 0 parameters, 2 given in %s on line %d
+bool(false)
===DONE===
\ No newline at end of file diff --git a/ext/gd/tests/gd_info_variation1.phpt b/ext/gd/tests/gd_info_variation1.phpt index 5430cedc8..9bbca4dfd 100644 --- a/ext/gd/tests/gd_info_variation1.phpt +++ b/ext/gd/tests/gd_info_variation1.phpt @@ -1,50 +1,50 @@ ---TEST-- -Test gd_info() function : variation - Checking all the values in returned array ---SKIPIF-- -<?php -if(!extension_loaded('gd')) { - die('skip gd extension is not loaded'); -} -if(!function_exists('gd_info')) { - die('skip gd_info function is not available'); -} -?> ---FILE-- -<?php -/* Prototype : array gd_info() - * Description: Retrieve information about the currently installed GD library - * Source code: ext/gd/gd.c - */ - -echo "*** Testing gd_info() : variation ***\n"; - -var_dump(gd_info()); -?> -===DONE=== ---EXPECTF-- -*** Testing gd_info() : variation *** -array(%d) { - ["GD Version"]=> - string(%d) "%s" - ["FreeType Support"]=> - bool(%s)%A - ["T1Lib Support"]=> - bool(%s) - ["GIF Read Support"]=> - bool(%s) - ["GIF Create Support"]=> - bool(%s) - ["JPG Support"]=> - bool(%s) - ["PNG Support"]=> - bool(%s) - ["WBMP Support"]=> - bool(%s) - ["XPM Support"]=> - bool(%s) - ["XBM Support"]=> - bool(%s) - ["JIS-mapped Japanese Font Support"]=> - bool(%s) -} +--TEST--
+Test gd_info() function : variation - Checking all the values in returned array
+--SKIPIF--
+<?php
+if(!extension_loaded('gd')) {
+ die('skip gd extension is not loaded');
+}
+if(!function_exists('gd_info')) {
+ die('skip gd_info function is not available');
+}
+?>
+--FILE--
+<?php
+/* Prototype : array gd_info()
+ * Description: Retrieve information about the currently installed GD library
+ * Source code: ext/gd/gd.c
+ */
+
+echo "*** Testing gd_info() : variation ***\n";
+
+var_dump(gd_info());
+?>
+===DONE===
+--EXPECTF--
+*** Testing gd_info() : variation ***
+array(%d) {
+ ["GD Version"]=>
+ string(%d) %a
+ ["FreeType Support"]=>
+ bool%a
+ ["T1Lib Support"]=>
+ bool%a
+ ["GIF Read Support"]=>
+ bool%a
+ ["GIF Create Support"]=>
+ bool%a
+ ["JPG Support"]=>
+ bool%a
+ ["PNG Support"]=>
+ bool%a
+ ["WBMP Support"]=>
+ bool%a
+ ["XPM Support"]=>
+ bool%a
+ ["XBM Support"]=>
+ bool%a
+ ["JIS-mapped Japanese Font Support"]=>
+ bool%a
+}
===DONE===
\ No newline at end of file diff --git a/ext/gd/tests/image_type_to_mime_type_basic.phpt b/ext/gd/tests/image_type_to_mime_type_basic.phpt index 7384c4632..5199fd2c4 100644 --- a/ext/gd/tests/image_type_to_mime_type_basic.phpt +++ b/ext/gd/tests/image_type_to_mime_type_basic.phpt @@ -49,7 +49,7 @@ string(10) "image/jpeg" string(9) "image/png" string(29) "application/x-shockwave-flash" string(9) "image/psd" -string(9) "image/bmp" +string(14) "image/x-ms-bmp" string(10) "image/tiff" string(10) "image/tiff" string(24) "application/octet-stream" diff --git a/ext/gd/tests/image_type_to_mime_type_error.phpt b/ext/gd/tests/image_type_to_mime_type_error.phpt index 5ecdce77c..91801c6f7 100644 --- a/ext/gd/tests/image_type_to_mime_type_error.phpt +++ b/ext/gd/tests/image_type_to_mime_type_error.phpt @@ -1,35 +1,35 @@ ---TEST-- -Test image_type_to_mime_type() function : error conditions - Pass incorrect number of arguments ---FILE-- -<?php -/* Prototype : proto string image_type_to_mime_type(int imagetype) - * Description: Get Mime-Type for image-type returned by getimagesize, exif_read_data, exif_thumbnail, exif_imagetype - * Source code: ext/standard/image.c - */ - -$imagetype = IMAGETYPE_GIF; -$extra_arg = 10; -echo "*** Testing image_type_to_mime_type() : error conditions ***\n"; - -// Zero arguments -echo "\n-- Testing image_type_to_mime_type() function with Zero arguments --\n"; -var_dump( image_type_to_mime_type() ); - -//Test image_type_to_mime_type with one more than the expected number of arguments -echo "\n-- Testing image_type_to_mime_type() function with more than expected no. of arguments --\n"; -var_dump( image_type_to_mime_type($imagetype, $extra_arg) ); -?> -===DONE=== ---EXPECTF-- -*** Testing image_type_to_mime_type() : error conditions *** - --- Testing image_type_to_mime_type() function with Zero arguments -- - -Warning: Wrong parameter count for image_type_to_mime_type() in %s on line %d -bool(false) - --- Testing image_type_to_mime_type() function with more than expected no. of arguments -- - -Warning: Wrong parameter count for image_type_to_mime_type() in %s on line %d -bool(false) +--TEST--
+Test image_type_to_mime_type() function : error conditions - Pass incorrect number of arguments
+--FILE--
+<?php
+/* Prototype : proto string image_type_to_mime_type(int imagetype)
+ * Description: Get Mime-Type for image-type returned by getimagesize, exif_read_data, exif_thumbnail, exif_imagetype
+ * Source code: ext/standard/image.c
+ */
+
+$imagetype = IMAGETYPE_GIF;
+$extra_arg = 10;
+echo "*** Testing image_type_to_mime_type() : error conditions ***\n";
+
+// Zero arguments
+echo "\n-- Testing image_type_to_mime_type() function with Zero arguments --\n";
+var_dump( image_type_to_mime_type() );
+
+//Test image_type_to_mime_type with one more than the expected number of arguments
+echo "\n-- Testing image_type_to_mime_type() function with more than expected no. of arguments --\n";
+var_dump( image_type_to_mime_type($imagetype, $extra_arg) );
+?>
+===DONE===
+--EXPECTF--
+*** Testing image_type_to_mime_type() : error conditions ***
+
+-- Testing image_type_to_mime_type() function with Zero arguments --
+
+Warning: image_type_to_mime_type() expects exactly 1 parameter, 0 given in %simage_type_to_mime_type_error.php on line 13
+NULL
+
+-- Testing image_type_to_mime_type() function with more than expected no. of arguments --
+
+Warning: image_type_to_mime_type() expects exactly 1 parameter, 2 given in %simage_type_to_mime_type_error.php on line 17
+NULL
===DONE===
\ No newline at end of file diff --git a/ext/gd/tests/image_type_to_mime_type_variation1.phpt b/ext/gd/tests/image_type_to_mime_type_variation1.phpt index 1747524d7..81851979e 100644 --- a/ext/gd/tests/image_type_to_mime_type_variation1.phpt +++ b/ext/gd/tests/image_type_to_mime_type_variation1.phpt @@ -1,138 +1,152 @@ ---TEST-- -Test image_type_to_mime_type() function : usage variations - Pass different data types as imagetype ---FILE-- -<?php -/* Prototype : string image_type_to_mime_type(int imagetype) - * Description: Get Mime-Type for image-type returned by getimagesize, exif_read_data, exif_thumbnail, exif_imagetype - * Source code: ext/standard/image.c - */ - -echo "*** Testing image_type_to_mime_type() : usage variations ***\n"; - -error_reporting(E_ALL ^ E_NOTICE); - -//get an unset variable -$unset_var = 10; -unset ($unset_var); - -class MyClass -{ - function __toString() { - return "MyClass"; - } -} - -//array of values to iterate over -$values = array( - - // float data - 100.5, - -100.5, - 100.1234567e10, - 100.7654321E-10, - .5, - - // array data - array(), - array('color' => 'red', 'item' => 'pen'), - - // null data - NULL, - null, - - // boolean data - true, - false, - TRUE, - FALSE, - - // empty data - "", - '', - - // string data - "string", - 'string', - - // object data - new MyClass(), - - // undefined data - @$undefined_var, - - // unset data - @$unset_var, -); - -// loop through each element of the array for imagetype -$iterator = 1; -foreach($values as $value) { - echo "\n-- Iteration $iterator --\n"; - var_dump( image_type_to_mime_type($value) ); - $iterator++; -}; -?> -===DONE=== ---EXPECTF-- -*** Testing image_type_to_mime_type() : usage variations *** - --- Iteration 1 -- -string(24) "application/octet-stream" - --- Iteration 2 -- -string(24) "application/octet-stream" - --- Iteration 3 -- -string(24) "application/octet-stream" - --- Iteration 4 -- -string(24) "application/octet-stream" - --- Iteration 5 -- -string(24) "application/octet-stream" - --- Iteration 6 -- -string(24) "application/octet-stream" - --- Iteration 7 -- -string(9) "image/gif" - --- Iteration 8 -- -string(24) "application/octet-stream" - --- Iteration 9 -- -string(24) "application/octet-stream" - --- Iteration 10 -- -string(9) "image/gif" - --- Iteration 11 -- -string(24) "application/octet-stream" - --- Iteration 12 -- -string(9) "image/gif" - --- Iteration 13 -- -string(24) "application/octet-stream" - --- Iteration 14 -- -string(24) "application/octet-stream" - --- Iteration 15 -- -string(24) "application/octet-stream" - --- Iteration 16 -- -string(24) "application/octet-stream" - --- Iteration 17 -- -string(24) "application/octet-stream" - --- Iteration 18 -- -string(9) "image/gif" - --- Iteration 19 -- -string(24) "application/octet-stream" - --- Iteration 20 -- -string(24) "application/octet-stream" +--TEST--
+Test image_type_to_mime_type() function : usage variations - Pass different data types as imagetype
+--FILE--
+<?php
+/* Prototype : string image_type_to_mime_type(int imagetype)
+ * Description: Get Mime-Type for image-type returned by getimagesize, exif_read_data, exif_thumbnail, exif_imagetype
+ * Source code: ext/standard/image.c
+ */
+
+echo "*** Testing image_type_to_mime_type() : usage variations ***\n";
+
+error_reporting(E_ALL ^ E_NOTICE);
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+class MyClass
+{
+ function __toString() {
+ return "MyClass";
+ }
+}
+
+//array of values to iterate over
+$values = array(
+
+ // float data
+ 100.5,
+ -100.5,
+ 100.1234567e10,
+ 100.7654321E-10,
+ .5,
+
+ // array data
+ array(),
+ array('color' => 'red', 'item' => 'pen'),
+
+ // null data
+ NULL,
+ null,
+
+ // boolean data
+ true,
+ false,
+ TRUE,
+ FALSE,
+
+ // empty data
+ "",
+ '',
+
+ // string data
+ "string",
+ 'string',
+
+ // object data
+ new MyClass(),
+
+ // undefined data
+ @$undefined_var,
+
+ // unset data
+ @$unset_var,
+);
+
+// loop through each element of the array for imagetype
+$iterator = 1;
+foreach($values as $value) {
+ echo "\n-- Iteration $iterator --\n";
+ var_dump( image_type_to_mime_type($value) );
+ $iterator++;
+};
+?>
+===DONE===
+--EXPECTF--
+*** Testing image_type_to_mime_type() : usage variations ***
+
+-- Iteration 1 --
+string(24) "application/octet-stream"
+
+-- Iteration 2 --
+string(24) "application/octet-stream"
+
+-- Iteration 3 --
+string(24) "application/octet-stream"
+
+-- Iteration 4 --
+string(24) "application/octet-stream"
+
+-- Iteration 5 --
+string(24) "application/octet-stream"
+
+-- Iteration 6 --
+
+Warning: image_type_to_mime_type() expects parameter 1 to be long, array given in %s on line %d
+NULL
+
+-- Iteration 7 --
+
+Warning: image_type_to_mime_type() expects parameter 1 to be long, array given in %s on line %d
+NULL
+
+-- Iteration 8 --
+string(24) "application/octet-stream"
+
+-- Iteration 9 --
+string(24) "application/octet-stream"
+
+-- Iteration 10 --
+string(9) "image/gif"
+
+-- Iteration 11 --
+string(24) "application/octet-stream"
+
+-- Iteration 12 --
+string(9) "image/gif"
+
+-- Iteration 13 --
+string(24) "application/octet-stream"
+
+-- Iteration 14 --
+
+Warning: image_type_to_mime_type() expects parameter 1 to be long, string given in %s on line %d
+NULL
+
+-- Iteration 15 --
+
+Warning: image_type_to_mime_type() expects parameter 1 to be long, string given in %s on line %d
+NULL
+
+-- Iteration 16 --
+
+Warning: image_type_to_mime_type() expects parameter 1 to be long, string given in %s on line %d
+NULL
+
+-- Iteration 17 --
+
+Warning: image_type_to_mime_type() expects parameter 1 to be long, string given in %s on line %d
+NULL
+
+-- Iteration 18 --
+
+Warning: image_type_to_mime_type() expects parameter 1 to be long, object given in %s on line %d
+NULL
+
+-- Iteration 19 --
+string(24) "application/octet-stream"
+
+-- Iteration 20 --
+string(24) "application/octet-stream"
===DONE===
\ No newline at end of file diff --git a/ext/gd/tests/image_type_to_mime_type_variation2.phpt b/ext/gd/tests/image_type_to_mime_type_variation2.phpt index 141bc576f..63a035a4a 100644 --- a/ext/gd/tests/image_type_to_mime_type_variation2.phpt +++ b/ext/gd/tests/image_type_to_mime_type_variation2.phpt @@ -1,80 +1,80 @@ ---TEST-- -Test image_type_to_mime_type() function : usage variations - Pass decimal, octal, and hexadecimal values as imagetype ---FILE-- -<?php -/* Prototype : string image_type_to_mime_type(int imagetype) - * Description: Get Mime-Type for image-type returned by getimagesize, exif_read_data, exif_thumbnail, exif_imagetype - * Source code: ext/standard/image.c - */ - -echo "*** Testing image_type_to_mime_type() : usage variations ***\n"; - -error_reporting(E_ALL ^ E_NOTICE); -$values = array ( - //Decimal values - 0, - 1, - 12345, - -12345, - - //Octal values - 02, - 010, - 030071, - -030071, - - //Hexadecimal values - 0x0, - 0x1, - 0xABCD, - -0xABCD -); - -// loop through each element of the array for imagetype -$iterator = 1; -foreach($values as $value) { - echo "\n-- Iteration $iterator --\n"; - var_dump( image_type_to_mime_type($value) ); - $iterator++; -}; -?> -===DONE=== ---EXPECT-- -*** Testing image_type_to_mime_type() : usage variations *** - --- Iteration 1 -- -string(24) "application/octet-stream" - --- Iteration 2 -- -string(9) "image/gif" - --- Iteration 3 -- -string(24) "application/octet-stream" - --- Iteration 4 -- -string(24) "application/octet-stream" - --- Iteration 5 -- -string(10) "image/jpeg" - --- Iteration 6 -- -string(10) "image/tiff" - --- Iteration 7 -- -string(24) "application/octet-stream" - --- Iteration 8 -- -string(24) "application/octet-stream" - --- Iteration 9 -- -string(24) "application/octet-stream" - --- Iteration 10 -- -string(9) "image/gif" - --- Iteration 11 -- -string(24) "application/octet-stream" - --- Iteration 12 -- -string(24) "application/octet-stream" -===DONE=== +--TEST--
+Test image_type_to_mime_type() function : usage variations - Pass decimal, octal, and hexadecimal values as imagetype
+--FILE--
+<?php
+/* Prototype : string image_type_to_mime_type(int imagetype)
+ * Description: Get Mime-Type for image-type returned by getimagesize, exif_read_data, exif_thumbnail, exif_imagetype
+ * Source code: ext/standard/image.c
+ */
+
+echo "*** Testing image_type_to_mime_type() : usage variations ***\n";
+
+error_reporting(E_ALL ^ E_NOTICE);
+$values = array (
+ //Decimal values
+ 0,
+ 1,
+ 12345,
+ -12345,
+
+ //Octal values
+ 02,
+ 010,
+ 030071,
+ -030071,
+
+ //Hexadecimal values
+ 0x0,
+ 0x1,
+ 0xABCD,
+ -0xABCD
+);
+
+// loop through each element of the array for imagetype
+$iterator = 1;
+foreach($values as $value) {
+ echo "\n-- Iteration $iterator --\n";
+ var_dump( image_type_to_mime_type($value) );
+ $iterator++;
+};
+?>
+===DONE===
+--EXPECT--
+*** Testing image_type_to_mime_type() : usage variations ***
+
+-- Iteration 1 --
+string(24) "application/octet-stream"
+
+-- Iteration 2 --
+string(9) "image/gif"
+
+-- Iteration 3 --
+string(24) "application/octet-stream"
+
+-- Iteration 4 --
+string(24) "application/octet-stream"
+
+-- Iteration 5 --
+string(10) "image/jpeg"
+
+-- Iteration 6 --
+string(10) "image/tiff"
+
+-- Iteration 7 --
+string(24) "application/octet-stream"
+
+-- Iteration 8 --
+string(24) "application/octet-stream"
+
+-- Iteration 9 --
+string(24) "application/octet-stream"
+
+-- Iteration 10 --
+string(9) "image/gif"
+
+-- Iteration 11 --
+string(24) "application/octet-stream"
+
+-- Iteration 12 --
+string(24) "application/octet-stream"
+===DONE===
diff --git a/ext/gd/tests/image_type_to_mime_type_variation3.phpt b/ext/gd/tests/image_type_to_mime_type_variation3.phpt index 483890406..8383facb0 100644 --- a/ext/gd/tests/image_type_to_mime_type_variation3.phpt +++ b/ext/gd/tests/image_type_to_mime_type_variation3.phpt @@ -39,7 +39,7 @@ string\(29\) "application\/x-shockwave-flash" string\(9\) "image\/psd" -- Iteration 6 -- -string\(9\) "image\/bmp" +string\(14\) "image\/x-ms-bmp" -- Iteration 7 -- string\(10\) "image\/tiff" @@ -72,5 +72,5 @@ string\(18\) "image\/vnd.wap.wbmp" string\(9\) "image\/xbm" -- Iteration 17 -- -string\(24\) "application\/octet-stream" +string\(24\) "image\/vnd.microsoft.icon" ===DONE=== diff --git a/ext/gd/tests/image_type_to_mime_type_variation4.phpt b/ext/gd/tests/image_type_to_mime_type_variation4.phpt index 90ae17b96..a67bb86a6 100644 --- a/ext/gd/tests/image_type_to_mime_type_variation4.phpt +++ b/ext/gd/tests/image_type_to_mime_type_variation4.phpt @@ -1,5 +1,11 @@ --TEST-- -Test image_type_to_mime_type() function : usage variations - Passing IMAGETYPE_ICO and IMAGETYPE_SWC +Test image_type_to_mime_type() function : usage variations - Passing IMAGETYPE_ICO and IMAGETYPE_SWC +--SKIPIF-- +<?php + if (!defined("IMAGETYPE_SWC") || !defined("IMAGETYPE_ICO") || !extension_loaded('zlib')) { + die("skip zlib extension is not available or IMAGETYPE_SWC/IMAGETYPE_ICO is not defined "); + } +?> --FILE-- <?php /* Prototype : string image_type_to_mime_type(int imagetype) @@ -16,8 +22,8 @@ var_dump( image_type_to_mime_type(IMAGETYPE_ICO) ); var_dump( image_type_to_mime_type(IMAGETYPE_SWC) ); ?> ===DONE=== ---EXPECTREGEX-- -\*\*\* Testing image_type_to_mime_type\(\) : usage variations \*\*\* -string\(24\) "application\/octet-stream" -string\(2[49]\) "application\/(x-shockwave-flash|octet-stream)" -===DONE===
\ No newline at end of file +--EXPECT-- +*** Testing image_type_to_mime_type() : usage variations *** +string(24) "image/vnd.microsoft.icon" +string(29) "application/x-shockwave-flash" +===DONE=== diff --git a/ext/gd/tests/imagecolorallocate_error.phpt b/ext/gd/tests/imagecolorallocate_error.phpt index fa05e9147..6c685b2c9 100644 --- a/ext/gd/tests/imagecolorallocate_error.phpt +++ b/ext/gd/tests/imagecolorallocate_error.phpt @@ -36,16 +36,14 @@ var_dump( imagecolorallocate($im, $red, $green) ); -- Testing imagecolorallocate() function with more than expected no. of arguments -- -Warning: Wrong parameter count for imagecolorallocate() in %s on line %d +Warning: imagecolorallocate() expects exactly 4 parameters, 5 given in %s on line %d NULL -- Testing imagecolorallocate() function with less than expected no. of arguments -- -Warning: Wrong parameter count for imagecolorallocate() in %s on line %d +Warning: imagecolorallocate() expects exactly 4 parameters, 0 given in %s on line %d NULL -Warning: Wrong parameter count for imagecolorallocate() in %s on line %d +Warning: imagecolorallocate() expects exactly 4 parameters, 3 given in %s on line %d NULL -===DONE=== - - +===DONE===
\ No newline at end of file diff --git a/ext/gd/tests/imagecolorallocate_variation1.phpt b/ext/gd/tests/imagecolorallocate_variation1.phpt index b08aecec2..552a0fc08 100644 --- a/ext/gd/tests/imagecolorallocate_variation1.phpt +++ b/ext/gd/tests/imagecolorallocate_variation1.phpt @@ -117,148 +117,148 @@ foreach($values as $key => $value) { -- int 0 -- -Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d -bool(false) +Warning: imagecolorallocate() expects parameter 1 to be resource, integer given in %s on line %d +NULL -- int 1 -- -Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d -bool(false) +Warning: imagecolorallocate() expects parameter 1 to be resource, integer given in %s on line %d +NULL -- int 12345 -- -Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d -bool(false) +Warning: imagecolorallocate() expects parameter 1 to be resource, integer given in %s on line %d +NULL -- int -12345 -- -Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d -bool(false) +Warning: imagecolorallocate() expects parameter 1 to be resource, integer given in %s on line %d +NULL -- float 10.5 -- -Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d -bool(false) +Warning: imagecolorallocate() expects parameter 1 to be resource, double given in %s on line %d +NULL -- float -10.5 -- -Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d -bool(false) +Warning: imagecolorallocate() expects parameter 1 to be resource, double given in %s on line %d +NULL -- float 10.1234567e10 -- -Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d -bool(false) +Warning: imagecolorallocate() expects parameter 1 to be resource, double given in %s on line %d +NULL -- float 10.7654321E-10 -- -Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d -bool(false) +Warning: imagecolorallocate() expects parameter 1 to be resource, double given in %s on line %d +NULL -- float .5 -- -Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d -bool(false) +Warning: imagecolorallocate() expects parameter 1 to be resource, double given in %s on line %d +NULL -- empty array -- -Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d -bool(false) +Warning: imagecolorallocate() expects parameter 1 to be resource, array given in %s on line %d +NULL -- int indexed array -- -Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d -bool(false) +Warning: imagecolorallocate() expects parameter 1 to be resource, array given in %s on line %d +NULL -- associative array -- -Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d -bool(false) +Warning: imagecolorallocate() expects parameter 1 to be resource, array given in %s on line %d +NULL -- nested arrays -- -Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d -bool(false) +Warning: imagecolorallocate() expects parameter 1 to be resource, array given in %s on line %d +NULL -- uppercase NULL -- -Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d -bool(false) +Warning: imagecolorallocate() expects parameter 1 to be resource, null given in %s on line %d +NULL -- lowercase null -- -Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d -bool(false) +Warning: imagecolorallocate() expects parameter 1 to be resource, null given in %s on line %d +NULL -- lowercase true -- -Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d -bool(false) +Warning: imagecolorallocate() expects parameter 1 to be resource, boolean given in %s on line %d +NULL -- lowercase false -- -Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d -bool(false) +Warning: imagecolorallocate() expects parameter 1 to be resource, boolean given in %s on line %d +NULL -- uppercase TRUE -- -Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d -bool(false) +Warning: imagecolorallocate() expects parameter 1 to be resource, boolean given in %s on line %d +NULL -- uppercase FALSE -- -Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d -bool(false) +Warning: imagecolorallocate() expects parameter 1 to be resource, boolean given in %s on line %d +NULL -- empty string DQ -- -Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d -bool(false) +Warning: imagecolorallocate() expects parameter 1 to be resource, string given in %s on line %d +NULL -- empty string SQ -- -Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d -bool(false) +Warning: imagecolorallocate() expects parameter 1 to be resource, string given in %s on line %d +NULL -- string DQ -- -Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d -bool(false) +Warning: imagecolorallocate() expects parameter 1 to be resource, string given in %s on line %d +NULL -- string SQ -- -Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d -bool(false) +Warning: imagecolorallocate() expects parameter 1 to be resource, string given in %s on line %d +NULL -- mixed case string -- -Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d -bool(false) +Warning: imagecolorallocate() expects parameter 1 to be resource, string given in %s on line %d +NULL -- heredoc -- -Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d -bool(false) +Warning: imagecolorallocate() expects parameter 1 to be resource, string given in %s on line %d +NULL -- instance of classWithToString -- -Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d -bool(false) +Warning: imagecolorallocate() expects parameter 1 to be resource, object given in %s on line %d +NULL -- instance of classWithoutToString -- -Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d -bool(false) +Warning: imagecolorallocate() expects parameter 1 to be resource, object given in %s on line %d +NULL -- undefined var -- -Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d -bool(false) +Warning: imagecolorallocate() expects parameter 1 to be resource, null given in %s on line %d +NULL -- unset var -- -Warning: imagecolorallocate(): supplied argument is not a valid Image resource in %s on line %d -bool(false) +Warning: imagecolorallocate() expects parameter 1 to be resource, null given in %s on line %d +NULL -- file resource -- diff --git a/ext/gd/tests/imagecolorallocate_variation2.phpt b/ext/gd/tests/imagecolorallocate_variation2.phpt index d8885f348..bd9dc984d 100644 --- a/ext/gd/tests/imagecolorallocate_variation2.phpt +++ b/ext/gd/tests/imagecolorallocate_variation2.phpt @@ -124,16 +124,24 @@ int(2570) int(2570) --empty array-- -int(2570) + +Warning: imagecolorallocate() expects parameter 2 to be long, array given in %s on line %d +NULL --int indexed array-- -int(68106) + +Warning: imagecolorallocate() expects parameter 2 to be long, array given in %s on line %d +NULL --associative array-- -int(68106) + +Warning: imagecolorallocate() expects parameter 2 to be long, array given in %s on line %d +NULL --nested arrays-- -int(68106) + +Warning: imagecolorallocate() expects parameter 2 to be long, array given in %s on line %d +NULL --uppercase NULL-- int(2570) @@ -154,32 +162,44 @@ int(68106) int(2570) --empty string DQ-- -int(2570) + +Warning: imagecolorallocate() expects parameter 2 to be long, string given in %s on line %d +NULL --empty string SQ-- -int(2570) + +Warning: imagecolorallocate() expects parameter 2 to be long, string given in %s on line %d +NULL --string DQ-- -int(2570) + +Warning: imagecolorallocate() expects parameter 2 to be long, string given in %s on line %d +NULL --string SQ-- -int(2570) + +Warning: imagecolorallocate() expects parameter 2 to be long, string given in %s on line %d +NULL --mixed case string-- -int(2570) + +Warning: imagecolorallocate() expects parameter 2 to be long, string given in %s on line %d +NULL --heredoc-- -int(2570) + +Warning: imagecolorallocate() expects parameter 2 to be long, string given in %s on line %d +NULL --instance of classWithToString-- -Notice: Object of class classWithToString could not be converted to int in %s on line %d -int(68106) +Warning: imagecolorallocate() expects parameter 2 to be long, object given in %s on line %d +NULL --instance of classWithoutToString-- -Notice: Object of class classWithoutToString could not be converted to int in %s on line %d -int(68106) +Warning: imagecolorallocate() expects parameter 2 to be long, object given in %s on line %d +NULL --undefined var-- int(2570) @@ -188,5 +208,7 @@ int(2570) int(2570) --file resource-- -int(330250) + +Warning: imagecolorallocate() expects parameter 2 to be long, resource given in %s on line %d +NULL ===DONE=== diff --git a/ext/gd/tests/imagecolorallocate_variation3.phpt b/ext/gd/tests/imagecolorallocate_variation3.phpt index 6bdf2596d..c48dc29cf 100644 --- a/ext/gd/tests/imagecolorallocate_variation3.phpt +++ b/ext/gd/tests/imagecolorallocate_variation3.phpt @@ -55,8 +55,8 @@ $values = array( // float data 'float 10.5' => 10.5, 'float -10.5' => -10.5, - 'float 10.1234567e10' => 10.1234567e10, - 'float 10.7654321E-10' => 10.7654321E-10, + 'float 10.1234567e5' => 10.1234567e5, + 'float 10.7654321E-5' => 10.7654321E-5, 'float .5' => .5, // array data @@ -114,26 +114,34 @@ int(657930) --float -10.5-- int(652810) ---float 10.1234567e10-- -int(217143306) +--float 10.1234567e5-- +int(259815690) ---float 10.7654321E-10-- +--float 10.7654321E-5-- int(655370) --float .5-- int(655370) --empty array-- -int(655370) + +Warning: imagecolorallocate() expects parameter 3 to be long, array given in %s on line %d +NULL --int indexed array-- -int(655626) + +Warning: imagecolorallocate() expects parameter 3 to be long, array given in %s on line %d +NULL --associative array-- -int(655626) + +Warning: imagecolorallocate() expects parameter 3 to be long, array given in %s on line %d +NULL --nested arrays-- -int(655626) + +Warning: imagecolorallocate() expects parameter 3 to be long, array given in %s on line %d +NULL --uppercase NULL-- int(655370) @@ -154,32 +162,44 @@ int(655626) int(655370) --empty string DQ-- -int(655370) + +Warning: imagecolorallocate() expects parameter 3 to be long, string given in %s on line %d +NULL --empty string SQ-- -int(655370) + +Warning: imagecolorallocate() expects parameter 3 to be long, string given in %s on line %d +NULL --string DQ-- -int(655370) + +Warning: imagecolorallocate() expects parameter 3 to be long, string given in %s on line %d +NULL --string SQ-- -int(655370) + +Warning: imagecolorallocate() expects parameter 3 to be long, string given in %s on line %d +NULL --mixed case string-- -int(655370) + +Warning: imagecolorallocate() expects parameter 3 to be long, string given in %s on line %d +NULL --heredoc-- -int(655370) + +Warning: imagecolorallocate() expects parameter 3 to be long, string given in %s on line %d +NULL --instance of classWithToString-- -Notice: Object of class classWithToString could not be converted to int in %s on line %d -int(655626) +Warning: imagecolorallocate() expects parameter 3 to be long, object given in %s on line %d +NULL --instance of classWithoutToString-- -Notice: Object of class classWithoutToString could not be converted to int in %s on line %d -int(655626) +Warning: imagecolorallocate() expects parameter 3 to be long, object given in %s on line %d +NULL --undefined var-- int(655370) @@ -188,5 +208,7 @@ int(655370) int(655370) --file resource-- -int(656650) + +Warning: imagecolorallocate() expects parameter 3 to be long, resource given in %s on line %d +NULL ===DONE===
\ No newline at end of file diff --git a/ext/gd/tests/imagecolorallocate_variation4.phpt b/ext/gd/tests/imagecolorallocate_variation4.phpt index f170e4ad9..328a4cd3b 100644 --- a/ext/gd/tests/imagecolorallocate_variation4.phpt +++ b/ext/gd/tests/imagecolorallocate_variation4.phpt @@ -123,16 +123,24 @@ int(657920) int(657920) --empty array-- -int(657920) + +Warning: imagecolorallocate() expects parameter 4 to be long, array given in %s on line %d +NULL --int indexed array-- -int(657921) + +Warning: imagecolorallocate() expects parameter 4 to be long, array given in %s on line %d +NULL --associative array-- -int(657921) + +Warning: imagecolorallocate() expects parameter 4 to be long, array given in %s on line %d +NULL --nested arrays-- -int(657921) + +Warning: imagecolorallocate() expects parameter 4 to be long, array given in %s on line %d +NULL --uppercase NULL-- int(657920) @@ -153,32 +161,44 @@ int(657921) int(657920) --empty string DQ-- -int(657920) + +Warning: imagecolorallocate() expects parameter 4 to be long, string given in %s on line %d +NULL --empty string SQ-- -int(657920) + +Warning: imagecolorallocate() expects parameter 4 to be long, string given in %s on line %d +NULL --string DQ-- -int(657920) + +Warning: imagecolorallocate() expects parameter 4 to be long, string given in %s on line %d +NULL --string SQ-- -int(657920) + +Warning: imagecolorallocate() expects parameter 4 to be long, string given in %s on line %d +NULL --mixed case string-- -int(657920) + +Warning: imagecolorallocate() expects parameter 4 to be long, string given in %s on line %d +NULL --heredoc-- -int(657920) + +Warning: imagecolorallocate() expects parameter 4 to be long, string given in %s on line %d +NULL --instance of classWithToString-- -Notice: Object of class classWithToString could not be converted to int in %s on line %d -int(657921) +Warning: imagecolorallocate() expects parameter 4 to be long, object given in %s on line %d +NULL --instance of classWithoutToString-- -Notice: Object of class classWithoutToString could not be converted to int in %s on line %d -int(657921) +Warning: imagecolorallocate() expects parameter 4 to be long, object given in %s on line %d +NULL --undefined var-- int(657920) @@ -187,5 +207,7 @@ int(657920) int(657920) --file resource-- -int(657925) -===DONE=== + +Warning: imagecolorallocate() expects parameter 4 to be long, resource given in %s on line %d +NULL +===DONE===
\ No newline at end of file diff --git a/ext/gd/tests/imagecolorclosesthwb.phpt b/ext/gd/tests/imagecolorclosesthwb.phpt new file mode 100644 index 000000000..4266514a8 --- /dev/null +++ b/ext/gd/tests/imagecolorclosesthwb.phpt @@ -0,0 +1,30 @@ +--TEST-- +imagecolorclosesthwb() test +--SKIPIF-- +<?php + if(!extension_loaded('gd')){ die('skip: gd extension not available'); } + if(!function_exists('imagecolorclosesthwb')){ die('skip: imagecolorclosesthwb() not available'); } +?> +--FILE-- +<?php + $im = imagecreatefrompng(dirname(__FILE__).'/test.png'); + + var_dump(imagecolorclosesthwb($im, 255, 50, 0)); + + var_dump(imagecolorclosesthwb(NULL)); + var_dump(imagecolorclosesthwb(NULL, NULL, NULL, NULL)); + var_dump(imagecolorclosesthwb($im, "hello", "from", "gd")); + + imagedestroy($im); +?> +--EXPECTF-- +int(16724480) + +Warning: imagecolorclosesthwb() expects exactly 4 parameters, 1 given in %s on line %d +NULL + +Warning: imagecolorclosesthwb() expects parameter 1 to be resource, null given in %s on line %d +NULL + +Warning: imagecolorclosesthwb() expects parameter 2 to be long, string given in %s on line %d +NULL diff --git a/ext/gd/tests/imagecolorstotal_error.phpt b/ext/gd/tests/imagecolorstotal_error.phpt index 995fa400e..a7f3b9571 100644 --- a/ext/gd/tests/imagecolorstotal_error.phpt +++ b/ext/gd/tests/imagecolorstotal_error.phpt @@ -39,12 +39,12 @@ fclose($im); -- Testing imagecolorstotal() function with Zero arguments -- -Warning: Wrong parameter count for imagecolorstotal() in %s on line %d +Warning: imagecolorstotal() expects exactly 1 parameter, 0 given in %s on line %d NULL -- Testing imagecolorstotal() function with more than expected no. of arguments -- -Warning: Wrong parameter count for imagecolorstotal() in %s on line %d +Warning: imagecolorstotal() expects exactly 1 parameter, 2 given in %s on line %d NULL -- Testing imagecolorstotal() function with a invalid resource diff --git a/ext/gd/tests/imagecolourstotal_basic.phpt b/ext/gd/tests/imagecolourstotal_basic.phpt new file mode 100644 index 000000000..c26fa68cf --- /dev/null +++ b/ext/gd/tests/imagecolourstotal_basic.phpt @@ -0,0 +1,50 @@ +--TEST-- +Test imagecolorstotal() function : basic functionality +--CREDITS-- +Felix De Vliegher <felix.devliegher@gmail.com> +--SKIPIF-- +<?php + if (!extension_loaded('gd')) { + die("skip gd extension not available."); + } + if (!function_exists("imagecolorstotal")) { + die("skip imagecolorstotal() not available."); + } +?> +--FILE-- +<?php +/* Prototype : int imagecolorstotal(resource im) + * Description: Find out the number of colors in an image's palette + * Source code: ext/gd/gd.c + * Alias to functions: + */ + +echo "*** Testing imagecolorstotal() : basic functionality ***\n"; + +// Palette image +$img = imagecreate( 50, 50 ); +var_dump( imagecolorstotal( $img ) ); +$bg = imagecolorallocate( $img, 255, 255, 255 ); +var_dump( imagecolorstotal( $img )); +$bg = imagecolorallocate( $img, 255, 0, 0 ); +$bg = imagecolorallocate( $img, 0, 0, 255 ); +var_dump( imagecolorstotal( $img )); +imagedestroy( $img ); + +// Truecolor image +$img = imagecreatetruecolor( 50, 50 ); +var_dump( imagecolorstotal( $img ) ); +$bg = imagecolorallocate( $img, 255, 255, 255 ); +var_dump( imagecolorstotal( $img ) ); +imagedestroy( $img ); + +?> +===DONE=== +--EXPECTF-- +*** Testing imagecolorstotal() : basic functionality *** +int(0) +int(1) +int(3) +int(0) +int(0) +===DONE=== diff --git a/ext/gd/tests/imagefilter.phpt b/ext/gd/tests/imagefilter.phpt index b3855d66f..8b17fb80b 100644 --- a/ext/gd/tests/imagefilter.phpt +++ b/ext/gd/tests/imagefilter.phpt @@ -21,7 +21,7 @@ $no_arg_filters = array( $SAVE_DIR = dirname(__FILE__); $SOURCE_IMG = $SAVE_DIR . "/test.png"; - + foreach ($no_arg_filters as $filt) { $im = imagecreatefrompng($SOURCE_IMG); if (imagefilter($im, constant($filt))) { @@ -34,7 +34,7 @@ $SOURCE_IMG = $SAVE_DIR . "/test.png"; } $im = imagecreatefrompng($SOURCE_IMG); - + if (imagefilter($im, IMG_FILTER_SMOOTH, -1924.124)) { imagepng($im, $SAVE_DIR . "/IMG_FILTER_SMOOTH.png"); echo "IMG_FILTER_SMOOTH success\n"; @@ -42,9 +42,9 @@ $SOURCE_IMG = $SAVE_DIR . "/test.png"; } else { echo "IMG_FILTER_SMOOTH failed\n"; } - + $im = imagecreatefrompng($SOURCE_IMG); - + if (imagefilter($im, IMG_FILTER_COLORIZE, -127.12, -127.98, 127)) { imagepng($im, $SAVE_DIR . "/IMG_FILTER_COLORIZE.png"); echo "IMG_FILTER_COLORIZE success\n"; @@ -52,9 +52,9 @@ $SOURCE_IMG = $SAVE_DIR . "/test.png"; } else { echo "IMG_FILTER_COLORIZE failed\n"; } - + $im = imagecreatefrompng($SOURCE_IMG); - + if (imagefilter($im, IMG_FILTER_CONTRAST, -90)) { imagepng($im, $SAVE_DIR . "/IMG_FILTER_CONTRAST.png"); echo "IMG_FILTER_CONTRAST success\n"; @@ -64,7 +64,7 @@ $SOURCE_IMG = $SAVE_DIR . "/test.png"; } $im = imagecreatefrompng($SOURCE_IMG); - + if (imagefilter($im, IMG_FILTER_BRIGHTNESS, 98)) { imagepng($im, $SAVE_DIR . "/IMG_FILTER_BRIGHTNESS.png"); echo "IMG_FILTER_BRIGHTNESS success\n"; @@ -72,6 +72,16 @@ $SOURCE_IMG = $SAVE_DIR . "/test.png"; } else { echo "IMG_FILTER_BRIGHTNESS failed\n"; } + + $im = imagecreatefrompng($SOURCE_IMG); + + if (imagefilter($im, IMG_FILTER_PIXELATE, 5, true)) { + imagepng($im, $SAVE_DIR . "/IMG_FILTER_PIXELATE.png"); + echo "IMG_FILTER_PIXELATE success\n"; + unlink($SAVE_DIR . "/IMG_FILTER_PIXELATE.png"); + } else { + echo "IMG_FILTER_PIXELATE failed\n"; + } ?> --EXPECT-- IMG_FILTER_NEGATE success @@ -85,3 +95,4 @@ IMG_FILTER_SMOOTH success IMG_FILTER_COLORIZE success IMG_FILTER_CONTRAST success IMG_FILTER_BRIGHTNESS success +IMG_FILTER_PIXELATE success diff --git a/ext/gd/tests/libgd00186.phpt b/ext/gd/tests/libgd00186.phpt new file mode 100644 index 000000000..cb1686b5a --- /dev/null +++ b/ext/gd/tests/libgd00186.phpt @@ -0,0 +1,36 @@ +--TEST-- +libgd #186 (Tiling true colour with palette image does not work) +--SKIPIF-- +<?php + if (!extension_loaded('gd')) die("skip gd extension not available\n"); +?> +--FILE-- +<?php +$im = imagecreatetruecolor(10,10); +$tile = imagecreate(10,10); +$red = imagecolorallocate($tile,0xff,0,0); +$green = imagecolorallocate($tile,0,0xff,0); +$blue = imagecolorallocate($tile,0,0,0xff); +$other = imagecolorallocate($tile,0,0,0x2); +imagefilledrectangle($tile,0,0,2,10,$red); +imagefilledrectangle($tile,3,0,4,10,$green); +imagefilledrectangle($tile,5,0,7,10,$blue); +imagefilledrectangle($tile,8,0,9,10,$other); +imagecolortransparent($tile,$blue); +imagesettile($im,$tile); +for ($i=0; $i<10; $i++) { + imagesetpixel($im,$i,$i,IMG_COLOR_TILED); +} +$index = imagecolorat($im,9,9); +$arr = imagecolorsforindex($im, $index); +if ($arr['blue'] == 2) { + $r = "Ok"; +} else { + $r = "Failed"; +} +imagedestroy($tile); +imagedestroy($im); +echo $r; +?> +--EXPECT-- +Ok diff --git a/ext/gd/tests/libgd00191.phpt b/ext/gd/tests/libgd00191.phpt new file mode 100644 index 000000000..6e3ffd51b --- /dev/null +++ b/ext/gd/tests/libgd00191.phpt @@ -0,0 +1,23 @@ +--TEST-- +libgd FS#191 (A circle becomes square) +--SKIPIF-- +<?php + if (!extension_loaded('gd')) die("skip gd extension not available\n"); + if (!GD_BUNDLED) die("skip requires bundled GD library\n"); +?> +--FILE-- +<?php +$im = imagecreatetruecolor(100, 100); +imagefilledrectangle($im, 0, 0, 100, 100, imagecolorallocate($im, 255, 255, 255)); +imagesetthickness($im, 20); +imagefilledellipse($im, 30, 50, 20, 20, imagecolorallocate($im, 0, 0, 0)); +$index = imagecolorat($im, 12, 28); +$arr = imagecolorsforindex($im, $index); +if ($arr['red'] == 255 && $arr['green'] == 255 && $arr['blue'] == 255) { + echo "Ok"; +} else { + echo "failed"; +} +?> +--EXPECT-- +Ok diff --git a/ext/gd/tests/lines.phpt b/ext/gd/tests/lines.phpt index e8c663bca..2c999695e 100644 --- a/ext/gd/tests/lines.phpt +++ b/ext/gd/tests/lines.phpt @@ -106,7 +106,7 @@ if ($p3) { ?> --EXPECTF-- -Warning: Wrong parameter count for imageline() in %s on line %d +Warning: imageline() expects exactly 6 parameters, 5 given in %s on line %d Horizontal: ok Vertical: ok Diagonal: ok |
