diff options
Diffstat (limited to 'ext/gd')
-rw-r--r-- | ext/gd/CREDITS | 2 | ||||
-rw-r--r-- | ext/gd/Makefile.in | 7 | ||||
-rw-r--r-- | ext/gd/config.m4 | 263 | ||||
-rw-r--r-- | ext/gd/gd.c | 3622 | ||||
-rw-r--r-- | ext/gd/gd.dsp | 203 | ||||
-rw-r--r-- | ext/gd/gd_ctx.c | 106 | ||||
-rw-r--r-- | ext/gd/gdcache.c | 201 | ||||
-rw-r--r-- | ext/gd/gdcache.h | 87 | ||||
-rw-r--r-- | ext/gd/gdt1.c | 549 | ||||
-rw-r--r-- | ext/gd/gdt1.h | 36 | ||||
-rw-r--r-- | ext/gd/gdttf.c | 868 | ||||
-rw-r--r-- | ext/gd/gdttf.h | 16 | ||||
-rw-r--r-- | ext/gd/php_gd.h | 180 | ||||
-rw-r--r-- | ext/gd/setup.stub | 6 |
14 files changed, 0 insertions, 6146 deletions
diff --git a/ext/gd/CREDITS b/ext/gd/CREDITS deleted file mode 100644 index 8cdeef9338..0000000000 --- a/ext/gd/CREDITS +++ /dev/null @@ -1,2 +0,0 @@ -GD imaging -Rasmus Lerdorf, Stig Bakken, Jim Winstead, Jouni Ahto diff --git a/ext/gd/Makefile.in b/ext/gd/Makefile.in deleted file mode 100644 index c1b73be7fb..0000000000 --- a/ext/gd/Makefile.in +++ /dev/null @@ -1,7 +0,0 @@ - -LTLIBRARY_NAME = libgd.la -LTLIBRARY_SOURCES = gd.c gdcache.c gdttf.c gdt1.c -LTLIBRARY_SHARED_NAME = gd.la -LTLIBRARY_SHARED_LIBADD = $(GD_SHARED_LIBADD) - -include $(top_srcdir)/build/dynlib.mk diff --git a/ext/gd/config.m4 b/ext/gd/config.m4 deleted file mode 100644 index f2723db7b8..0000000000 --- a/ext/gd/config.m4 +++ /dev/null @@ -1,263 +0,0 @@ -dnl -dnl $Id$ -dnl - -AC_DEFUN(PHP_GD_JPEG,[ - PHP_ARG_WITH(jpeg-dir, for the location of libjpeg, - [ --with-jpeg-dir=DIR GD: Set the path to libjpeg install prefix.]) - - if test "$PHP_JPEG_DIR" != "no"; then - - for i in /usr /usr/local $PHP_JPEG_DIR; do - test -f $i/lib/libjpeg.$SHLIB_SUFFIX_NAME -o -f $i/lib/libjpeg.a && GD_JPEG_DIR=$i - done - - if test -z "$GD_JPEG_DIR"; then - AC_MSG_ERROR([libjpeg.(a|so) not found.]) - fi - - PHP_CHECK_LIBRARY(jpeg,jpeg_read_header, - [ - PHP_ADD_LIBRARY_WITH_PATH(jpeg, $GD_JPEG_DIR/lib, GD_SHARED_LIBADD) - ],[ - AC_MSG_ERROR([Problem with libjpeg.(a|so). Please check config.log for more information.]) - ],[ - -L$GD_JPEG_DIR/lib - ]) - else - AC_MSG_RESULT([If configure fails try --with-jpeg-dir=<DIR>]) - fi -]) - -AC_DEFUN(PHP_GD_PNG,[ - PHP_ARG_WITH(png-dir, for the location of libpng, - [ --with-png-dir=DIR GD: Set the path to libpng install prefix.]) - - if test "$PHP_PNG_DIR" != "no"; then - - for i in /usr /usr/local $PHP_PNG_DIR; do - test -f $i/lib/libpng.$SHLIB_SUFFIX_NAME -o -f $i/lib/libpng.a && GD_PNG_DIR=$i - done - - if test -z "$GD_PNG_DIR"; then - AC_MSG_ERROR([libpng.(a|so) not found.]) - fi - - if test "$PHP_ZLIB_DIR" = "no"; then - AC_MSG_ERROR([PNG support requires ZLIB. Use --with-zlib-dir=<DIR>]) - fi - - PHP_CHECK_LIBRARY(png,png_write_image, - [ - PHP_ADD_LIBRARY_WITH_PATH(z, $PHP_ZLIB_DIR/lib, GD_SHARED_LIBADD) - PHP_ADD_LIBRARY_WITH_PATH(png, $GD_PNG_DIR/lib, GD_SHARED_LIBADD) - ],[ - AC_MSG_ERROR([Problem with libpng.(a|so) or libz.(a|so). Please check config.log for more information.]) - ],[ - -L$PHP_ZLIB_DIR/lib -lz -L$GD_PNG_DIR/lib - ]) - - else - AC_MSG_RESULT([If configure fails try --with-png-dir=<DIR> and --with-zlib-dir=<DIR>]) - fi -]) - -AC_DEFUN(PHP_GD_XPM,[ - PHP_ARG_WITH(xpm-dir, for the location of libXpm, - [ --with-xpm-dir=DIR GD: Set the path to libXpm install prefix.]) - - if test "$PHP_XPM_DIR" != "no"; then - - for i in /usr /usr/local /usr/X11R6 $PHP_XPM_DIR; do - test -f $i/lib/libXpm.$SHLIB_SUFFIX_NAME -o -f $i/lib/libXpm.a && GD_XPM_DIR=$i - done - - if test -z "$GD_XPM_DIR"; then - AC_MSG_ERROR([libXpm.(a|so) not found.]) - fi - - PHP_CHECK_LIBRARY(Xpm,XpmFreeXpmImage, - [ - PHP_ADD_LIBRARY_WITH_PATH(Xpm, $GD_XPM_DIR/lib, GD_SHARED_LIBADD) - PHP_ADD_LIBRARY_WITH_PATH(X11, $GD_XPM_DIR/lib, GD_SHARED_LIBADD) - ],[ - AC_MSG_ERROR([Problem with libXpm.(a|so) or libX11.(a|so). Please check config.log for more information.]) - ],[ - -L$GD_XPM_DIR/lib -lX11 - ]) - else - AC_MSG_RESULT(If configure fails try --with-xpm-dir=<DIR>) - fi -]) - -AC_DEFUN(PHP_GD_FREETYPE1,[ - PHP_ARG_WITH(ttf,for FreeType 1.x support, - [ --with-ttf[=DIR] GD: Include FreeType 1.x support]) - - if test "$PHP_TTF" != "no"; then - if test "$PHP_FREETYPE_DIR" = "no" -o "$PHP_FREETYPE_DIR" = ""; then - if test -n "$PHP_TTF" ; then - for i in /usr /usr/local $PHP_TTF; 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 - done - fi - if test -n "$TTF_DIR" ; then - AC_DEFINE(HAVE_LIBTTF,1,[ ]) - PHP_ADD_LIBRARY_WITH_PATH(ttf, $TTF_DIR/lib, 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_RESULT([no - FreeType 2.x is to be used instead]) - fi - fi -]) - -AC_DEFUN(PHP_GD_FREETYPE2,[ - PHP_ARG_WITH(freetype-dir, for freetype(2), - [ --with-freetype-dir=DIR GD: Set the path to freetype2 install prefix.]) - - if test "$PHP_FREETYPE_DIR" != "no"; then - for i in /usr /usr/local $PHP_FREETYPE_DIR; do - if test -f "$i/include/freetype2/freetype/freetype.h"; then - FREETYPE2_DIR=$i - FREETYPE2_INC_DIR=$i/include/freetype2/freetype - fi - done - - if test -n "$FREETYPE2_DIR" ; then - PHP_ADD_LIBRARY_WITH_PATH(freetype, $FREETYPE2_DIR/lib, GD_SHARED_LIBADD) - PHP_ADD_INCLUDE($FREETYPE2_INC_DIR) - AC_DEFINE(USE_GD_IMGSTRTTF, 1, [ ]) - AC_DEFINE(HAVE_LIBFREETYPE,1,[ ]) - else - AC_MSG_ERROR([freetype2 not found!]) - fi - else - AC_MSG_RESULT([If configure fails try --with-freetype-dir=<DIR>]) - fi -]) - -AC_DEFUN(PHP_GD_T1LIB,[ - PHP_ARG_WITH(t1lib, for T1lib support, - [ --with-t1lib[=DIR] GD: Include T1lib support.]) - - if test "$PHP_T1LIB" != "no"; then - - for i in /usr /usr/local $PHP_T1LIB; do - test -f "$i/include/t1lib.h" && GD_T1_DIR=$i - done - - if test -z "$GD_T1_DIR"; then - AC_MSG_ERROR([Your t1lib distribution is not installed correctly. Please reinstall it.]) - fi - - PHP_CHECK_LIBRARY(t1, T1_LoadFont, - [ - AC_DEFINE(HAVE_LIBT1,1,[ ]) - PHP_ADD_INCLUDE("$GD_T1_DIR/include") - PHP_ADD_LIBRARY_WITH_PATH(t1, "$GD_T1_DIR/lib", GD_SHARED_LIBADD) - ],[ - AC_MSG_ERROR([Problem with libt1.(a|so). Please check config.log for more information.]) - ],[ - -L$GD_T1_DIR/lib - ]) - fi -]) - -AC_DEFUN(PHP_GD_TTSTR,[ - PHP_ARG_ENABLE(gd-native-ttf, whether to enable truetype string function in GD, - [ --enable-gd-native-ttf GD: Enable TrueType string function.]) - - if test "$PHP_GD_NATIVE_TTF" = "yes"; then - AC_DEFINE(USE_GD_IMGSTRTTF, 1, [ ]) - fi -]) - -AC_DEFUN(PHP_GD_CHECK_VERSION,[ - PHP_CHECK_LIBRARY(gd, gdImageString16, [AC_DEFINE(HAVE_LIBGD13, 1, [ ])], [], [ -L$GD_LIB $GD_SHARED_LIBADD ]) - PHP_CHECK_LIBRARY(gd, gdImagePaletteCopy, [AC_DEFINE(HAVE_LIBGD15, 1, [ ])], [], [ -L$GD_LIB $GD_SHARED_LIBADD ]) - PHP_CHECK_LIBRARY(gd, gdImageCreateFromPng, [AC_DEFINE(HAVE_GD_PNG, 1, [ ])], [], [ -L$GD_LIB $GD_SHARED_LIBADD ]) - PHP_CHECK_LIBRARY(gd, gdImageCreateFromGif, [AC_DEFINE(HAVE_GD_GIF_READ, 1, [ ])], [], [ -L$GD_LIB $GD_SHARED_LIBADD ]) - PHP_CHECK_LIBRARY(gd, gdImageGif, [AC_DEFINE(HAVE_GD_GIF_CREATE, 1, [ ])], [], [ -L$GD_LIB $GD_SHARED_LIBADD ]) - PHP_CHECK_LIBRARY(gd, gdImageWBMP, [AC_DEFINE(HAVE_GD_WBMP, 1, [ ])], [], [ -L$GD_LIB $GD_SHARED_LIBADD ]) - PHP_CHECK_LIBRARY(gd, gdImageCreateFromJpeg, [AC_DEFINE(HAVE_GD_JPG, 1, [ ])], [], [ -L$GD_LIB $GD_SHARED_LIBADD ]) - PHP_CHECK_LIBRARY(gd, gdImageCreateFromXpm, [AC_DEFINE(HAVE_GD_XPM, 1, [ ])], [], [ -L$GD_LIB $GD_SHARED_LIBADD ]) - PHP_CHECK_LIBRARY(gd, gdImageCreateFromGd2, [AC_DEFINE(HAVE_GD_GD2, 1, [ ])], [], [ -L$GD_LIB $GD_SHARED_LIBADD ]) - PHP_CHECK_LIBRARY(gd, gdImageCreateTrueColor, [AC_DEFINE(HAVE_LIBGD20, 1, [ ])], [], [ -L$GD_LIB $GD_SHARED_LIBADD ]) - PHP_CHECK_LIBRARY(gd, gdImageSetTile, [AC_DEFINE(HAVE_GD_IMAGESETTILE, 1, [ ])], [], [ -L$GD_LIB $GD_SHARED_LIBADD ]) - PHP_CHECK_LIBRARY(gd, gdImageSetBrush, [AC_DEFINE(HAVE_GD_IMAGESETBRUSH, 1, [ ])], [], [ -L$GD_LIB $GD_SHARED_LIBADD ]) - PHP_CHECK_LIBRARY(gd, gdImageStringTTF, [AC_DEFINE(HAVE_GD_STRINGTTF, 1, [ ])], [], [ -L$GD_LIB $GD_SHARED_LIBADD ]) - PHP_CHECK_LIBRARY(gd, gdImageStringFT, [AC_DEFINE(HAVE_GD_STRINGFT, 1, [ ])], [], [ -L$GD_LIB $GD_SHARED_LIBADD ]) - PHP_CHECK_LIBRARY(gd, gdImageStringFTEx, [AC_DEFINE(HAVE_GD_STRINGFTEX, 1, [ ])], [], [ -L$GD_LIB $GD_SHARED_LIBADD ]) - PHP_CHECK_LIBRARY(gd, gdImageColorClosestHWB, [AC_DEFINE(HAVE_COLORCLOSESTHWB, 1, [ ])], [], [ -L$GD_LIB $GD_SHARED_LIBADD ]) - PHP_CHECK_LIBRARY(gd, gdImageColorResolve, [AC_DEFINE(HAVE_GDIMAGECOLORRESOLVE, 1, [ ])], [], [ -L$GD_LIB $GD_SHARED_LIBADD ]) - PHP_CHECK_LIBRARY(gd, gdImageGifCtx, [AC_DEFINE(HAVE_GD_GIF_CTX, 1, [ ])], [], [ -L$GD_LIB $GD_SHARED_LIBADD ]) -]) - - -PHP_ARG_WITH(gd, for GD support, -[ --with-gd[=DIR] Include GD support (DIR is GD's install dir).]) - -if test "$PHP_GD" != "no"; then - - PHP_EXTENSION(gd, $ext_shared) - PHP_SUBST(GD_SHARED_LIBADD) - -dnl Various checks for GD features - PHP_SHLIB_SUFFIX_NAME - PHP_GD_TTSTR - PHP_GD_JPEG - PHP_GD_PNG - PHP_GD_XPM - PHP_GD_FREETYPE2 - PHP_GD_FREETYPE1 - PHP_GD_T1LIB - - if test "$PHP_GD" = "yes"; then - GD_SEARCH_PATHS="/usr/local /usr" - else - GD_SEARCH_PATHS=$PHP_GD - fi - - for j in $GD_SEARCH_PATHS; do - for i in include/gd1.3 include/gd include gd1.3 gd ""; do - test -f $j/$i/gd.h && GD_INCLUDE=$j/$i - done - - for i in lib/gd1.3 lib/gd lib gd1.3 gd ""; do - test -f $j/$i/libgd.$SHLIB_SUFFIX_NAME -o -f $j/$i/libgd.a && GD_LIB=$j/$i - done - done - - if test -n "$GD_INCLUDE" -a -n "$GD_LIB" ; then - PHP_ADD_LIBRARY_WITH_PATH(gd, $GD_LIB, GD_SHARED_LIBADD) - AC_DEFINE(HAVE_LIBGD,1,[ ]) - PHP_GD_CHECK_VERSION - else - AC_MSG_ERROR([Unable to find libgd.(a|so) anywhere under $withval]) - fi - -dnl NetBSD package structure - if test -f /usr/pkg/include/gd/gd.h -a -z "$GD_INCLUDE" ; then - GD_INCLUDE=/usr/pkg/include/gd - fi - -dnl SuSE 6.x package structure - if test -f /usr/include/gd/gd.h -a -z "$GD_INCLUDE" ; then - GD_INCLUDE=/usr/include/gd - fi - - PHP_EXPAND_PATH($GD_INCLUDE, GD_INCLUDE) - PHP_ADD_INCLUDE($GD_INCLUDE) - -fi diff --git a/ext/gd/gd.c b/ext/gd/gd.c deleted file mode 100644 index e5f8aa200e..0000000000 --- a/ext/gd/gd.c +++ /dev/null @@ -1,3622 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2002 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | - | Stig Bakken <ssb@guardian.no> | - | Jim Winstead <jimw@php.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -/* gd 1.2 is copyright 1994, 1995, Quest Protein Database Center, - Cold Spring Harbor Labs. */ - -/* Note that there is no code from the gd package in this file */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "php.h" -#include "ext/standard/head.h" -#include <math.h> -#include "SAPI.h" -#include "php_gd.h" -#include "ext/standard/info.h" - -#if HAVE_SYS_WAIT_H -# include <sys/wait.h> -#endif -#if HAVE_UNISTD_H -# include <unistd.h> -#endif -#ifdef PHP_WIN32 -# include <io.h> -# include <fcntl.h> -#endif - -#if HAVE_LIBGD - -static int le_gd, le_gd_font; -#if HAVE_LIBT1 -static int le_ps_font, le_ps_enc; -#endif - -#include <gd.h> -#include <gdfontt.h> /* 1 Tiny font */ -#include <gdfonts.h> /* 2 Small font */ -#include <gdfontmb.h> /* 3 Medium bold font */ -#include <gdfontl.h> /* 4 Large font */ -#include <gdfontg.h> /* 5 Giant font */ -#ifdef ENABLE_GD_TTF -# include "gdttf.h" -#endif - -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif - -#ifdef ENABLE_GD_TTF -static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int, int); -#endif - -#if HAVE_LIBGD15 -/* it's >= 1.5, i.e. has IOCtx */ -#define USE_GD_IOCTX 1 -#else -#undef USE_GD_IOCTX -#endif - -#ifdef USE_GD_IOCTX -#include "gd_ctx.c" -#else -#define gdImageCreateFromGdCtx NULL -#define gdImageCreateFromGd2Ctx NULL -#define gdImageCreateFromGd2partCtx NULL -#define gdImageCreateFromGifCtx NULL -#define gdImageCreateFromJpegCtx NULL -#define gdImageCreateFromPngCtx NULL -#define gdImageCreateFromWBMPCtx NULL -typedef FILE gdIOCtx; -#define CTX_PUTC(c, fp) fputc(c, fp) -#endif - -static gdImagePtr _php_image_create_from_string (zval **Data, char *tn, gdImagePtr (*ioctx_func_p)() TSRMLS_DC); -static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, gdImagePtr (*func_p)(), gdImagePtr (*ioctx_func_p)()); -static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, void (*func_p)()); -static int _php_image_type ( char data[8] ); -static void _php_image_convert(INTERNAL_FUNCTION_PARAMETERS, int image_type); -static void _php_image_bw_convert(gdImagePtr im_org, gdIOCtx *out, int threshold); - -/* {{{ gd_functions[] - */ -function_entry gd_functions[] = { - PHP_FE(imagearc, NULL) - PHP_FE(imagechar, NULL) - PHP_FE(imagecharup, NULL) - PHP_FE(imagecolorallocate, NULL) - PHP_FE(imagepalettecopy, NULL) - PHP_FE(imagecolorat, NULL) - PHP_FE(imagecolorclosest, NULL) - PHP_FE(imagecolorclosesthwb, NULL) - PHP_FE(imagecolordeallocate, NULL) - PHP_FE(imagecolorresolve, NULL) - PHP_FE(imagecolorexact, NULL) - PHP_FE(imagecolorset, NULL) - PHP_FE(imagecolortransparent, NULL) - PHP_FE(imagecolorstotal, NULL) - PHP_FE(imagecolorsforindex, NULL) - PHP_FE(imagecopy, NULL) - PHP_FE(imagecopymerge, NULL) - PHP_FE(imagecopyresized, NULL) - PHP_FE(imagecreate, NULL) - - PHP_FE(imagecreatetruecolor, NULL) - PHP_FE(imagetruecolortopalette, NULL) - PHP_FE(imagesetthickness, NULL) - PHP_FE(imageellipse, NULL) - PHP_FE(imagefilledellipse, NULL) - PHP_FE(imagefilledarc, NULL) - PHP_FE(imagealphablending, NULL) - PHP_FE(imagecolorresolvealpha, NULL) - PHP_FE(imagecolorclosestalpha, NULL) - PHP_FE(imagecolorexactalpha, NULL) - PHP_FE(imagecopyresampled, NULL) - PHP_FE(imagesettile, NULL) - - PHP_FE(imagesetbrush, NULL) - PHP_FE(imagesetstyle, NULL) - PHP_FE(imagecopymergegray, NULL) - - PHP_FE(imagecreatefromstring, NULL) - PHP_FE(imagecreatefrompng, NULL) - PHP_FE(imagecreatefromgif, NULL) - PHP_FE(imagecreatefromjpeg, NULL) - PHP_FE(imagecreatefromwbmp, NULL) - PHP_FE(imagecreatefromxbm, NULL) - PHP_FE(imagecreatefromxpm, NULL) - PHP_FE(imagecreatefromgd, NULL) - PHP_FE(imagecreatefromgd2, NULL) - PHP_FE(imagecreatefromgd2part, NULL) - - PHP_FE(imagepng, NULL) - PHP_FE(imagegif, NULL) - PHP_FE(imagejpeg, NULL) - PHP_FE(imagewbmp, NULL) - PHP_FE(imagegd, NULL) - PHP_FE(imagegd2, NULL) - - PHP_FE(imagedestroy, NULL) - PHP_FE(imagegammacorrect, NULL) - PHP_FE(imagefill, NULL) - PHP_FE(imagefilledpolygon, NULL) - PHP_FE(imagefilledrectangle, NULL) - PHP_FE(imagefilltoborder, NULL) - PHP_FE(imagefontwidth, NULL) - PHP_FE(imagefontheight, NULL) - PHP_FE(imageinterlace, NULL) - PHP_FE(imageline, NULL) - PHP_FE(imageloadfont, NULL) - PHP_FE(imagepolygon, NULL) - PHP_FE(imagerectangle, NULL) - PHP_FE(imagesetpixel, NULL) - PHP_FE(imagestring, NULL) - PHP_FE(imagestringup, NULL) - PHP_FE(imagesx, NULL) - PHP_FE(imagesy, NULL) - PHP_FE(imagedashedline, NULL) - PHP_FE(imagettfbbox, NULL) - PHP_FE(imagettftext, NULL) - PHP_FE(imageftbbox, NULL) - PHP_FE(imagefttext, NULL) - PHP_FE(imagepsloadfont, NULL) - /* - PHP_FE(imagepscopyfont, NULL) - */ - PHP_FE(imagepsfreefont, NULL) - PHP_FE(imagepsencodefont, NULL) - PHP_FE(imagepsextendfont, NULL) - PHP_FE(imagepsslantfont, NULL) - PHP_FE(imagepstext, NULL) - PHP_FE(imagepsbbox, NULL) - PHP_FE(imagetypes, NULL) - - PHP_FE(jpeg2wbmp, NULL) - PHP_FE(png2wbmp, NULL) - PHP_FE(image2wbmp, NULL) - - {NULL, NULL, NULL} -}; -/* }}} */ - -zend_module_entry gd_module_entry = { - STANDARD_MODULE_HEADER, - "gd", - gd_functions, - PHP_MINIT(gd), - NULL, - NULL, - NULL, - PHP_MINFO(gd), - NO_VERSION_YET, - STANDARD_MODULE_PROPERTIES -}; - -#ifdef COMPILE_DL_GD -ZEND_GET_MODULE(gd) -#endif - -/* {{{ php_free_gd_image - */ -static void php_free_gd_image(zend_rsrc_list_entry *rsrc TSRMLS_DC) -{ - gdImageDestroy((gdImagePtr)rsrc->ptr); -} -/* }}} */ - -/* {{{ php_free_gd_font - */ -static void php_free_gd_font(zend_rsrc_list_entry *rsrc TSRMLS_DC) -{ - gdFontPtr fp = (gdFontPtr)rsrc->ptr; - - if (fp->data) { - efree(fp->data); - } - efree(fp); -} -/* }}} */ - -/* {{{ PHP_MINIT_FUNCTION - */ -PHP_MINIT_FUNCTION(gd) -{ - le_gd = zend_register_list_destructors_ex(php_free_gd_image, NULL, "gd", module_number); - le_gd_font = zend_register_list_destructors_ex(php_free_gd_font, NULL, "gd font", module_number); -#if HAVE_LIBT1 - T1_SetBitmapPad(8); - T1_InitLib(NO_LOGFILE|IGNORE_CONFIGFILE|IGNORE_FONTDATABASE); - T1_SetLogLevel(T1LOG_DEBUG); - le_ps_font = zend_register_list_destructors_ex(php_free_ps_font, NULL, "gd PS font", module_number); - le_ps_enc = zend_register_list_destructors_ex(php_free_ps_enc, NULL, "gd PS encoding", module_number); -#endif - REGISTER_LONG_CONSTANT("IMG_GIF", 1, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("IMG_JPG", 2, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("IMG_JPEG", 2, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("IMG_PNG", 4, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("IMG_WBMP", 8, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("IMG_XPM", 16, CONST_CS | CONST_PERSISTENT); -#ifdef gdTiled - /* special colours for gd */ - REGISTER_LONG_CONSTANT("IMG_COLOR_TILED", gdTiled, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("IMG_COLOR_STYLED", gdStyled, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("IMG_COLOR_BRUSHED", gdBrushed, CONST_CS | CONST_PERSISTENT); - 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 - return SUCCESS; -} -/* }}} */ - -/* {{{ PHP_MINFO_FUNCTION - */ -PHP_MINFO_FUNCTION(gd) -{ - php_info_print_table_start(); - php_info_print_table_row(2, "GD Support", "enabled"); - - /* need to use a PHPAPI function here because it is external module in windows */ - -#if HAVE_LIBGD20 - php_info_print_table_row(2, "GD Version", "2.0 or higher"); -#elif HAVE_GDIMAGECOLORRESOLVE - php_info_print_table_row(2, "GD Version", "1.6.2 or higher"); -#elif HAVE_LIBGD13 - php_info_print_table_row(2, "GD Version", "between 1.3 and 1.6.1"); -#else - php_info_print_table_row(2, "GD Version", "1.2"); -#endif - -#ifdef ENABLE_GD_TTF - php_info_print_table_row(2, "FreeType Support", "enabled"); -#if HAVE_LIBFREETYPE - php_info_print_table_row(2, "FreeType Linkage", "with freetype"); -#elif HAVE_LIBTTF - php_info_print_table_row(2, "FreeType Linkage", "with TTF library"); -#else - php_info_print_table_row(2, "FreeType Linkage", "with unknown library"); -#endif -#endif - -#ifdef HAVE_LIBT1 - php_info_print_table_row(2, "T1Lib Support", "enabled"); -#endif - -/* this next part is stupid ... if I knew better, I'd put them all on one row (cmv) */ - -#ifdef HAVE_GD_GIF_READ - php_info_print_table_row(2, "GIF Read Support", "enabled"); -#endif -#ifdef HAVE_GD_GIF_CREATE - php_info_print_table_row(2, "GIF Create Support", "enabled"); -#endif -#ifdef HAVE_GD_JPG - php_info_print_table_row(2, "JPG Support", "enabled"); -#endif -#ifdef HAVE_GD_PNG - php_info_print_table_row(2, "PNG Support", "enabled"); -#endif -#ifdef HAVE_GD_WBMP - php_info_print_table_row(2, "WBMP Support", "enabled"); -#endif -#ifdef HAVE_GD_XBM - php_info_print_table_row(2, "XBM Support", "enabled"); -#endif - php_info_print_table_end(); -} -/* }}} */ - -/* Need this for cpdf. See also comment in file.c php3i_get_le_fp() */ -PHP_GD_API int phpi_get_le_gd(void) -{ - return le_gd; -} - -#ifndef HAVE_GDIMAGECOLORRESOLVE - -/* {{{ gdImageColorResolve - */ -/********************************************************************/ -/* gdImageColorResolve is a replacement for the old fragment: */ -/* */ -/* if ((color=gdImageColorExact(im,R,G,B)) < 0) */ -/* if ((color=gdImageColorAllocate(im,R,G,B)) < 0) */ -/* color=gdImageColorClosest(im,R,G,B); */ -/* */ -/* in a single function */ - -int -gdImageColorResolve(gdImagePtr im, int r, int g, int b) -{ - int c; - int ct = -1; - int op = -1; - long rd, gd, bd, dist; - long mindist = 3*255*255; /* init to max poss dist */ - - for (c = 0; c < im->colorsTotal; c++) { - if (im->open[c]) { - op = c; /* Save open slot */ - continue; /* Color not in use */ - } - rd = (long)(im->red [c] - r); - gd = (long)(im->green[c] - g); - bd = (long)(im->blue [c] - b); - dist = rd * rd + gd * gd + bd * bd; - if (dist < mindist) { - if (dist == 0) { - return c; /* Return exact match color */ - } - mindist = dist; - ct = c; - } - } - /* no exact match. We now know closest, but first try to allocate exact */ - if (op == -1) { - op = im->colorsTotal; - if (op == gdMaxColors) { /* No room for more colors */ - return ct; /* Return closest available color */ - } - im->colorsTotal++; - } - im->red [op] = r; - im->green[op] = g; - im->blue [op] = b; - im->open [op] = 0; - return op; /* Return newly allocated color */ -} -/* }}} */ - -#endif - -#define FLIPWORD(a) (((a & 0xff000000) >> 24) | ((a & 0x00ff0000) >> 8) | ((a & 0x0000ff00) << 8) | ((a & 0x000000ff) << 24)) - -/* {{{ proto int imageloadfont(string filename) - Load a new font */ -PHP_FUNCTION(imageloadfont) -{ - zval **file; - int hdr_size = sizeof(gdFont) - sizeof(char *); - int ind, body_size, n=0, b, i, body_size_check; - gdFontPtr font; - FILE *fp; - int issock=0, socketd=0; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &file) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } - - convert_to_string_ex(file); - -#ifdef PHP_WIN32 - fp = VCWD_FOPEN(Z_STRVAL_PP(file), "rb"); -#else - fp = php_fopen_wrapper(Z_STRVAL_PP(file), "r", IGNORE_PATH|IGNORE_URL_WIN, &issock, &socketd, NULL TSRMLS_CC); -#endif - if (fp == NULL) { - php_error(E_WARNING, "ImageFontLoad: unable to open file"); - RETURN_FALSE; - } - - /* Only supports a architecture-dependent binary dump format - * at the moment. - * The file format is like this on machines with 32-byte integers: - * - * byte 0-3: (int) number of characters in the font - * byte 4-7: (int) value of first character in the font (often 32, space) - * byte 8-11: (int) pixel width of each character - * byte 12-15: (int) pixel height of each character - * bytes 16-: (char) array with character data, one byte per pixel - * in each character, for a total of - * (nchars*width*height) bytes. - */ - font = (gdFontPtr)emalloc(sizeof(gdFont)); - b = 0; - while (b < hdr_size && (n = fread(&font[b], 1, hdr_size - b, fp))) - b += n; - if (!n) { - fclose(fp); - efree(font); - if (feof(fp)) { - php_error(E_WARNING, "ImageFontLoad: end of file while reading header"); - } else { - php_error(E_WARNING, "ImageFontLoad: error while reading header"); - } - RETURN_FALSE; - } - i = ftell(fp); - fseek(fp, 0, SEEK_END); - body_size_check = ftell(fp) - hdr_size; - fseek(fp, i, SEEK_SET); - body_size = font->w * font->h * font->nchars; - if (body_size != body_size_check) { - font->w = FLIPWORD(font->w); - font->h = FLIPWORD(font->h); - font->nchars = FLIPWORD(font->nchars); - body_size = font->w * font->h * font->nchars; - } - if (body_size != body_size_check) { - php_error(E_WARNING, "ImageFontLoad: error reading font"); - efree(font); - RETURN_FALSE; - } - - font->data = emalloc(body_size); - b = 0; - while (b < body_size && (n = fread(&font->data[b], 1, body_size - b, fp))) - b += n; - if (!n) { - fclose(fp); - efree(font->data); - efree(font); - if (feof(fp)) { - php_error(E_WARNING, "ImageFontLoad: end of file while reading body"); - } else { - php_error(E_WARNING, "ImageFontLoad: error while reading body"); - } - RETURN_FALSE; - } - fclose(fp); - - /* Adding 5 to the font index so we will never have font indices - * that overlap with the old fonts (with indices 1-5). The first - * list index given out is always 1. - */ - ind = 5 + zend_list_insert(font, le_gd_font); - - RETURN_LONG(ind); -} -/* }}} */ - -/* {{{ proto void imagesetstyle(resource im, array styles) - Set the line drawing styles for use with imageline and IMG_COLOR_STYLED. */ -PHP_FUNCTION(imagesetstyle) -{ - 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(); - } - - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); - convert_to_array_ex(styles); - - /* copy the style values in the stylearr */ - stylearr = emalloc(sizeof(int) * zend_hash_num_elements(HASH_OF(*styles))); - - zend_hash_internal_pointer_reset_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) - break; - - convert_to_long_ex(item); - - stylearr[index++] = Z_LVAL_PP(item); - } - gdImageSetStyle(im, stylearr, index); - - efree(stylearr); - - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto int imagecreatetruecolor(int x_size, int y_size) - Create a new true color image */ -PHP_FUNCTION(imagecreatetruecolor) -{ -#if HAVE_LIBGD20 - zval **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(); - } - - convert_to_long_ex(x_size); - convert_to_long_ex(y_size); - - im = gdImageCreateTrueColor(Z_LVAL_PP(x_size), Z_LVAL_PP(y_size)); - - ZEND_REGISTER_RESOURCE(return_value, im, le_gd); -#else - zend_error(E_ERROR, "%s(): requires GD 2.0 or later", get_active_function_name(TSRMLS_C)); -#endif -} -/* }}} */ - -/* {{{ proto void imagetruecolortopalette(resource im, bool ditherFlag, int colorsWanted) - Convert a true colour image to a palette based image with a number of colours, optionally using dithering. */ -PHP_FUNCTION(imagetruecolortopalette) -{ -#if HAVE_LIBGD20 - zval **IM, **dither, **ncolors; - gdImagePtr im; - - if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &IM, &dither, &ncolors) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } - - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); - convert_to_boolean_ex(dither); - convert_to_long_ex(ncolors); - - gdImageTrueColorToPalette(im, Z_LVAL_PP(dither), Z_LVAL_PP(ncolors)); - - RETURN_TRUE; -#else - zend_error(E_ERROR, "%s(): requires GD 2.0 or later", get_active_function_name(TSRMLS_C)); -#endif - -} -/* }}} */ - -/* {{{ proto void imagesetthickness(resource im, int thickness) - Set line thickness for drawing lines, ellipses, rectangles, polygons etc. */ -PHP_FUNCTION(imagesetthickness) -{ -#if HAVE_LIBGD20 - zval **IM, **thick; - gdImagePtr im; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &IM, &thick) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } - - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); - convert_to_long_ex(thick); - - gdImageSetThickness(im, Z_LVAL_PP(thick)); - - RETURN_TRUE; -#else - zend_error(E_ERROR, "%s(): requires GD 2.0 or later", get_active_function_name(TSRMLS_C)); -#endif - -} -/* }}} */ - -/* {{{ proto void imageellipse(resource im, int cx, int cy, int w, int h, int color) - Draw an ellipse */ -PHP_FUNCTION(imageellipse) -{ -#if 0 && HAVE_LIBGD20 /* this function is missing from GD 2.0.1 */ - zval **IM, **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(); - } - - 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); - - gdImageEllipse(im, Z_LVAL_PP(cx), Z_LVAL_PP(cy), Z_LVAL_PP(w), Z_LVAL_PP(h), Z_LVAL_PP(color)); - - RETURN_TRUE; -#else - zend_error(E_ERROR, "%s(): requires GD 2.0 or later", get_active_function_name(TSRMLS_C)); -#endif -} -/* }}} */ - -/* {{{ proto void imagefilledellipse(resource im, int cx, int cy, int w, int h, int color) - Draw an ellipse */ -PHP_FUNCTION(imagefilledellipse) -{ -#if HAVE_LIBGD20 - zval **IM, **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(); - } - - 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); - - gdImageFilledEllipse(im, Z_LVAL_PP(cx), Z_LVAL_PP(cy), Z_LVAL_PP(w), Z_LVAL_PP(h), Z_LVAL_PP(color)); - - RETURN_TRUE; -#else - zend_error(E_ERROR, "%s(): requires GD 2.0 or later", get_active_function_name(TSRMLS_C)); -#endif -} -/* }}} */ - -/* {{{ proto int imagefilledarc(int im, int cx, int cy, int w, int h, int s, int e, int col, int style) - Draw a filled partial ellipse */ -PHP_FUNCTION(imagefilledarc) -{ -#if HAVE_LIBGD20 - zval **IM, **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(); - } - - 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); - - e = Z_LVAL_PP(E); - st = Z_LVAL_PP(ST); - - if (e < 0) e %= 360; - 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)); - RETURN_TRUE; -#else - zend_error(E_ERROR, "%s(): requires GD 2.0 or later", get_active_function_name(TSRMLS_C)); -#endif -} -/* }}} */ - -/* {{{ proto void imagealphablending(resource im, bool on) - Turn alpha blending mode on or off for the given image */ -PHP_FUNCTION(imagealphablending) -{ -#if HAVE_LIBGD20 - zval **IM, **blend; - gdImagePtr im; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &IM, &blend) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } - - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); - convert_to_boolean_ex(blend); - - gdImageAlphaBlending(im, Z_LVAL_PP(blend)); - - RETURN_TRUE; -#else - zend_error(E_ERROR, "%s(): requires GD 2.0 or later", get_active_function_name(TSRMLS_C)); -#endif -} -/* }}} */ - -/* {{{ proto int imagecolorresolvealpha(resource im, int red, int green, int blue, int alpha) - Resolve/Allocate a colour with an alpha level. Works for true colour and palette based images */ -PHP_FUNCTION(imagecolorresolvealpha) -{ -#if HAVE_LIBGD20 - zval **IM, ** 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(); - } - - 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); - - RETURN_LONG(gdImageColorResolveAlpha(im, Z_LVAL_PP(red), Z_LVAL_PP(green), Z_LVAL_PP(blue), Z_LVAL_PP(alpha))); -#else - zend_error(E_ERROR, "%s(): requires GD 2.0 or later", get_active_function_name(TSRMLS_C)); -#endif - -} -/* }}} */ - -/* {{{ proto int imagecolorclosestalpha(resource im, int red, int green, int blue, int alpha) - Find the closest matching colour with alpha transparency */ -PHP_FUNCTION(imagecolorclosestalpha) -{ -#if HAVE_LIBGD20 - zval **IM, ** 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(); - } - - 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); - - RETURN_LONG(gdImageColorClosestAlpha(im, Z_LVAL_PP(red), Z_LVAL_PP(green), Z_LVAL_PP(blue), Z_LVAL_PP(alpha))); -#else - zend_error(E_ERROR, "%s(): requires GD 2.0 or later", get_active_function_name(TSRMLS_C)); -#endif -} -/* }}} */ - -/* {{{ proto int imagecolorexactalpha(resource im, int red, int green, int blue, int alpha) - Find exact match for colour with transparency */ -PHP_FUNCTION(imagecolorexactalpha) -{ -#if HAVE_LIBGD20 - zval **IM, **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(); - } - - 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); - - RETURN_LONG(gdImageColorExactAlpha(im, Z_LVAL_PP(red), Z_LVAL_PP(green), Z_LVAL_PP(blue), Z_LVAL_PP(alpha))); -#else - zend_error(E_ERROR, "%s(): requires GD 2.0 or later", get_active_function_name(TSRMLS_C)); -#endif -} -/* }}} */ - -/* {{{ proto int imagecopyresampled(int dst_im, int src_im, int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h) - Copy and resize part of an image using resampling to help ensure clarity */ -PHP_FUNCTION(imagecopyresampled) -{ -#if HAVE_LIBGD20 - zval **SIM, **DIM, **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(); - } - - 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); - - 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); - - gdImageCopyResampled(im_dst, im_src, dstX, dstY, srcX, srcY, dstW, dstH, srcW, srcH); - RETURN_TRUE; -#else - zend_error(E_ERROR, "%s(): requires GD 2.0 or later", get_active_function_name(TSRMLS_C)); -#endif -} -/* }}} */ - -/* {{{ proto int imagesettile(resource image, resource tile) - Set the tile image to $tile when filling $image with the "IMG_COLOR_TILED" color */ -PHP_FUNCTION(imagesettile) -{ -#if HAVE_GD_IMAGESETTILE - zval **IM, **TILE; - gdImagePtr im, tile; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &IM, &TILE) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } - - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); - ZEND_FETCH_RESOURCE(tile, gdImagePtr, TILE, -1, "Image", le_gd); - - gdImageSetTile(im, tile); - - RETURN_TRUE; -#else - zend_error(E_ERROR, "%s(): requires a more recent version of GD", get_active_function_name(TSRMLS_C)); -#endif -} -/* }}} */ - -/* {{{ proto int imagesetbrush(resource image, resource brush) - Set the brush image to $brush when filling $image with the "IMG_COLOR_BRUSHED" color */ -PHP_FUNCTION(imagesetbrush) -{ -#if HAVE_GD_IMAGESETBRUSH - zval **IM, **TILE; - gdImagePtr im, tile; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &IM, &TILE) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } - - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); - ZEND_FETCH_RESOURCE(tile, gdImagePtr, TILE, -1, "Image", le_gd); - - gdImageSetBrush(im, tile); - - RETURN_TRUE; -#else - zend_error(E_ERROR, "%s(): requires a more recent version of GD", get_active_function_name(TSRMLS_C)); -#endif -} -/* }}} */ - -/* {{{ proto int imagecreate(int x_size, int y_size) - Create a new image */ -PHP_FUNCTION(imagecreate) -{ - zval **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(); - } - - convert_to_long_ex(x_size); - convert_to_long_ex(y_size); - - im = gdImageCreate(Z_LVAL_PP(x_size), Z_LVAL_PP(y_size)); - - ZEND_REGISTER_RESOURCE(return_value, im, le_gd); -} -/* }}} */ - -/* {{{ proto int imagetypes(void) - Return the types of images supported in a bitfield - 1=GIF, 2=JPEG, 4=PNG, 8=WBMP, 16=XPM */ -PHP_FUNCTION(imagetypes) -{ - int ret=0; -#ifdef HAVE_GD_GIF_CREATE - ret = 1; -#endif -#ifdef HAVE_GD_JPG - ret |= 2; -#endif -#ifdef HAVE_GD_PNG - ret |= 4; -#endif -#ifdef HAVE_GD_WBMP - ret |= 8; -#endif -#ifdef HAVE_GD_XPM - ret |= 16; -#endif - if (ZEND_NUM_ARGS() != 0) { - WRONG_PARAM_COUNT; - } - - RETURN_LONG(ret); -} -/* }}} */ - -/* {{{ _php_image_type - */ -static const char php_sig_gd2[3] = {'g', 'd', '2'}; - -static int _php_image_type (char data[8]) -{ -#ifdef HAVE_LIBGD15 - /* Based on ext/standard/images.c */ - - if (data == NULL) - return -1; - - if (!memcmp(data, php_sig_gd2, 3)) - return PHP_GDIMG_TYPE_GD2; - else if (!memcmp(data, php_sig_jpg, 3)) - return PHP_GDIMG_TYPE_JPG; - else if (!memcmp(data, php_sig_png, 3)) { - if (!memcmp(data, php_sig_png, 8)) - return PHP_GDIMG_TYPE_PNG; - } - else if (!memcmp(data, php_sig_gif, 3)) - return PHP_GDIMG_TYPE_GIF; -#ifdef HAVE_GD_WMBP - else { - gdIOCtx *io_ctx; - io_ctx = gdNewDynamicCtx (8, data); - if (io_ctx) { - if (getmbi(gdGetC, io_ctx) == 0 && skipheader(gdGetC, io_ctx) == 0 ) { - io_ctx->free(io_ctx); - return PHP_GDIMG_TYPE_WBM; - } else - io_ctx->free(io_ctx); - } - } -#endif - return -1; -#endif -} -/* }}} */ - -/* {{{ _php_image_create_from_string - */ -gdImagePtr _php_image_create_from_string(zval **data, char *tn, gdImagePtr (*ioctx_func_p)() TSRMLS_DC) -{ -#ifdef HAVE_LIBGD15 - gdImagePtr im; - gdIOCtx *io_ctx; - - io_ctx = gdNewDynamicCtx (Z_STRLEN_PP(data), Z_STRVAL_PP(data)); - - if(!io_ctx) { - return NULL; - } - - im = (*ioctx_func_p)(io_ctx); - if (!im) { - php_error(E_WARNING, "%s: Passed data is not in '%s' format", get_active_function_name(TSRMLS_C), tn); - return NULL; - } - - return im; -#else - return NULL; -#endif -} -/* }}} */ - -/* {{{ proto int imagecreatefromstring(string image) - Create a new image from the image stream in the string */ -PHP_FUNCTION(imagecreatefromstring) -{ -#ifdef HAVE_LIBGD15 - zval **data; - gdImagePtr im; - int imtype; - char sig[8]; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &data) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } - - convert_to_string_ex(data); - memcpy(sig, Z_STRVAL_PP(data), 8); - - imtype = _php_image_type (sig); - - switch (imtype) { - case PHP_GDIMG_TYPE_JPG: -#ifdef HAVE_GD_JPG - im = _php_image_create_from_string (data, "JPEG", gdImageCreateFromJpegCtx TSRMLS_CC); -#else - php_error(E_WARNING, "No JPEG support in this PHP build"); - RETURN_FALSE; -#endif - break; - - case PHP_GDIMG_TYPE_PNG: -#ifdef HAVE_GD_PNG - im = _php_image_create_from_string (data, "PNG", gdImageCreateFromPngCtx TSRMLS_CC); -#else - php_error(E_WARNING, "No PNG support in this PHP build"); - RETURN_FALSE; -#endif - break; - - case PHP_GDIMG_TYPE_GIF: -#ifdef HAVE_GD_GIF_READ - im = _php_image_create_from_string (data, "GIF", gdImageCreateFromGifCtx TSRMLS_CC); -#else - php_error(E_WARNING, "No GIF support in this PHP build"); - RETURN_FALSE; -#endif - break; - - case PHP_GDIMG_TYPE_WBM: -#ifdef HAVE_GD_WBMP - im = _php_image_create_from_string (data, "WBMP", gdImageCreateFromWBMPCtx TSRMLS_CC); -#else - php_error(E_WARNING, "No WBMP support in this PHP build"); - RETURN_FALSE; -#endif - break; - - case PHP_GDIMG_TYPE_GD2: -#ifdef HAVE_GD_GD2 - im = _php_image_create_from_string (data, "GD2", gdImageCreateFromGd2Ctx TSRMLS_CC); -#else - php_error(E_WARNING, "No GD2 support in this PHP build"); - RETURN_FALSE; -#endif - break; - - default: - php_error(E_WARNING, "Data is not in a recognized format."); - RETURN_FALSE; - - } - if (!im) { - php_error(E_WARNING, "Couldn't create GD Image Stream out of Data"); - RETURN_FALSE; - } - - ZEND_REGISTER_RESOURCE(return_value, im, le_gd); -#else - php_error(E_ERROR, "ImageCreateFromString: Only available with GD 1.5+"); -#endif -} -/* }}} */ - -size_t php_fread_all(char **buf, int socket, FILE *fp, int issock); - -/* {{{ _php_image_create_from - */ -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; - gdImagePtr im; - char *fn=NULL; - FILE *fp; - int issock=0, socketd=0; - int argc=ZEND_NUM_ARGS(); - - if ((image_type == PHP_GDIMG_TYPE_GD2PART && argc != 4) || - argc != 1 || zend_get_parameters_ex(argc, &file, &srcx, &srcy, &width, &height) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } - - convert_to_string_ex(file); - - if (argc == 4 && image_type == PHP_GDIMG_TYPE_GD2PART) { - multi_convert_to_long_ex(4, srcx, srcy, width, height); - } - - fn = Z_STRVAL_PP(file); - -#ifdef PHP_WIN32 - fp = VCWD_FOPEN(fn, "rb"); -#else - fp = php_fopen_wrapper(fn, "r", IGNORE_PATH|IGNORE_URL_WIN, &issock, &socketd, NULL TSRMLS_CC); -#endif - if (!fp && !socketd) { - php_strip_url_passwd(fn); - php_error(E_WARNING, "%s: Unable to open '%s' for reading", get_active_function_name(TSRMLS_C), fn); - RETURN_FALSE; - } - -#ifndef USE_GD_IOCTX - ioctx_func_p = NULL; /* don't allow sockets without IOCtx */ -#endif - - if(issock && !ioctx_func_p) { - php_error(E_WARNING, "%s: Sockets are not supported for image type '%s'", get_active_function_name(TSRMLS_C), tn); - RETURN_FALSE; - } - - if(issock && socketd) { -#ifdef USE_GD_IOCTX - gdIOCtx* io_ctx; - size_t buff_size; - char *buff, *buff_em; - - buff_size = php_fread_all(&buff_em, socketd, fp, issock); - - if(!buff_size) { - php_error(E_WARNING,"%s: Cannot read image data", get_active_function_name(TSRMLS_C)); - RETURN_FALSE; - } - - buff = malloc(buff_size); /* Should be malloc! GD uses free */ - memcpy(buff, buff_em, buff_size); - efree(buff_em); - - io_ctx = gdNewDynamicCtx(buff_size, buff); - if(!io_ctx) { - php_error(E_WARNING,"%s: Cannot allocate GD IO context", get_active_function_name(TSRMLS_C)); - RETURN_FALSE; - } - 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)); - } else { - im = (*ioctx_func_p)(io_ctx); - } - io_ctx->free(io_ctx); -#endif - } else { - if (image_type == PHP_GDIMG_TYPE_GD2PART) { - im = (*func_p)(fp, Z_LVAL_PP(srcx), Z_LVAL_PP(srcy), Z_LVAL_PP(width), Z_LVAL_PP(height)); - } else { - im = (*func_p)(fp); - } - - fflush(fp); - fclose(fp); - } - - if (!im) { - php_error(E_WARNING,"%s: '%s' is not a valid %s file", get_active_function_name(TSRMLS_C), fn, tn); - RETURN_FALSE; - } - - ZEND_REGISTER_RESOURCE(return_value, im, le_gd); -} -/* }}} */ - -/* {{{ proto int imagecreatefromgif(string filename) - Create a new image from GIF file or URL */ -PHP_FUNCTION(imagecreatefromgif) -{ -#ifdef HAVE_GD_GIF_READ - _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_GIF, "GIF", gdImageCreateFromGif, gdImageCreateFromGifCtx); -#else /* HAVE_GD_GIF_READ */ - php_error(E_WARNING, "ImageCreateFromGif: No GIF read support in this PHP build"); - RETURN_FALSE; -#endif /* HAVE_GD_GIF_READ */ -} -/* }}} */ - -/* {{{ proto int imagecreatefromjpeg(string filename) - Create a new image from JPEG file or URL */ -PHP_FUNCTION(imagecreatefromjpeg) -{ -#ifdef HAVE_GD_JPG - _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_JPG, "JPEG", gdImageCreateFromJpeg, gdImageCreateFromJpegCtx); -#else /* HAVE_GD_JPG */ - php_error(E_WARNING, "ImageCreateFromJpeg: No JPEG support in this PHP build"); - RETURN_FALSE; -#endif /* HAVE_GD_JPG */ -} -/* }}} */ - -/* {{{ proto int imagecreatefrompng(string filename) - Create a new image from PNG file or URL */ -PHP_FUNCTION(imagecreatefrompng) -{ -#ifdef HAVE_GD_PNG - _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_PNG, "PNG", gdImageCreateFromPng, gdImageCreateFromPngCtx); -#else /* HAVE_GD_PNG */ - php_error(E_WARNING, "ImageCreateFromPng: No PNG support in this PHP build"); - RETURN_FALSE; -#endif /* HAVE_GD_PNG */ -} -/* }}} */ - -/* {{{ proto int imagecreatefromxbm(string filename) - Create a new image from XBM file or URL */ -PHP_FUNCTION(imagecreatefromxbm) -{ -#ifdef HAVE_GD_XBM - _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_XBM, "XBM", gdImageCreateFromXbm, NULL); -#else /* HAVE_GD_XBM */ - php_error(E_WARNING, "ImageCreateFromXbm: No XBM support in this PHP build"); - RETURN_FALSE; -#endif /* HAVE_GD_XBM */ -} -/* }}} */ - -/* {{{ proto int imagecreatefromxpm(string filename) - Create a new image from XPM file or URL */ -PHP_FUNCTION(imagecreatefromxpm) -{ - /* -#ifdef HAVE_GD_XPM - _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_XPM, "XPM", gdImageCreateFromXpm, NULL); -#else - */ - php_error(E_WARNING, "ImageCreateFromXpm: No XPM support in this PHP build"); - RETURN_FALSE; - /* -#endif - */ -} -/* }}} */ - -/* {{{ proto int imagecreatefromwbmp(string filename) - Create a new image from WBMP file or URL */ -PHP_FUNCTION(imagecreatefromwbmp) -{ -#ifdef HAVE_GD_WBMP - _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_WBM, "WBMP", gdImageCreateFromWBMP, gdImageCreateFromWBMPCtx); -#else /* HAVE_GD_WBMP */ - php_error(E_WARNING, "ImageCreateFromWBMP: No WBMP support in this PHP build"); - RETURN_FALSE; -#endif /* HAVE_GD_WBMP */ -} -/* }}} */ - -/* {{{ proto int imagecreatefromgd(string filename) - Create a new image from GD file or URL */ -PHP_FUNCTION(imagecreatefromgd) -{ - _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_GD, "GD", gdImageCreateFromGd, gdImageCreateFromGdCtx); -} -/* }}} */ - -/* {{{ proto int imagecreatefromgd2(string filename) - Create a new image from GD2 file or URL */ -PHP_FUNCTION(imagecreatefromgd2) -{ -#ifdef HAVE_GD_GD2 - _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_GD2, "GD2", gdImageCreateFromGd2, gdImageCreateFromGd2Ctx); -#else /* HAVE_GD_GD2 */ - php_error(E_WARNING, "ImageCreateFromGd2: No GD2 support in this PHP build"); - RETURN_FALSE; -#endif /* HAVE_GD_GD2 */ -} -/* }}} */ - -/* {{{ proto int imagecreatefromgd2part(string filename, int srcX, int srcY, int width, int height) - Create a new image from a given part of GD2 file or URL */ -PHP_FUNCTION(imagecreatefromgd2part) -{ -#ifdef HAVE_GD_GD2 - _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_GD2PART, "GD2", gdImageCreateFromGd2Part, gdImageCreateFromGd2PartCtx); -#else /* HAVE_GD_GD2 */ - php_error(E_WARNING, "ImageCreateFromGd2Part: No GD2 support in this PHP build"); - RETURN_FALSE; -#endif /* HAVE_GD_GD2 */ -} -/* }}} */ - -/* {{{ _php_image_output - */ -static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, void (*func_p)()) -{ - zval **imgind, **file, **quality; - gdImagePtr im; - char *fn = NULL; - FILE *fp; - int argc = ZEND_NUM_ARGS(); - int q = -1, i; - - /* 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. */ - - if (argc < 1 || argc > 3 || zend_get_parameters_ex(argc, &imgind, &file, &quality) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } - - ZEND_FETCH_RESOURCE(im, gdImagePtr, imgind, -1, "Image", le_gd); - - if (argc > 1) { - convert_to_string_ex(file); - fn = Z_STRVAL_PP(file); - if (argc == 3) { - convert_to_long_ex(quality); - q = Z_LVAL_PP(quality); - } - } - - if ((argc == 2) || (argc == 3 && Z_STRLEN_PP(file))) { - if (!fn || fn == empty_string || php_check_open_basedir(fn TSRMLS_CC)) { - php_error(E_WARNING, "%s: invalid filename '%s'", get_active_function_name(TSRMLS_C), fn); - RETURN_FALSE; - } - - fp = VCWD_FOPEN(fn, "wb"); - if (!fp) { - php_error(E_WARNING, "%s: unable to open '%s' for writing", get_active_function_name(TSRMLS_C), fn); - RETURN_FALSE; - } - - switch(image_type) { - case PHP_GDIMG_CONVERT_WBM: - if(q<0||q>255) { - php_error(E_WARNING, "%s: invalid threshold value '%d'. It must be between 0 and 255", get_active_function_name(TSRMLS_C), q); - } - case PHP_GDIMG_TYPE_JPG: - (*func_p)(im, fp, q); - break; - case PHP_GDIMG_TYPE_WBM: - for(i=0; i < gdImageColorsTotal(im); i++) { - if(gdImageRed(im, i) == 0) break; - } - (*func_p)(im, i, fp); - break; - default: - (*func_p)(im, fp); - break; - } - fflush(fp); - fclose(fp); - } else { - int b; - FILE *tmp; - char buf[4096]; - - tmp = tmpfile(); - if (tmp == NULL) { - php_error(E_WARNING, "%s: unable to open temporary file", get_active_function_name(TSRMLS_C)); - RETURN_FALSE; - } - - switch(image_type) { - case PHP_GDIMG_CONVERT_WBM: - if(q<0||q>255) { - php_error(E_WARNING, "%s: invalid threshold value '%d'. It must be between 0 and 255", get_active_function_name(TSRMLS_C), q); - } - case PHP_GDIMG_TYPE_JPG: - (*func_p)(im, tmp, q); - break; - case PHP_GDIMG_TYPE_WBM: - for(i=0; i < gdImageColorsTotal(im); i++) { - if(gdImageRed(im, i) == 0) break; - } - (*func_p)(im, q, tmp); - break; - default: - (*func_p)(im, tmp); - break; - } - - fseek(tmp, 0, SEEK_SET); - -#if APACHE && defined(CHARSET_EBCDIC) - /* XXX this is unlikely to work any more thies@thieso.net */ - - /* This is a binary file already: avoid EBCDIC->ASCII conversion */ - ap_bsetflag(php3_rqst->connection->client, B_EBCDIC2ASCII, 0); -#endif - while ((b = fread(buf, 1, sizeof(buf), tmp)) > 0) { - php_write(buf, b TSRMLS_CC); - } - - fclose(tmp); - /* the temporary file is automatically deleted */ - } - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto int imagegif(int im [, string filename]) - Output GIF image to browser or file */ -PHP_FUNCTION(imagegif) -{ -#ifdef HAVE_GD_GIF_CREATE -#ifdef HAVE_GD_GIF_CTX - _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_GIF, "GIF", gdImageGifCtx); -#else - _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_GIF, "GIF", gdImageGif); -#endif -#else /* HAVE_GD_GIF_CREATE */ - php_error(E_WARNING, "ImageGif: No GIF create support in this PHP build"); - RETURN_FALSE; -#endif /* HAVE_GD_GIF_CREATE */ -} -/* }}} */ - -/* {{{ proto int imagepng(int im [, string filename]) - Output PNG image to browser or file */ -PHP_FUNCTION(imagepng) -{ -#ifdef HAVE_GD_PNG -#ifdef USE_GD_IOCTX - _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_PNG, "PNG", gdImagePngCtx); -#else - _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_PNG, "PNG", gdImagePng); -#endif -#else /* HAVE_GD_PNG */ - php_error(E_WARNING, "ImagePng: No PNG support in this PHP build"); - RETURN_FALSE; -#endif /* HAVE_GD_PNG */ -} -/* }}} */ - -/* {{{ proto int imagejpeg(int im [, string filename [, int quality]]) - Output JPEG image to browser or file */ -PHP_FUNCTION(imagejpeg) -{ -#ifdef HAVE_GD_JPG -#ifdef USE_GD_IOCTX - _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_JPG, "JPEG", gdImageJpegCtx); -#else - _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_JPG, "JPEG", gdImageJpeg); -#endif -#else /* HAVE_GD_JPG */ - php_error(E_WARNING, "ImageJpeg: No JPG support in this PHP build"); - RETURN_FALSE; -#endif /* HAVE_GD_JPG */ -} -/* }}} */ - -/* {{{ proto int imagewbmp(int im [, string filename, [, int foreground]]) - Output WBMP image to browser or file */ -PHP_FUNCTION(imagewbmp) -{ -#ifdef HAVE_GD_WBMP -#ifdef USE_GD_IOCTX - _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_WBM, "WBMP", gdImageWBMPCtx); -#else - _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_WBM, "WBMP", gdImageWBMP); -#endif -#else /* HAVE_GD_WBMP */ - php_error(E_WARNING, "ImageWBMP: No WBMP support in this PHP build"); - RETURN_FALSE; -#endif /* HAVE_GD_WBMP */ -} -/* }}} */ - -/* {{{ proto int imagegd(int im [, string filename]) - Output GD image to browser or file */ -PHP_FUNCTION(imagegd) -{ - _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_GD, "GD", gdImageGd); -} -/* }}} */ - -/* {{{ proto int imagegd2(int im [, string filename]) - Output GD2 image to browser or file */ -PHP_FUNCTION(imagegd2) -{ -#ifdef HAVE_GD_GD2 - _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_GD2, "GD2", gdImageGd2); -#else /* HAVE_GD_GD2 */ - php_error(E_WARNING, "ImageGd2: No GD2 support in this PHP build"); - RETURN_FALSE; -#endif /* HAVE_GD_GD2 */ -} -/* }}} */ - -/* {{{ proto int imagedestroy(int im) - Destroy an image */ -PHP_FUNCTION(imagedestroy) -{ - zval **IM; - gdImagePtr im; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &IM) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } - - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); - - zend_list_delete(Z_LVAL_PP(IM)); - - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto int imagecolorallocate(int im, int red, int green, int blue) - Allocate a color for an image */ -PHP_FUNCTION(imagecolorallocate) -{ - zval **IM, **red, **green, **blue; - gdImagePtr im; - - if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &IM, &red, &green, &blue) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } - - 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); - - RETURN_LONG(gdImageColorAllocate(im, Z_LVAL_PP(red), Z_LVAL_PP(green), Z_LVAL_PP(blue))); -} -/* }}} */ - -/* {{{ proto int imagepalettecopy(int dst, int src) - Copy the palette from the src image onto the dst image */ -PHP_FUNCTION(imagepalettecopy) -{ -#if HAVE_LIBGD15 - zval **dstim, **srcim; - gdImagePtr dst, src; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &dstim, &srcim) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } - - ZEND_FETCH_RESOURCE(dst, gdImagePtr, dstim, -1, "Image", le_gd); - ZEND_FETCH_RESOURCE(src, gdImagePtr, srcim, -1, "Image", le_gd); - - gdImagePaletteCopy(dst, src); -#else - php_error(E_WARNING, "Sorry ImagePaletteCopy was introduced in GD version 1.5"); - RETURN_FALSE; -#endif -} -/* }}} */ - -/* {{{ proto int imagecolorat(int im, int x, int y) - Get the index of the color of a pixel */ -PHP_FUNCTION(imagecolorat) -{ - zval **IM, **x, **y; - gdImagePtr im; - - if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &IM, &x, &y) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } - - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); - - convert_to_long_ex(x); - convert_to_long_ex(y); - -#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))); - } else { - php_error(E_NOTICE, "%ld,%ld is out of bounds",Z_LVAL_PP(x), Z_LVAL_PP(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 - } else { - php_error(E_NOTICE, "%ld,%ld is out of bounds",Z_LVAL_PP(x), Z_LVAL_PP(y)); - RETURN_FALSE; - } -#if HAVE_LIBGD20 - } -#endif -} -/* }}} */ - -/* {{{ proto int imagecolorclosest(int im, int red, int green, int blue) - Get the index of the closest color to the specified color */ -PHP_FUNCTION(imagecolorclosest) -{ - zval **IM, **red, **green, **blue; - gdImagePtr im; - - if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &IM, &red, &green, &blue) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } - - 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); - - RETURN_LONG(gdImageColorClosest(im, Z_LVAL_PP(red), Z_LVAL_PP(green), Z_LVAL_PP(blue))); -} -/* }}} */ - -/* {{{ proto int imagecolorclosesthwb(int im, int red, int green, int blue) - Get the index of the color which has the hue, white and blackness nearest to the given color */ -PHP_FUNCTION(imagecolorclosesthwb) -{ -#if HAVE_COLORCLOSESTHWB - zval **IM, **red, **green, **blue; - gdImagePtr im; - - if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &IM, &red, &green, &blue) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } - - 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); - - RETURN_LONG(gdImageColorClosestHWB(im, Z_LVAL_PP(red), Z_LVAL_PP(green), Z_LVAL_PP(blue))); -#else - php_error(E_WARNING, "ImageColorClosestHWB functionality was added in GD 1.8"); - RETURN_FALSE; -#endif -} -/* }}} */ - -/* {{{ proto int imagecolordeallocate(int im, int index) - De-allocate a color for an image */ -PHP_FUNCTION(imagecolordeallocate) -{ - zval **IM, **index; - int col; - gdImagePtr im; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &IM, &index) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } - - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); - - convert_to_long_ex(index); - col = Z_LVAL_PP(index); - - if (col >= 0 && col < gdImageColorsTotal(im)) { - gdImageColorDeallocate(im, col); - RETURN_TRUE; - } else { - php_error(E_WARNING, "Color index out of range"); - RETURN_FALSE; - } -} -/* }}} */ - -/* {{{ proto int imagecolorresolve(int im, int red, int green, int blue) - Get the index of the specified color or its closest possible alternative */ -PHP_FUNCTION(imagecolorresolve) -{ - zval **IM, **red, **green, **blue; - gdImagePtr im; - - if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &IM, &red, &green, &blue) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } - - 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); - - RETURN_LONG(gdImageColorResolve(im, Z_LVAL_PP(red), Z_LVAL_PP(green), Z_LVAL_PP(blue))); -} -/* }}} */ - -/* {{{ proto int imagecolorexact(int im, int red, int green, int blue) - Get the index of the specified color */ -PHP_FUNCTION(imagecolorexact) -{ - zval **IM, **red, **green, **blue; - gdImagePtr im; - - if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &IM, &red, &green, &blue) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } - - 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); - - RETURN_LONG(gdImageColorExact(im, Z_LVAL_PP(red), Z_LVAL_PP(green), Z_LVAL_PP(blue))); -} -/* }}} */ - -/* {{{ proto int imagecolorset(int im, int col, int red, int green, int blue) - Set the color for the specified palette index */ -PHP_FUNCTION(imagecolorset) -{ - zval **IM, **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(); - } - - 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); - - col = Z_LVAL_PP(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); - } else { - RETURN_FALSE; - } -} -/* }}} */ - -/* {{{ proto array imagecolorsforindex(int im, int col) - Get the colors for an index */ -PHP_FUNCTION(imagecolorsforindex) -{ - zval **IM, **index; - int col; - gdImagePtr im; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &IM, &index) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } - - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); - - 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))) { - if (array_init(return_value) == FAILURE) { - RETURN_FALSE; - } - add_assoc_long(return_value,"red", gdImageRed(im,col)); - 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)) { - if (array_init(return_value) == FAILURE) { - RETURN_FALSE; - } - 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 { - php_error(E_WARNING, "Color index out of range"); - RETURN_FALSE; - } -} -/* }}} */ - -/* {{{ proto int imagegammacorrect(int im, float inputgamma, float outputgamma) - Apply a gamma correction to a GD image */ -PHP_FUNCTION(imagegammacorrect) -{ - zval **IM, **inputgamma, **outputgamma; - 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(); - } - - 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); - -#if HAVE_LIBGD20 - if (gdImageTrueColor(im)) { - int x, y, c; - - for (y = 0; y < gdImageSY(im); y++) { - for (x = 0; x < gdImageSX(im); x++) { - c = gdImageGetPixel(im, x, y); - gdImageSetPixel(im, x, y, - gdTrueColor( - (int)((pow((pow((gdTrueColorGetRed(c) / 255.0), input)), 1.0 / output) * 255)+.5), - (int)((pow((pow((gdTrueColorGetGreen(c) / 255.0), input)), 1.0 / output) * 255)+.5), - (int)((pow((pow((gdTrueColorGetBlue(c) / 255.0), input)), 1.0 / output) * 255)+.5) - ) - ); - } - } - 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); - im->blue[i] = (int)((pow((pow((im->blue[i] / 255.0), input)), 1.0 / output) * 255)+.5); - } - - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto int imagesetpixel(int im, int x, int y, int col) - Set a single pixel */ -PHP_FUNCTION(imagesetpixel) -{ - zval **IM, **x, **y, **col; - gdImagePtr im; - - if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &IM, &x, &y, &col) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } - - 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); - - gdImageSetPixel(im, Z_LVAL_PP(x), Z_LVAL_PP(y), Z_LVAL_PP(col)); - - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto int imageline(int im, int x1, int y1, int x2, int y2, int col) - Draw a line */ -PHP_FUNCTION(imageline) -{ - zval **IM, **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(); - } - - 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); - - gdImageLine(im, Z_LVAL_PP(x1), Z_LVAL_PP(y1), Z_LVAL_PP(x2), Z_LVAL_PP(y2), Z_LVAL_PP(col)); - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto int imagedashedline(int im, int x1, int y1, int x2, int y2, int col) - Draw a dashed line */ -PHP_FUNCTION(imagedashedline) -{ - zval **IM, **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(); - } - - 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); - - gdImageDashedLine(im, Z_LVAL_PP(x1), Z_LVAL_PP(y1), Z_LVAL_PP(x2), Z_LVAL_PP(y2), Z_LVAL_PP(col)); - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto int imagerectangle(int im, int x1, int y1, int x2, int y2, int col) - Draw a rectangle */ -PHP_FUNCTION(imagerectangle) -{ - zval **IM, **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(); - } - - 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); - - gdImageRectangle(im, Z_LVAL_PP(x1), Z_LVAL_PP(y1), Z_LVAL_PP(x2), Z_LVAL_PP(y2), Z_LVAL_PP(col)); - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto int imagefilledrectangle(int im, int x1, int y1, int x2, int y2, int col) - Draw a filled rectangle */ -PHP_FUNCTION(imagefilledrectangle) -{ - zval **IM, **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(); - } - - 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); - - gdImageFilledRectangle(im, Z_LVAL_PP(x1), Z_LVAL_PP(y1), Z_LVAL_PP(x2), Z_LVAL_PP(y2), Z_LVAL_PP(col)); - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto int imagearc(int im, int cx, int cy, int w, int h, int s, int e, int col) - Draw a partial ellipse */ -PHP_FUNCTION(imagearc) -{ - zval **IM, **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(); - } - - 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); - - e = Z_LVAL_PP(E); - st = Z_LVAL_PP(ST); - - if (e < 0) e %= 360; - 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)); - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto int imagefilltoborder(int im, int x, int y, int border, int col) - Flood fill to specific color */ -PHP_FUNCTION(imagefilltoborder) -{ - zval **IM, **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(); - } - - 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); - - gdImageFillToBorder(im, Z_LVAL_PP(x), Z_LVAL_PP(y), Z_LVAL_PP(border), Z_LVAL_PP(col)); - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto int imagefill(int im, int x, int y, int col) - Flood fill */ -PHP_FUNCTION(imagefill) -{ - zval **IM, **x, **y, **col; - gdImagePtr im; - - if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &IM, &x, &y, &col) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } - - 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); - - gdImageFill(im, Z_LVAL_PP(x), Z_LVAL_PP(y), Z_LVAL_PP(col)); - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto int imagecolorstotal(int im) - Find out the number of colors in an image's palette */ -PHP_FUNCTION(imagecolorstotal) -{ - zval **IM; - gdImagePtr im; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &IM) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } - - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); - - RETURN_LONG(gdImageColorsTotal(im)); -} -/* }}} */ - -/* {{{ proto int imagecolortransparent(int im [, int col]) - Define a color as transparent */ -PHP_FUNCTION(imagecolortransparent) -{ - zval **IM, **COL; - 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, &COL) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } - convert_to_long_ex(COL); - break; - default: - ZEND_WRONG_PARAM_COUNT(); - } - - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); - - if (ZEND_NUM_ARGS() > 1) { - gdImageColorTransparent(im, Z_LVAL_PP(COL)); - } - - RETURN_LONG(gdImageGetTransparent(im)); -} -/* }}} */ - -/* {{{ proto int imageinterlace(int im [, int interlace]) - Enable or disable interlace */ -PHP_FUNCTION(imageinterlace) -{ - zval **IM, **INT; - 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(); - } - - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); - - if (ZEND_NUM_ARGS() > 1) { - gdImageInterlace(im, Z_LVAL_PP(INT)); - } - - RETURN_LONG(gdImageGetInterlaced(im)); -} -/* }}} */ - -/* {{{ php_imagepolygon - arg = 0 normal polygon - arg = 1 filled polygon */ -/* im, points, num_points, col */ -static void php_imagepolygon(INTERNAL_FUNCTION_PARAMETERS, int filled) -{ - zval **IM, **POINTS, **NPOINTS, **COL; - pval **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(); - } - - 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); - - if (Z_TYPE_PP(POINTS) != IS_ARRAY) { - php_error(E_WARNING, "2nd argument to imagepolygon not an array"); - RETURN_FALSE; - } - - nelem = zend_hash_num_elements(Z_ARRVAL_PP(POINTS)); - if (nelem < 6) { - php_error(E_WARNING, "you must have at least 3 points in your array"); - RETURN_FALSE; - } - - if (nelem < npoints * 2) { - php_error(E_WARNING, "trying to use %d points in array with only %d points", npoints, nelem/2); - RETURN_FALSE; - } - - points = (gdPointPtr) emalloc(npoints * sizeof(gdPoint)); - - for (i = 0; i < npoints; i++) { - if (zend_hash_index_find(Z_ARRVAL_PP(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) { - SEPARATE_ZVAL(var); - convert_to_long(*var); - points[i].y = Z_LVAL_PP(var); - } - } - - if (filled) { - gdImageFilledPolygon(im, points, npoints, col); - } else { - gdImagePolygon(im, points, npoints, col); - } - - efree(points); - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto int imagepolygon(int im, array point, int num_points, int col) - Draw a polygon */ -PHP_FUNCTION(imagepolygon) -{ - php_imagepolygon(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); -} -/* }}} */ - -/* {{{ proto int imagefilledpolygon(int im, array point, int num_points, int col) - Draw a filled polygon */ -PHP_FUNCTION(imagefilledpolygon) -{ - php_imagepolygon(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); -} -/* }}} */ - -/* {{{ php_find_gd_font - */ -static gdFontPtr php_find_gd_font(int size) -{ - gdFontPtr font; - int ind_type; - TSRMLS_FETCH(); - - switch (size) { - case 1: - font = gdFontTiny; - break; - case 2: - font = gdFontSmall; - break; - case 3: - font = gdFontMediumBold; - break; - case 4: - font = gdFontLarge; - break; - case 5: - font = gdFontGiant; - break; - default: - font = zend_list_find(size - 5, &ind_type); - if (!font || ind_type != le_gd_font) { - if (size < 1) { - font = gdFontTiny; - } else { - font = gdFontGiant; - } - } - break; - } - - return font; -} -/* }}} */ - -/* {{{ php_imagefontsize - * arg = 0 ImageFontWidth - * arg = 1 ImageFontHeight - */ -static void php_imagefontsize(INTERNAL_FUNCTION_PARAMETERS, int arg) -{ - zval **SIZE; - gdFontPtr font; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &SIZE) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } - - convert_to_long_ex(SIZE); - - font = php_find_gd_font(Z_LVAL_PP(SIZE)); - RETURN_LONG(arg ? font->h : font->w); -} -/* }}} */ - -/* {{{ proto int imagefontwidth(int font) - Get font width */ -PHP_FUNCTION(imagefontwidth) -{ - php_imagefontsize(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); -} -/* }}} */ - -/* {{{ proto int imagefontheight(int font) - Get font height */ -PHP_FUNCTION(imagefontheight) -{ - php_imagefontsize(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); -} -/* }}} */ - -/* {{{ php_gdimagecharup - * workaround for a bug in gd 1.2 */ -static void php_gdimagecharup(gdImagePtr im, gdFontPtr f, int x, int y, int c, int color) -{ - int cx, cy, px, py, fline; - cx = 0; - cy = 0; - if ((c < f->offset) || (c >= (f->offset + f->nchars))) { - return; - } - fline = (c - f->offset) * f->h * f->w; - for (py = y; (py > (y - f->w)); py--) { - for (px = x; (px < (x + f->h)); px++) { - if (f->data[fline + cy * f->w + cx]) { - gdImageSetPixel(im, px, py, color); - } - cy++; - } - cy = 0; - cx++; - } -} -/* }}} */ - -/* {{{ php_imagechar - * arg = 0 ImageChar - * arg = 1 ImageCharUp - * arg = 2 ImageString - * arg = 3 ImageStringUp - */ -static void php_imagechar(INTERNAL_FUNCTION_PARAMETERS, int mode) -{ - zval **IM, **SIZE, **X, **Y, **C, **COL; - 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(); - } - - 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); - - col = Z_LVAL_PP(COL); - - if (mode < 2) { - ch = (int)((unsigned char)*(Z_STRVAL_PP(C))); - } else { - str = (unsigned char *) estrndup(Z_STRVAL_PP(C), Z_STRLEN_PP(C)); - l = strlen(str); - } - - y = Z_LVAL_PP(Y); - x = Z_LVAL_PP(X); - size = Z_LVAL_PP(SIZE); - - font = php_find_gd_font(size); - - switch(mode) { - case 0: - gdImageChar(im, font, x, y, ch, col); - break; - case 1: - php_gdimagecharup(im, font, x, y, ch, col); - break; - case 2: - for (i = 0; (i < l); i++) { - gdImageChar(im, font, x, y, (int)((unsigned char)str[i]), - col); - x += font->w; - } - break; - case 3: { - for (i = 0; (i < l); i++) { - /* php_gdimagecharup(im, font, x, y, (int)str[i], col); */ - gdImageCharUp(im, font, x, y, (int)str[i], col); - y -= font->w; - } - break; - } - } - if (str) { - efree(str); - } - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto int imagechar(int im, int font, int x, int y, string c, int col) - Draw a character */ -PHP_FUNCTION(imagechar) -{ - php_imagechar(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); -} -/* }}} */ - -/* {{{ proto int imagecharup(int im, int font, int x, int y, string c, int col) - Draw a character rotated 90 degrees counter-clockwise */ -PHP_FUNCTION(imagecharup) -{ - php_imagechar(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); -} -/* }}} */ - -/* {{{ proto int imagestring(int im, int font, int x, int y, string str, int col) - Draw a string horizontally */ -PHP_FUNCTION(imagestring) -{ - php_imagechar(INTERNAL_FUNCTION_PARAM_PASSTHRU, 2); -} -/* }}} */ - -/* {{{ proto int imagestringup(int im, int font, int x, int y, string str, int col) - Draw a string vertically - rotated 90 degrees counter-clockwise */ -PHP_FUNCTION(imagestringup) -{ - php_imagechar(INTERNAL_FUNCTION_PARAM_PASSTHRU, 3); -} -/* }}} */ - -/* {{{ proto int imagecopy(int dst_im, int src_im, int dst_x, int dst_y, int src_x, int src_y, int src_w, int src_h) - Copy part of an image */ -PHP_FUNCTION(imagecopy) -{ - zval **SIM, **DIM, **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(); - } - - 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); - - 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); - - gdImageCopy(im_dst, im_src, dstX, dstY, srcX, srcY, srcW, srcH); - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto int imagecopymerge(int src_im, int dst_im, int dst_x, int dst_y, int src_x, int src_y, int src_w, int src_h, int pct) - Merge one part of an image with another */ -PHP_FUNCTION(imagecopymerge) -{ -#if HAVE_LIBGD15 - zval **SIM, **DIM, **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(); - } - - 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); - - 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); - - gdImageCopyMerge(im_dst, im_src, dstX, dstY, srcX, srcY, srcW, srcH, pct); - RETURN_TRUE; -#else - php_error(E_WARNING, "ImageCopyMerge was introduced in GD version 1.5"); - RETURN_FALSE; -#endif -} -/* }}} */ - -/* {{{ proto int imagecopymergegray(int src_im, int dst_im, int dst_x, int dst_y, int src_x, int src_y, int src_w, int src_h, int pct) - Merge one part of an image with another */ -PHP_FUNCTION(imagecopymergegray) -{ -#if HAVE_LIBGD15 - zval **SIM, **DIM, **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(); - } - - 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); - - 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); - - gdImageCopyMergeGray(im_dst, im_src, dstX, dstY, srcX, srcY, srcW, srcH, pct); - RETURN_TRUE; -#else - php_error(E_WARNING, "%s(): was introduced in GD version 1.5", get_active_function_name(TSRMLS_C)); - RETURN_FALSE; -#endif -} -/* }}} */ - -/* {{{ proto int imagecopyresized(int dst_im, int src_im, int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h) - Copy and resize part of an image */ -PHP_FUNCTION(imagecopyresized) -{ - zval **SIM, **DIM, **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(); - } - - 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); - - 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); - - gdImageCopyResized(im_dst, im_src, dstX, dstY, srcX, srcY, dstW, dstH, srcW, srcH); - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto int imagesx(int im) - Get image width */ -PHP_FUNCTION(imagesx) -{ - zval **IM; - gdImagePtr im; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &IM) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } - - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); - - RETURN_LONG(gdImageSX(im)); -} -/* }}} */ - -/* {{{ proto int imagesy(int im) - Get image height */ -PHP_FUNCTION(imagesy) -{ - zval **IM; - gdImagePtr im; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &IM) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } - - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); - - RETURN_LONG(gdImageSY(im)); -} -/* }}} */ - -#ifdef ENABLE_GD_TTF -#define TTFTEXT_DRAW 0 -#define TTFTEXT_BBOX 1 -#endif - - -/* {{{ proto array imageftbbox(int size, int angle, string font_file, string text[, array extrainfo]) - Give the bounding box of a text using fonts via freetype2 */ -PHP_FUNCTION(imageftbbox) -{ -#if HAVE_LIBGD20 && HAVE_LIBFREETYPE && HAVE_GD_STRINGFTEX - php_imagettftext_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, TTFTEXT_BBOX, 1); -#else - php_error(E_WARNING, "%s(): No FreeType 2 support in this PHP build", get_active_function_name(TSRMLS_C)); - RETURN_FALSE; -#endif -} -/* }}} */ - -/* {{{ proto array imagefttext(int im, int size, int angle, int x, int y, int col, string font_file, string text, [array extrainfo]) - Write text to the image using fonts via freetype2 */ -PHP_FUNCTION(imagefttext) -{ -#if HAVE_LIBGD20 && HAVE_LIBFREETYPE && HAVE_GD_STRINGFTEX - php_imagettftext_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, TTFTEXT_DRAW, 1); -#else - php_error(E_WARNING, "%s(): No FreeType 2 support in this PHP build", get_active_function_name(TSRMLS_C)); - RETURN_FALSE; -#endif -} -/* }}} */ - - -/* {{{ proto array imagettfbbox(int size, int angle, string font_file, string text) - Give the bounding box of a text using TrueType fonts */ -PHP_FUNCTION(imagettfbbox) -{ -#ifdef ENABLE_GD_TTF - php_imagettftext_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, TTFTEXT_BBOX, 0); -#else - php_error(E_WARNING, "ImageTtfBBox: No TTF support in this PHP build"); - RETURN_FALSE; -#endif -} -/* }}} */ - -/* {{{ proto array imagettftext(int im, int size, int angle, int x, int y, int col, string font_file, string text) - Write text to the image using a TrueType font */ -PHP_FUNCTION(imagettftext) -{ -#ifdef ENABLE_GD_TTF - php_imagettftext_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, TTFTEXT_DRAW, 0); -#else - php_error(E_WARNING, "ImageTtfText: No TTF support in this PHP build"); - RETURN_FALSE; -#endif -} -/* }}} */ - -#ifdef ENABLE_GD_TTF -/* {{{ php_imagettftext_common - */ -static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int mode, int extended) -{ - zval **IM, **PTSIZE, **ANGLE, **X, **Y, **C, **FONTNAME, **COL, **EXT = NULL; - gdImagePtr im=NULL; - int col, x, y, l=0, i, brect[8]; - double ptsize, angle; - unsigned char *str = NULL, *fontname = NULL; - char *error; - int argc; -#if HAVE_GD_STRINGFTEX - gdFTStringExtra strex; -#endif - -#if !HAVE_GD_STRINGFTEX - if (extended) { - zend_error(E_ERROR, "%s(): gdImageStringFTEx not supported in this PHP build", get_active_function_name(TSRMLS_C)); - RETURN_FALSE; - } -#endif - - argc = ZEND_NUM_ARGS(); - - if (mode == TTFTEXT_BBOX) { - if ((extended && argc != 5) || (!extended && argc != 4) || - zend_get_parameters_ex(argc, &PTSIZE, &ANGLE, &FONTNAME, &C, &EXT) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } - } else { - if ((extended && argc != 9) || (!extended && argc != 8) || - zend_get_parameters_ex(argc, &IM, &PTSIZE, &ANGLE, &X, &Y, &COL, &FONTNAME, &C, &EXT) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } - ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd); - } - - convert_to_double_ex(PTSIZE); - convert_to_double_ex(ANGLE); - convert_to_string_ex(FONTNAME); - convert_to_string_ex(C); - - if (mode == TTFTEXT_BBOX) { - im = NULL; - col = x = y = -1; - } else { - convert_to_long_ex(X); - convert_to_long_ex(Y); - convert_to_long_ex(COL); - col = Z_LVAL_PP(COL); - y = Z_LVAL_PP(Y); - x = Z_LVAL_PP(X); - -#if HAVE_GD_STRINGFTEX - if (EXT) { - /* parse extended info */ - - HashPosition pos; - - convert_to_array_ex(EXT); - memset(&strex, 0, sizeof(strex)); - - /* walk the assoc array */ - zend_hash_internal_pointer_reset_ex(HASH_OF(*EXT), &pos); - do { - zval ** item; - char * key; - - if (zend_hash_get_current_key_ex(HASH_OF(*EXT), &key, NULL, NULL, 0, &pos) == FAILURE) - continue; - - if (zend_hash_get_current_data_ex(HASH_OF(*EXT), (void**)&item, &pos) == FAILURE) - continue; - - if (strcmp("linespacing", key) == 0) { - convert_to_double_ex(item); - strex.flags |= gdFTEX_LINESPACE; - strex.linespacing = Z_DVAL_PP(item); - } - - } while(zend_hash_move_forward_ex(HASH_OF(*EXT), &pos) == SUCCESS); - } -#endif - - } - - ptsize = Z_DVAL_PP(PTSIZE); - angle = Z_DVAL_PP(ANGLE) * (M_PI/180); /* convert to radians */ - - str = (unsigned char *) Z_STRVAL_PP(C); - l = strlen(str); - -#ifdef VIRTUAL_DIR - if(virtual_filepath(Z_STRVAL_PP(FONTNAME), &fontname TSRMLS_CC)) { - fontname = (unsigned char*)Z_STRVAL_PP(FONTNAME); - } -#else - fontname = (unsigned char*)Z_STRVAL_PP(FONTNAME); -#endif - - -#ifdef USE_GD_IMGSTRTTF -# if HAVE_GD_STRINGFTEX - if (extended) { - error = gdImageStringFTEx(im, brect, col, fontname, ptsize, angle, x, y, str, &strex); - } - else -# endif - -# if HAVE_GD_STRINGFT - error = gdImageStringFT(im, brect, col, fontname, ptsize, angle, x, y, str); -# elif HAVE_GD_STRINGTTF - 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) { - php_error(E_WARNING, "%s", error); - RETURN_FALSE; - } - - if (array_init(return_value) == FAILURE) { - RETURN_FALSE; - } - - /* return array with the text's bounding box */ - for (i = 0; i < 8; i++) { - add_next_index_long(return_value, brect[i]); - } -} -/* }}} */ -#endif /* ENABLE_GD_TTF */ - -#if HAVE_LIBT1 - -/* {{{ php_free_ps_font - */ -void php_free_ps_font(zend_rsrc_list_entry *rsrc TSRMLS_DC) -{ - int *font = (int *)rsrc->ptr; - - T1_DeleteFont(*font); - efree(font); -} -/* }}} */ - -/* {{{ php_free_ps_enc - */ -void php_free_ps_enc(zend_rsrc_list_entry *rsrc TSRMLS_DC) -{ - char **enc = (char **)rsrc->ptr; - - T1_DeleteEncoding(enc); -} -/* }}} */ - -#endif - -/* {{{ proto int imagepsloadfont(string pathname) - Load a new font from specified file */ -PHP_FUNCTION(imagepsloadfont) -{ -#if HAVE_LIBT1 - zval **file; - int f_ind, *font; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &file) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } - - convert_to_string_ex(file); - - f_ind = T1_AddFont(Z_STRVAL_PP(file)); - - if (f_ind < 0) { - switch (f_ind) { - case -1: - php_error(E_WARNING, "Couldn't find the font file"); - RETURN_FALSE; - break; - case -2: - case -3: - php_error(E_WARNING, "Memory allocation fault in t1lib"); - RETURN_FALSE; - break; - default: - php_error(E_WARNING, "An unknown error occurred in t1lib"); - RETURN_FALSE; - break; - } - } - - if (T1_LoadFont(f_ind)) { - php_error(E_WARNING, "Couldn't load the font"); - RETURN_FALSE; - } - - font = (int *) emalloc(sizeof(int)); - *font = f_ind; - ZEND_REGISTER_RESOURCE(return_value, font, le_ps_font); -#else - php_error(E_WARNING, "ImagePsLoadFont: No T1lib support in this PHP build"); - RETURN_FALSE; -#endif -} -/* }}} */ - -/* {{{ proto int imagepscopyfont(int font_index) - Make a copy of a font for purposes like extending or reenconding */ -/* The function in t1lib which this function uses seem to be buggy... -PHP_FUNCTION(imagepscopyfont) -{ -#if HAVE_LIBT1 - zval **fnt; - int l_ind, type; - gd_ps_font *nf_ind, *of_ind; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &fnt) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } - - convert_to_long_ex(fnt); - - of_ind = zend_list_find(Z_LVAL_PP(fnt), &type); - - if (type != le_ps_font) { - php_error(E_WARNING, "%d is not a Type 1 font index", Z_LVAL_PP(fnt)); - RETURN_FALSE; - } - - nf_ind = emalloc(sizeof(gd_ps_font)); - nf_ind->font_id = T1_CopyFont(of_ind->font_id); - - if (nf_ind->font_id < 0) { - l_ind = nf_ind->font_id; - efree(nf_ind); - switch (l_ind) { - case -1: - php_error(E_WARNING, "FontID %d is not loaded in memory", l_ind); - RETURN_FALSE; - break; - case -2: - php_error(E_WARNING, "Tried to copy a logical font"); - RETURN_FALSE; - break; - case -3: - php_error(E_WARNING, "Memory allocation fault in t1lib"); - RETURN_FALSE; - break; - default: - php_error(E_WARNING, "An unknown error occurred in t1lib"); - RETURN_FALSE; - break; - } - } - - nf_ind->extend = 1; - l_ind = zend_list_insert(nf_ind, le_ps_font); - RETURN_LONG(l_ind); -#else - php_error(E_WARNING, "ImagePsCopyFont: No T1lib support in this PHP build"); - RETURN_FALSE; -#endif -} -*/ -/* }}} */ - -/* {{{ proto bool imagepsfreefont(int font_index) - Free memory used by a font */ -PHP_FUNCTION(imagepsfreefont) -{ -#if HAVE_LIBT1 - zval **fnt; - int *f_ind; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &fnt) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } - - ZEND_FETCH_RESOURCE(f_ind, int *, fnt, -1, "Type 1 font", le_ps_font); - - zend_list_delete(Z_LVAL_PP(fnt)); - RETURN_TRUE; -#else - php_error(E_WARNING, "ImagePsFreeFont: No T1lib support in this PHP build"); - RETURN_FALSE; -#endif -} -/* }}} */ - -/* {{{ proto bool imagepsencodefont(int font_index, string filename) - To change a fonts character encoding vector */ -PHP_FUNCTION(imagepsencodefont) -{ -#if HAVE_LIBT1 - zval **fnt, **enc; - char **enc_vector; - int *f_ind; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &fnt, &enc) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } - - convert_to_string_ex(enc); - - 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(E_WARNING, "Couldn't load encoding vector from %s", Z_STRVAL_PP(enc)); - RETURN_FALSE; - } - - T1_DeleteAllSizes(*f_ind); - if (T1_ReencodeFont(*f_ind, enc_vector)) { - T1_DeleteEncoding(enc_vector); - php_error(E_WARNING, "Couldn't reencode font"); - RETURN_FALSE; - } - zend_list_insert(enc_vector, le_ps_enc); - RETURN_TRUE; -#else - php_error(E_WARNING, "ImagePsEncodeFont: No T1lib support in this PHP build"); - RETURN_FALSE; -#endif -} -/* }}} */ - -/* {{{ proto bool imagepsextendfont(int font_index, float extend) - Extend or or condense (if extend < 1) a font */ -PHP_FUNCTION(imagepsextendfont) -{ -#if HAVE_LIBT1 - zval **fnt, **ext; - int *f_ind; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &fnt, &ext) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } - - convert_to_double_ex(ext); - - ZEND_FETCH_RESOURCE(f_ind, int *, fnt, -1, "Type 1 font", le_ps_font); - - if (T1_ExtendFont(*f_ind, Z_DVAL_PP(ext)) != 0) RETURN_FALSE; - - RETURN_TRUE; -#else - php_error(E_WARNING, "ImagePsExtendFont: No T1lib support in this PHP build"); - RETURN_FALSE; -#endif -} -/* }}} */ - -/* {{{ proto bool imagepsslantfont(int font_index, float slant) - Slant a font */ -PHP_FUNCTION(imagepsslantfont) -{ -#if HAVE_LIBT1 - zval **fnt, **slt; - int *f_ind; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &fnt, &slt) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } - - convert_to_double_ex(slt); - - ZEND_FETCH_RESOURCE(f_ind, int *, fnt, -1, "Type 1 font", le_ps_font); - - if (T1_SlantFont(*f_ind, Z_DVAL_PP(slt)) != 0) RETURN_FALSE; - RETURN_TRUE; -#else - php_error(E_WARNING, "ImagePsSlantFont: No T1lib support in this PHP build"); - RETURN_FALSE; -#endif -} -/* }}} */ - -/* {{{ proto array imagepstext(int image, string text, int font, int size, int xcoord, int ycoord [, int space, int tightness, float angle, int antialias]) - Rasterize a string over an image */ -PHP_FUNCTION(imagepstext) -{ -#if HAVE_LIBT1 - zval **img, **str, **fnt, **sz, **fg, **bg, **sp, **px, **py, **aas, **wd, **ang; - int i, j, x, y; - int space; - 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, _fg, _bg; - int aa[16], aa_steps; - int width, amount_kern, add_width; - double angle, extend; - unsigned long aa_greys[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; - gdImagePtr bg_img; - GLYPH *str_img; - T1_OUTLINE *char_path, *str_path; - T1_TMATRIX *transform = NULL; - char *_str; - - switch(ZEND_NUM_ARGS()) { - case 8: - if (zend_get_parameters_ex(8, &img, &str, &fnt, &sz, &fg, &bg, &px, &py) == FAILURE) { - RETURN_FALSE; - } - space = 0; - aa_steps = 4; - width = 0; - angle = 0; - break; - case 12: - if (zend_get_parameters_ex(12, &img, &str, &fnt, &sz, &fg, &bg, &px, &py, &sp, &wd, &ang, &aas) == FAILURE) { - RETURN_FALSE; - } - convert_to_long_ex(sp); - convert_to_long_ex(aas); - convert_to_long_ex(wd); - convert_to_double_ex(ang); - space = Z_LVAL_PP(sp); - aa_steps = Z_LVAL_PP(aas); - width = Z_LVAL_PP(wd); - angle = Z_DVAL_PP(ang); - break; - default: - ZEND_WRONG_PARAM_COUNT(); - } - - ZEND_FETCH_RESOURCE(bg_img, gdImagePtr, img, -1, "Image", le_gd); - ZEND_FETCH_RESOURCE(f_ind, int *, fnt, -1, "Type 1 font", le_ps_font); - - x = Z_LVAL_PP(px); - y = Z_LVAL_PP(py); - _fg = Z_LVAL_PP(fg); - _bg = Z_LVAL_PP(bg); - - fg_rd = gdImageRed (bg_img, _fg); - fg_gr = gdImageGreen(bg_img, _fg); - fg_bl = gdImageBlue (bg_img, _fg); - - bg_rd = gdImageRed (bg_img, _bg); - bg_gr = gdImageGreen(bg_img, _bg); - bg_bl = gdImageBlue (bg_img, _bg); - - 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); - aa[i] = gdImageColorResolve(bg_img, rd, gr, bl); - } - - T1_AASetBitsPerPixel(8); - - switch (aa_steps) { - case 4: - T1_AASetGrayValues(0, 1, 2, 3, 4); - T1_AASetLevel(T1_AA_LOW); - break; - case 16: - T1_AAHSetGrayValues(aa_greys); - T1_AASetLevel(T1_AA_HIGH); - break; - default: - php_error(E_WARNING, "Invalid value %d as number of steps for antialiasing", aa_steps); - RETURN_FALSE; - } - - if (angle) { - transform = T1_RotateMatrix(NULL, angle); - } - - _str = Z_STRVAL_PP(str); - - if (width) { - extend = T1_GetExtend(*f_ind); - str_path = T1_GetCharOutline(*f_ind, _str[0], Z_LVAL_PP(sz), transform); - - for (i = 1; i < Z_STRLEN_PP(str); i++) { - amount_kern = (int) T1_GetKerning(*f_ind, _str[i-1], _str[i]); - amount_kern += _str[i-1] == ' ' ? space : 0; - add_width = (int) (amount_kern+width)/extend; - - char_path = T1_GetMoveOutline(*f_ind, add_width, 0, 0, Z_LVAL_PP(sz), transform); - str_path = T1_ConcatOutlines(str_path, char_path); - - char_path = T1_GetCharOutline(*f_ind, _str[i], Z_LVAL_PP(sz), transform); - str_path = T1_ConcatOutlines(str_path, char_path); - } - str_img = T1_AAFillOutline(str_path, 0); - } else { - str_img = T1_AASetString(*f_ind, _str, Z_STRLEN_PP(str), space, T1_KERNING, Z_LVAL_PP(sz), transform); - } - - if (T1_errno) { - php_error(E_WARNING, "libt1 returned error %d", T1_errno); - RETURN_FALSE; - } - - h_lines = str_img->metrics.ascent - str_img->metrics.descent; - v_lines = str_img->metrics.rightSideBearing - str_img->metrics.leftSideBearing; - - for (i = 0; i < v_lines; i++) { - for (j = 0; j < h_lines; j++) { - switch (str_img->bits[j*v_lines+i]) { - case 0: - break; - default: - c_ind = aa[str_img->bits[j*v_lines+i]-1]; - gdImageSetPixel(bg_img, x+str_img->metrics.leftSideBearing+i, y-str_img->metrics.ascent+j, c_ind); - } - } - } - - if (array_init(return_value) == FAILURE) { - php_error(E_WARNING, "Couldn't initialize array for returning bounding box"); - RETURN_FALSE; - } - - add_next_index_long(return_value, str_img->metrics.leftSideBearing); - add_next_index_long(return_value, str_img->metrics.descent); - add_next_index_long(return_value, str_img->metrics.rightSideBearing); - add_next_index_long(return_value, str_img->metrics.ascent); - -#else - php_error(E_WARNING, "ImagePsText: No T1lib support in this PHP build"); - RETURN_FALSE; -#endif -} -/* }}} */ - -/* {{{ proto array imagepsbbox(string text, int font, int size [, int space, int tightness, int angle]) - Return the bounding box needed by a string if rasterized */ -PHP_FUNCTION(imagepsbbox) -{ -#if HAVE_LIBT1 - zval **str, **fnt, **sz, **sp, **wd, **ang; - int i, space, 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; - 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(); - } - - ZEND_FETCH_RESOURCE(f_ind, int *, fnt, -1, "Type 1 font", le_ps_font); - - convert_to_string_ex(str); - convert_to_long_ex(sz); - -#define max(a, b) (a > b ? a : b) -#define min(a, b) (a < b ? a : b) -#define new_x(a, b) (int) ((a) * cos_a - (b) * sin_a) -#define new_y(a, b) (int) ((a) * sin_a + (b) * cos_a) - - if (per_char) { - 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] == ' ') { - 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]); - } - amount_kern = i ? T1_GetKerning(*f_ind, Z_STRVAL_PP(str)[i-1], Z_STRVAL_PP(str)[i]) : 0; - - /* Transfer character bounding box to right place */ - x1 = new_x(char_bbox.llx, char_bbox.lly) + cur_x; - y1 = new_y(char_bbox.llx, char_bbox.lly) + cur_y; - x2 = new_x(char_bbox.llx, char_bbox.ury) + cur_x; - y2 = new_y(char_bbox.llx, char_bbox.ury) + cur_y; - x3 = new_x(char_bbox.urx, char_bbox.ury) + cur_x; - y3 = new_y(char_bbox.urx, char_bbox.ury) + cur_y; - x4 = new_x(char_bbox.urx, char_bbox.lly) + cur_x; - y4 = new_y(char_bbox.urx, char_bbox.lly) + cur_y; - - /* Find min & max values and compare them with current bounding box */ - str_bbox.llx = min(str_bbox.llx, min(x1, min(x2, min(x3, x4)))); - str_bbox.lly = min(str_bbox.lly, min(y1, min(y2, min(y3, y4)))); - str_bbox.urx = max(str_bbox.urx, max(x1, max(x2, max(x3, x4)))); - str_bbox.ury = max(str_bbox.ury, max(y1, max(y2, max(y3, y4)))); - - /* Move to the next base point */ - dx = new_x(char_width + add_width + amount_kern, 0); - dy = new_y(char_width + add_width + amount_kern, 0); - cur_x += dx; - cur_y += dy; - /* - printf("%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n", x1, y1, x2, y2, x3, y3, x4, y4, char_bbox.llx, char_bbox.lly, char_bbox.urx, char_bbox.ury, char_width, amount_kern, cur_x, cur_y, dx, dy); - */ - } - - } else { - str_bbox = T1_GetStringBBox(*f_ind, Z_STRVAL_PP(str), Z_STRLEN_PP(str), space, T1_KERNING); - } - if (T1_errno) RETURN_FALSE; - - if (array_init(return_value) == FAILURE) { - RETURN_FALSE; - } - /* - 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)); -#else - php_error(E_WARNING, "ImagePsBBox: No T1lib support in this PHP build"); - RETURN_FALSE; -#endif -} -/* }}} */ - -/* {{{ proto int image2wbmp(int im [, string filename [, int threshold]]) - Output WBMP image to browser or file */ -PHP_FUNCTION(image2wbmp) -{ -#ifdef HAVE_GD_WBMP - _php_image_output (INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_CONVERT_WBM, "WBMP", _php_image_bw_convert); -#else /* HAVE_GD_WBMP */ - php_error(E_WARNING, "Image2Wbmp: No WBMP support in this PHP build"); - RETURN_FALSE; -#endif /* HAVE_GD_WBMP */ -} -/* }}} */ - -/* {{{ proto void jpeg2wbmp (string f_org, string f_dest, int d_height, int d_width, int threshold) - Convert JPEG image to WBMP image */ -PHP_FUNCTION(jpeg2wbmp) -{ -#ifdef HAVE_GD_JPG -#ifdef HAVE_GD_WBMP - _php_image_convert (INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_JPG); -#else /* HAVE_GD_WBMP */ - php_error(E_WARNING, "jpeg2wbmp: No WBMP support in this PHP build"); - RETURN_FALSE; -#endif /* HAVE_GD_WBMP */ -#else /* HAVE_GD_JPG */ - php_error(E_WARNING, "jpeg2wbmp: No JPG support in this PHP build"); - RETURN_FALSE; -#endif /* HAVE_GD_JPG */ -} -/* }}} */ - -/* {{{ proto void png2wbmp (string f_org, string f_dest, int d_height, int d_width, int threshold) - Convert PNG image to WBMP image */ -PHP_FUNCTION(png2wbmp) -{ -#ifdef HAVE_GD_PNG -#ifdef HAVE_GD_WBMP - _php_image_convert (INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_PNG); -#else /* HAVE_GD_WBMP */ - php_error(E_WARNING, "png2wbmp: No WBMP support in this PHP build"); - RETURN_FALSE; -#endif /* HAVE_GD_WBMP */ -#else /* HAVE_GD_PNG */ - php_error(E_WARNING, "png2wbmp: No PNG support in this PHP build"); - RETURN_FALSE; -#endif /* HAVE_GD_PNG */ -} -/* }}} */ - -#ifdef HAVE_GD_WBMP -/* {{{ _php_image_bw_convert - * It converts a gd Image to bw using a threshold value */ -static void _php_image_bw_convert( gdImagePtr im_org, gdIOCtx *out, int threshold) -{ - gdImagePtr im_dest; - int white, black; - int color, color_org, median; - int dest_height = gdImageSY (im_org); - int dest_width = gdImageSX (im_org); - int x, y; - TSRMLS_FETCH(); - - im_dest = gdImageCreate (dest_width, dest_height); - if (im_dest == NULL) { - php_error (E_WARNING, "%s: unable to allocate temporary buffer", get_active_function_name(TSRMLS_C)); - return; - } - white = gdImageColorAllocate (im_dest, 255, 255, 255); - if( white == -1) { - php_error (E_WARNING, "%s: unable to allocate the colors for the destination buffer", get_active_function_name(TSRMLS_C)); - return; - } - - black = gdImageColorAllocate (im_dest, 0, 0, 0); - if (black == -1) { - php_error (E_WARNING, "%s: unable to allocate the colors for the destination buffer", get_active_function_name(TSRMLS_C)); - return; - } - - for (y = 0; y < dest_height; y++) { - for (x = 0; x < dest_width; x++) { - color_org = gdImageGetPixel (im_org, x, y); - median = (im_org->red[color_org] + im_org->green[color_org] + im_org->blue[color_org]) / 3; - if (median < threshold) { - color = black; - } - else { - color = white; - } - gdImageSetPixel (im_dest, x, y, color); - } - } -#ifdef USE_GD_IOCTX - gdImageWBMPCtx (im_dest, black, out); -#else - gdImageWBMP (im_dest, black, out); -#endif - -} -/* }}} */ - -/* {{{ _php_image_convert - * _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; - gdImagePtr im_org, im_dest, im_tmp; - char *fn_org = NULL; - char *fn_dest = NULL; - FILE *org, *dest; - int argc; - int dest_height = -1; - int dest_width = -1; - int org_height, org_width; - int white, black; - int color, color_org, median; - int int_threshold; - int x, y; - float x_ratio, y_ratio; - - argc = ZEND_NUM_ARGS(); - if (argc != 5 || zend_get_parameters_ex(argc, &f_org, &f_dest, &height, &width, &threshold) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } - - convert_to_string_ex (f_org); - convert_to_string_ex (f_dest); - fn_org = Z_STRVAL_PP(f_org); - fn_dest = Z_STRVAL_PP(f_dest); - convert_to_long_ex(height); - dest_height = Z_LVAL_PP(height); - convert_to_long_ex(width); - dest_width = Z_LVAL_PP(width); - convert_to_long_ex(threshold); - int_threshold = Z_LVAL_PP(threshold); - - /* Check threshold value */ - if( int_threshold < 0 || int_threshold > 8 ) { - php_error (E_WARNING, "Invalid threshold value '%d' in %s", int_threshold, get_active_function_name(TSRMLS_C)); - RETURN_FALSE; - } - - /* Check origin file */ - if (!fn_org || fn_org == empty_string || php_check_open_basedir(fn_org TSRMLS_CC)) { - php_error (E_WARNING, "%s: invalid origin filename '%s'", get_active_function_name(TSRMLS_C), fn_org); - RETURN_FALSE; - } - - /* Check destination file */ - if (!fn_dest || fn_dest == empty_string || php_check_open_basedir(fn_dest TSRMLS_CC)) { - php_error (E_WARNING, "%s: invalid destination filename '%s'", get_active_function_name(TSRMLS_C), fn_dest); - RETURN_FALSE; - } - - /* Open origin file */ - org = VCWD_FOPEN(fn_org, "rb"); - if (!org) { - php_error (E_WARNING, "%s: unable to open '%s' for reading", get_active_function_name(TSRMLS_C), fn_org); - RETURN_FALSE; - } - - /* Open destination file */ - dest = VCWD_FOPEN(fn_dest, "wb"); - if (!dest) { - php_error (E_WARNING, "%s: unable to open '%s' for writing", get_active_function_name(TSRMLS_C), fn_dest); - RETURN_FALSE; - } - - switch (image_type) { -#ifdef HAVE_GD_GIF_READ - case PHP_GDIMG_TYPE_GIF: - im_org = gdImageCreateFromGif (org); - if (im_org == NULL) { - php_error (E_WARNING, "%s: unable to open '%s' Not a valid GIF file", get_active_function_name(TSRMLS_C), fn_dest); - RETURN_FALSE; - } - break; -#endif /* HAVE_GD_GIF_READ */ - -#ifdef HAVE_GD_JPG - case PHP_GDIMG_TYPE_JPG: - im_org = gdImageCreateFromJpeg (org); - if (im_org == NULL) { - php_error (E_WARNING, "%s: unable to open '%s' Not a valid JPEG file", get_active_function_name(TSRMLS_C), fn_dest); - RETURN_FALSE; - } - break; -#endif /* HAVE_GD_JPG */ - - -#ifdef HAVE_GD_PNG - case PHP_GDIMG_TYPE_PNG: - im_org = gdImageCreateFromPng(org); - if (im_org == NULL) { - php_error (E_WARNING, "%s: unable to open '%s' Not a valid PNG file", get_active_function_name(TSRMLS_C), fn_dest); - RETURN_FALSE; - } - break; -#endif /* HAVE_GD_PNG */ - - default: - php_error(E_WARNING, "%s: Format not supported", get_active_function_name(TSRMLS_C)); - RETURN_FALSE; - break; - } - - org_width = gdImageSX (im_org); - org_height = gdImageSY (im_org); - - x_ratio = (float) org_width / (float) dest_width; - y_ratio = (float) org_height / (float) dest_height; - - if (x_ratio > 1 && y_ratio > 1) { - if (y_ratio > x_ratio) { - x_ratio = y_ratio; - } - else { - y_ratio = x_ratio; - } - dest_width = (int)(org_width / x_ratio); - dest_height = (int)(org_height / y_ratio); - } - else { - x_ratio = (float) dest_width / (float) org_width; - y_ratio = (float) dest_height / (float) org_height; - - if (y_ratio < x_ratio) { - x_ratio = y_ratio; - } - else { - y_ratio = x_ratio; - } - dest_width = (int)(org_width * x_ratio); - dest_height = (int)(org_height * y_ratio); - } - - im_tmp = gdImageCreate (dest_width, dest_height); - if (im_tmp == NULL ) { - php_error(E_WARNING, "%s: unable to allocate temporary buffer", get_active_function_name(TSRMLS_C)); - RETURN_FALSE; - } - - gdImageCopyResized (im_tmp, im_org, 0, 0, 0, 0, dest_width, dest_height, org_width, org_height); - - gdImageDestroy(im_org); - - fclose(org); - - im_dest = gdImageCreate(dest_width, dest_height); - if (im_dest == NULL) { - php_error(E_WARNING, "%s: unable to allocate destination buffer", get_active_function_name(TSRMLS_C)); - RETURN_FALSE; - } - white = gdImageColorAllocate(im_dest, 255, 255, 255); - if (white == -1) { - php_error(E_WARNING, "%s: unable to allocate the colors for the destination buffer", get_active_function_name(TSRMLS_C)); - RETURN_FALSE; - } - - black = gdImageColorAllocate(im_dest, 0, 0, 0); - if (black == -1) { - php_error(E_WARNING, "%s: unable to allocate the colors for the destination buffer", get_active_function_name(TSRMLS_C)); - RETURN_FALSE; - } - - int_threshold = int_threshold * 32; - - for (y = 0; y < dest_height; y++) { - for(x = 0; x < dest_width; x++) { - color_org = gdImageGetPixel (im_tmp, x, y); - median = (im_tmp->red[color_org] + im_tmp->green[color_org] + im_tmp->blue[color_org]) / 3; - if (median < int_threshold) { - color = black; - } - else { - color = white; - } - gdImageSetPixel (im_dest, x, y, color); - } - } - - gdImageDestroy (im_tmp ); - - gdImageWBMP (im_dest, black , dest); - - fflush(dest); - fclose(dest); - - gdImageDestroy( im_dest ); - - RETURN_TRUE; -} -/* }}} */ -#endif /* HAVE_GD_WBMP */ - -#endif /* HAVE_LIBGD */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/gd/gd.dsp b/ext/gd/gd.dsp deleted file mode 100644 index e8e3f99a19..0000000000 --- a/ext/gd/gd.dsp +++ /dev/null @@ -1,203 +0,0 @@ -# Microsoft Developer Studio Project File - Name="gd" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
-
-CFG=gd - Win32 Release_TS GD2
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE
-!MESSAGE NMAKE /f "gd.mak".
-!MESSAGE
-!MESSAGE You can specify a configuration when running NMAKE
-!MESSAGE by defining the macro CFG on the command line. For example:
-!MESSAGE
-!MESSAGE NMAKE /f "gd.mak" CFG="gd - Win32 Release_TS GD2"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "gd - Win32 Release_TS GD2" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "gd - Win32 Release_TS GD1" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "gd - Win32 Debug_TS GD2" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "gd - Win32 Debug_TS GD1" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE
-
-# Begin Project
-# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-CPP=cl.exe
-MTL=midl.exe
-RSC=rc.exe
-
-!IF "$(CFG)" == "gd - Win32 Release_TS GD2"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "gd___Win32_Release_TS_GD2"
-# PROP BASE Intermediate_Dir "gd___Win32_Release_TS_GD2"
-# PROP BASE Ignore_Export_Lib 0
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Release_TS"
-# PROP Intermediate_Dir "Release_TS"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MD /W3 /GX /O2 /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /D ZEND_DEBUG=0 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "COMPILE_DL_GD" /D ZTS=1 /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_GDIMAGECOLORRESOLVE=1 /D HAVE_LIBTTF=1 /D "HAVE_GD_PNG" /D "HAVE_GD_JPG" /D "HAVE_GD_WBMP" /D HAVE_LIBGD13=1 /D HAVE_LIBGD=1 /D HAVE_LIBGD15=1 /FR /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /D ZEND_DEBUG=0 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "COMPILE_DL_GD" /D ZTS=1 /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_GDIMAGECOLORRESOLVE=1 /D "HAVE_GD_PNG" /D "HAVE_GD_JPG" /D "HAVE_GD_WBMP" /D HAVE_LIBGD=1 /D HAVE_LIBGD13=1 /D HAVE_LIBGD15=1 /D HAVE_LIBGD20=1 /D "USE_GD_IOCTX" /D HAVE_LIBFREETYPE=1 /D "USE_GD_IMGSTRTTF" /D HAVE_GD_STRINGTTF=1 /FR /YX /FD /c
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x406 /d "NDEBUG"
-# ADD RSC /l 0x406 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 php4ts.lib freetype.lib gd.lib libjpeg.lib libtiff.lib libpng.lib zlib.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"..\..\Release_TS/php_gd.dll" /libpath:"..\..\Release_TS" /libpath:"..\..\Release_TS_Inline"
-# SUBTRACT BASE LINK32 /pdb:none
-# ADD LINK32 php4ts.lib freetype2.lib gd.lib libjpeg.lib libtiff.lib libpng.lib zlib.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"..\..\Release_TS/php_gd.dll" /libpath:"..\..\Release_TS" /libpath:"..\..\Release_TS_Inline"
-# SUBTRACT LINK32 /pdb:none
-
-!ELSEIF "$(CFG)" == "gd - Win32 Release_TS GD1"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "gd___Win32_Release_TS_GD1"
-# PROP BASE Intermediate_Dir "gd___Win32_Release_TS_GD1"
-# PROP BASE Ignore_Export_Lib 0
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Release_TS"
-# PROP Intermediate_Dir "Release_TS"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MD /W3 /GX /O2 /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /D ZEND_DEBUG=0 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "COMPILE_DL_GD" /D ZTS=1 /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_GDIMAGECOLORRESOLVE=1 /D HAVE_LIBTTF=1 /D "HAVE_GD_PNG" /D "HAVE_GD_JPG" /D "HAVE_GD_WBMP" /D HAVE_LIBGD13=1 /D HAVE_LIBGD=1 /D HAVE_LIBGD15=1 /FR /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /D ZEND_DEBUG=0 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "COMPILE_DL_GD" /D ZTS=1 /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_GDIMAGECOLORRESOLVE=1 /D HAVE_LIBTTF=1 /D "HAVE_GD_PNG" /D "HAVE_GD_JPG" /D "HAVE_GD_WBMP" /D HAVE_LIBGD13=1 /D HAVE_LIBGD=1 /D HAVE_LIBGD15=1 /FR /YX /FD /c
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x406 /d "NDEBUG"
-# ADD RSC /l 0x406 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 php4ts.lib freetype.lib gd.lib libjpeg.lib libtiff.lib libpng.lib zlib.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"..\..\Release_TS/php_gd.dll" /libpath:"..\..\Release_TS" /libpath:"..\..\Release_TS_Inline"
-# SUBTRACT BASE LINK32 /pdb:none
-# ADD LINK32 php4ts.lib freetype.lib gd.lib libjpeg.lib libtiff.lib libpng.lib zlib.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"..\..\Release_TS/php_gd.dll" /libpath:"..\..\Release_TS" /libpath:"..\..\Release_TS_Inline"
-# SUBTRACT LINK32 /pdb:none
-
-!ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD2"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "gd___Win32_Debug_TS_GD2"
-# PROP BASE Intermediate_Dir "gd___Win32_Debug_TS_GD2"
-# PROP BASE Ignore_Export_Lib 0
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Debug_TS"
-# PROP Intermediate_Dir "Debug_TS"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MDd /W3 /GX /ZI /Od /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /D ZEND_DEBUG=1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "COMPILE_DL_GD" /D ZTS=1 /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_GDIMAGECOLORRESOLVE=1 /D HAVE_LIBTTF=1 /D "HAVE_GD_PNG" /D "HAVE_GD_JPG" /D "HAVE_GD_WBMP" /D HAVE_LIBGD13=1 /D HAVE_LIBGD=1 /D HAVE_LIBGD15=1 /FR /YX /FD /c
-# ADD CPP /nologo /MDd /W3 /GX /ZI /Od /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /D ZEND_DEBUG=1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "COMPILE_DL_GD" /D ZTS=1 /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_GDIMAGECOLORRESOLVE=1 /D "HAVE_GD_PNG" /D "HAVE_GD_JPG" /D "HAVE_GD_WBMP" /D HAVE_LIBGD=1 /D HAVE_LIBGD13=1 /D "HAVE_LIBGD15" /D HAVE_LIBGD20=1 /D "USE_GD_IOCTX" /D HAVE_LIBFREETYPE=1 /D "USE_GD_IMGSTRTTF" /D HAVE_GD_STRINGTTF=1 /FR /YX /FD /c
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x406 /d "NDEBUG"
-# ADD RSC /l 0x406 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 php4ts_debug.lib gd.lib libjpeg.lib freetype.lib libtiff.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /incremental:yes /debug /machine:I386 /out:"..\..\Debug_TS/php_gd.dll" /libpath:"..\..\Debug_TS"
-# SUBTRACT BASE LINK32 /pdb:none
-# ADD LINK32 php4ts_debug.lib gd.lib libjpeg.lib freetype2.lib libtiff.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /incremental:yes /debug /machine:I386 /out:"..\..\Debug_TS/php_gd.dll" /libpath:"..\..\Debug_TS"
-# SUBTRACT LINK32 /pdb:none
-
-!ELSEIF "$(CFG)" == "gd - Win32 Debug_TS GD1"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "gd___Win32_Debug_TS_GD1"
-# PROP BASE Intermediate_Dir "gd___Win32_Debug_TS_GD1"
-# PROP BASE Ignore_Export_Lib 0
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Debug_TS"
-# PROP Intermediate_Dir "Debug_TS"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MDd /W3 /GX /ZI /Od /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /D ZEND_DEBUG=1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "COMPILE_DL_GD" /D ZTS=1 /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_GDIMAGECOLORRESOLVE=1 /D HAVE_LIBTTF=1 /D "HAVE_GD_PNG" /D "HAVE_GD_JPG" /D "HAVE_GD_WBMP" /D HAVE_LIBGD13=1 /D HAVE_LIBGD=1 /D HAVE_LIBGD15=1 /FR /YX /FD /c
-# ADD CPP /nologo /MDd /W3 /GX /ZI /Od /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /D ZEND_DEBUG=1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "COMPILE_DL_GD" /D ZTS=1 /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_GDIMAGECOLORRESOLVE=1 /D HAVE_LIBTTF=1 /D "HAVE_GD_PNG" /D "HAVE_GD_JPG" /D "HAVE_GD_WBMP" /D HAVE_LIBGD13=1 /D HAVE_LIBGD=1 /D HAVE_LIBGD15=1 /FR /YX /FD /c
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x406 /d "NDEBUG"
-# ADD RSC /l 0x406 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 php4ts_debug.lib gd.lib libjpeg.lib freetype.lib libtiff.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /incremental:yes /debug /machine:I386 /out:"..\..\Debug_TS/php_gd.dll" /libpath:"..\..\Debug_TS"
-# SUBTRACT BASE LINK32 /pdb:none
-# ADD LINK32 php4ts_debug.lib gd.lib libjpeg.lib freetype.lib libtiff.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /incremental:yes /debug /machine:I386 /out:"..\..\Debug_TS/php_gd.dll" /libpath:"..\..\Debug_TS"
-# SUBTRACT LINK32 /pdb:none
-
-!ENDIF
-
-# Begin Target
-
-# Name "gd - Win32 Release_TS GD2"
-# Name "gd - Win32 Release_TS GD1"
-# Name "gd - Win32 Debug_TS GD2"
-# Name "gd - Win32 Debug_TS GD1"
-# Begin Group "Source Files"
-
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
-# Begin Source File
-
-SOURCE=.\gd.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\gdcache.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\gdt1.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\gdttf.c
-# End Source File
-# End Group
-# Begin Group "Header Files"
-
-# PROP Default_Filter "h;hpp;hxx;hm;inl"
-# Begin Source File
-
-SOURCE=.\gdcache.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\gdt1.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\gdttf.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\php_gd.h
-# End Source File
-# End Group
-# Begin Group "Resource Files"
-
-# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
-# End Group
-# End Target
-# End Project
diff --git a/ext/gd/gd_ctx.c b/ext/gd/gd_ctx.c deleted file mode 100644 index 3c599cab65..0000000000 --- a/ext/gd/gd_ctx.c +++ /dev/null @@ -1,106 +0,0 @@ -#include "php_gd.h" - - -#define CTX_PUTC(c,ctx) ctx->putC(ctx, c) - -static void _php_image_output_putc(struct gdIOCtx *ctx, int c) -{ - TSRMLS_FETCH(); - php_write(&c, 1 TSRMLS_CC); -} - -static int _php_image_output_putbuf(struct gdIOCtx *ctx, const void* buf, int l) -{ - TSRMLS_FETCH(); - return php_write((void *)buf, l TSRMLS_CC); -} - -static void _php_image_output_ctxfree(struct gdIOCtx *ctx) -{ - if(ctx) { - efree(ctx); - } -} - -static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, void (*func_p)()) -{ - zval **imgind, **file, **quality; - gdImagePtr im; - char *fn = NULL; - FILE *fp = NULL; - int argc = ZEND_NUM_ARGS(); - int q = -1, i; - gdIOCtx *ctx; - - /* The quality parameter for Wbmp stands for the threshold when called from image2wbmp() */ - - if (argc < 1 || argc > 3 || zend_get_parameters_ex(argc, &imgind, &file, &quality) == FAILURE) - { - WRONG_PARAM_COUNT; - } - - ZEND_FETCH_RESOURCE(im, gdImagePtr, imgind, -1, "Image", phpi_get_le_gd()); - - if (argc > 1) { - convert_to_string_ex(file); - fn = Z_STRVAL_PP(file); - if (argc == 3) { - convert_to_long_ex(quality); - q = Z_LVAL_PP(quality); - } - } - - if ((argc == 2) || (argc == 3 && Z_STRLEN_PP(file))) { - if (!fn || fn == empty_string || php_check_open_basedir(fn TSRMLS_CC)) { - php_error(E_WARNING, "%s: invalid filename '%s'", get_active_function_name(TSRMLS_C), fn); - RETURN_FALSE; - } - - fp = VCWD_FOPEN(fn, "wb"); - if (!fp) { - php_error(E_WARNING, "%s: unable to open '%s' for writing", get_active_function_name(TSRMLS_C), fn); - RETURN_FALSE; - } - - ctx = gdNewFileCtx(fp); - } else { - ctx = emalloc(sizeof(gdIOCtx)); - ctx->putC = _php_image_output_putc; - ctx->putBuf = _php_image_output_putbuf; - ctx->free = _php_image_output_ctxfree; - -#if APACHE && defined(CHARSET_EBCDIC) - /* XXX this is unlikely to work any more thies@thieso.net */ - /* This is a binary file already: avoid EBCDIC->ASCII conversion */ - ap_bsetflag(php3_rqst->connection->client, B_EBCDIC2ASCII, 0); -#endif - } - - switch(image_type) { - case PHP_GDIMG_CONVERT_WBM: - if(q<0||q>255) { - php_error(E_WARNING, "%s: invalid threshold value '%d'. It must be between 0 and 255",get_active_function_name(TSRMLS_C), q); - } - case PHP_GDIMG_TYPE_JPG: - (*func_p)(im, ctx, q); - break; - case PHP_GDIMG_TYPE_WBM: - for(i=0; i < gdImageColorsTotal(im); i++) { - if(gdImageRed(im, i) == 0) break; - } - (*func_p)(im, i, ctx); - break; - default: - (*func_p)(im, ctx); - break; - } - - ctx->free(ctx); - - if(fp) { - fflush(fp); - fclose(fp); - } - - RETURN_TRUE; -} diff --git a/ext/gd/gdcache.c b/ext/gd/gdcache.c deleted file mode 100644 index b89f5610ac..0000000000 --- a/ext/gd/gdcache.c +++ /dev/null @@ -1,201 +0,0 @@ -/* - * $Id$ - * - * 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 - * reached a given size. - * - * John Ellson (ellson@lucent.com) Oct 31, 1997 - * - * Test this with: - * gcc -o gdcache -g -Wall -DTEST gdcache.c - * - * The cache is implemented by a singly-linked list of elements - * each containing a pointer to a user struct that is being managed by - * the cache. - * - * The head structure has a pointer to the most-recently-used - * element, and elements are moved to this position in the list each - * time they are used. The head also contains pointers to three - * user defined functions: - * - a function to test if a cached userdata matches some keydata - * - a function to provide a new userdata struct to the cache - * if there has been a cache miss. - * - a function to release a userdata struct when it is - * no longer being managed by the cache - * - * In the event of a cache miss the cache is allowed to grow up to - * a specified maximum size. After the maximum size is reached then - * the least-recently-used element is discarded to make room for the - * new. The most-recently-returned value is always left at the - * beginning of the list after retrieval. - * - * In the current implementation the cache is traversed by a linear - * search from most-recent to least-recent. This linear search - * probably limits the usefulness of this implementation to cache - * sizes of a few tens of elements. - */ - -/* This just seems unessacary */ -#if (WIN32|WINNT) -#define ENABLE_GD_TTF -#else -#include "php_config.h" -#endif -#if HAVE_LIBTTF|HAVE_LIBFREETYPE - -#include "gdcache.h" - -/*********************************************************/ -/* implementation */ -/*********************************************************/ - - -/* create a new cache */ -gdCache_head_t * -gdCacheCreate( - int size, - gdCacheTestFn_t gdCacheTest, - gdCacheFetchFn_t gdCacheFetch, - gdCacheReleaseFn_t gdCacheRelease ) -{ - gdCache_head_t *head; - - head = (gdCache_head_t *)malloc(sizeof(gdCache_head_t)); - head->mru = NULL; - head->size = size; - head->gdCacheTest = gdCacheTest; - head->gdCacheFetch = gdCacheFetch; - head->gdCacheRelease = gdCacheRelease; - return head; -} - -void -gdCacheDelete( gdCache_head_t *head ) -{ - gdCache_element_t *elem, *prev; - - elem = head->mru; - while(elem) { - (*(head->gdCacheRelease))(elem->userdata); - prev = elem; - elem = elem->next; - free((char *)prev); - } - free((char *)head); -} - -void * -gdCacheGet( gdCache_head_t *head, void *keydata ) -{ - int i=0; - gdCache_element_t *elem, *prev = NULL, *prevprev = NULL; - void *userdata; - - elem = head->mru; - while(elem) { - if ((*(head->gdCacheTest))(elem->userdata, keydata)) { - if (i) { /* if not already most-recently-used */ - /* relink to top of list */ - prev->next = elem->next; - elem->next = head->mru; - head->mru = elem; - } - return elem->userdata; - } - prevprev = prev; - prev = elem; - elem = elem->next; - i++; - } - userdata = (*(head->gdCacheFetch))(&(head->error), keydata); - if (! userdata) { - /* if there was an error in the fetch then don't cache */ - return NULL; - } - if (i < head->size) { /* cache still growing - add new elem */ - elem = (gdCache_element_t *)malloc(sizeof(gdCache_element_t)); - } - else { /* cache full - replace least-recently-used */ - /* preveprev becomes new end of list */ - prevprev->next = NULL; - elem = prev; - (*(head->gdCacheRelease))(elem->userdata); - } - /* relink to top of list */ - elem->next = head->mru; - head->mru = elem; - elem->userdata = userdata; - return userdata; -} - - - -/*********************************************************/ -/* test stub */ -/*********************************************************/ - - -#ifdef GDCACHE_TEST - -#include <stdio.h> - -typedef struct { - int key; - int value; -} key_value_t; - -static int -cacheTest( void *map, void *key ) -{ - return (((key_value_t *)map)->key == *(int *)key); -} - -static void * -cacheFetch( char **error, void *key ) -{ - key_value_t *map; - - map = (key_value_t *)malloc(sizeof(key_value_t)); - map->key = *(int *)key; - map->value = 3; - - *error = NULL; - return (void *)map; -} - -static void -cacheRelease( void *map) -{ - free( (char *)map ); -} - -int -main(char *argv[], int argc) -{ - gdCache_head_t *cacheTable; - int elem, key; - - cacheTable = gdCacheCreate(3, cacheTest, cacheFetch, cacheRelease); - - key = 20; - elem = *(int *)gdCacheGet(cacheTable, &key); - key = 30; - elem = *(int *)gdCacheGet(cacheTable, &key); - key = 40; - elem = *(int *)gdCacheGet(cacheTable, &key); - key = 50; - elem = *(int *)gdCacheGet(cacheTable, &key); - key = 30; - elem = *(int *)gdCacheGet(cacheTable, &key); - key = 30; - elem = *(int *)gdCacheGet(cacheTable, &key); - - gdCacheDelete(cacheTable); - - return 0; -} - -#endif - -#endif /* ENABLE_GD_TTF */ diff --git a/ext/gd/gdcache.h b/ext/gd/gdcache.h deleted file mode 100644 index 06bf0ee6ce..0000000000 --- a/ext/gd/gdcache.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * $Id$ - * - * 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 - * reached a given size. - * - * John Ellson (ellson@lucent.com) Oct 31, 1997 - * - * Test this with: - * gcc -o gdcache -g -Wall -DTEST gdcache.c - * - * The cache is implemented by a singly-linked list of elements - * each containing a pointer to a user struct that is being managed by - * the cache. - * - * The head structure has a pointer to the most-recently-used - * element, and elements are moved to this position in the list each - * time they are used. The head also contains pointers to three - * user defined functions: - * - a function to test if a cached userdata matches some keydata - * - a function to provide a new userdata struct to the cache - * if there has been a cache miss. - * - a function to release a userdata struct when it is - * no longer being managed by the cache - * - * In the event of a cache miss the cache is allowed to grow up to - * a specified maximum size. After the maximum size is reached then - * the least-recently-used element is discarded to make room for the - * new. The most-recently-returned value is always left at the - * beginning of the list after retrieval. - * - * In the current implementation the cache is traversed by a linear - * search from most-recent to least-recent. This linear search - * probably limits the usefulness of this implementation to cache - * sizes of a few tens of elements. - */ - -/*********************************************************/ -/* header */ -/*********************************************************/ - -#if (!defined _OSD_POSIX) && HAVE_MALLOC_H -#include <malloc.h> -#else -#include <stdlib.h> /* BS2000/OSD defines malloc() & friends in stdlib.h */ -#endif -#ifndef NULL -#define NULL (void *)0 -#endif - -/* user defined function templates */ -typedef int (*gdCacheTestFn_t)(void *userdata, void *keydata); -typedef void *(*gdCacheFetchFn_t)(char **error, void *keydata); -typedef void (*gdCacheReleaseFn_t)(void *userdata); - -/* element structure */ -typedef struct gdCache_element_s gdCache_element_t; -struct gdCache_element_s { - gdCache_element_t *next; - void *userdata; -}; - -/* head structure */ -typedef struct gdCache_head_s gdCache_head_t; -struct gdCache_head_s { - gdCache_element_t *mru; - int size; - char *error; - gdCacheTestFn_t gdCacheTest; - gdCacheFetchFn_t gdCacheFetch; - gdCacheReleaseFn_t gdCacheRelease; -}; - -/* function templates */ -gdCache_head_t * -gdCacheCreate( - int size, - gdCacheTestFn_t gdCacheTest, - gdCacheFetchFn_t gdCacheFetch, - gdCacheReleaseFn_t gdCacheRelease ); - -void -gdCacheDelete( gdCache_head_t *head ); - -void * -gdCacheGet( gdCache_head_t *head, void *keydata ); diff --git a/ext/gd/gdt1.c b/ext/gd/gdt1.c deleted file mode 100644 index 3f5eefd090..0000000000 --- a/ext/gd/gdt1.c +++ /dev/null @@ -1,549 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2002 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Jouni Ahto <jah@mork.net> | - | | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#if 0 /* Moved currently back to gd.c */ - -#include "php.h" -#include "php_gd.h" - -#if HAVE_LIBT1 - -void php_free_ps_font(int font_id) -{ - T1_DeleteFont(font_id); -} - -void php_free_ps_enc(char **enc) -{ - T1_DeleteEncoding(enc); -} - -/* {{{ proto int imagepsloadfont(string pathname) - Load a new font from specified file */ -PHP_FUNCTION(imagepsloadfont) -{ - zval **file; - int f_ind, l_ind; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &file) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(file); - - f_ind = T1_AddFont(Z_STRVAL_PP(file)); - - if (f_ind < 0) { - switch (f_ind) { - case -1: - php_error(E_WARNING, "Couldn't find the font file"); - RETURN_FALSE; - break; - case -2: - case -3: - php_error(E_WARNING, "Memory allocation fault in t1lib"); - RETURN_FALSE; - break; - default: - php_error(E_WARNING, "An unknown error occurred in t1lib"); - RETURN_FALSE; - break; - } - } - - T1_LoadFont(f_ind); - /* - l_ind = zend_list_insert(f_ind, T1_GLOBAL(le_ps_font)); - RETURN_LONG(l_ind); - */ - zend_list_addref(f_ind); - RETURN_LONG(f_ind); -} -/* }}} */ - -/* {{{ The function in t1lib which this function uses seem to be buggy... -proto int imagepscopyfont(int font_index) -Make a copy of a font for purposes like extending or reenconding */ -/* -PHP_FUNCTION(imagepscopyfont) -{ - pval *fnt; - int l_ind, type; - gd_ps_font *nf_ind, *of_ind; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters(ht, 1, &fnt) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_long(fnt); - - of_ind = zend_list_find(Z_LVAL_P(fnt), &type); - - if (type != GD_GLOBAL(le_ps_font)) { - php_error(E_WARNING, "%d is not a Type 1 font index", Z_LVAL_P(fnt)); - RETURN_FALSE; - } - - nf_ind = emalloc(sizeof(gd_ps_font)); - nf_ind->font_id = T1_CopyFont(of_ind->font_id); - - if (nf_ind->font_id < 0) { - l_ind = nf_ind->font_id; - efree(nf_ind); - switch (l_ind) { - case -1: - php_error(E_WARNING, "FontID %d is not loaded in memory", l_ind); - RETURN_FALSE; - break; - case -2: - php_error(E_WARNING, "Tried to copy a logical font"); - RETURN_FALSE; - break; - case -3: - php_error(E_WARNING, "Memory allocation fault in t1lib"); - RETURN_FALSE; - break; - default: - php_error(E_WARNING, "An unknown error occurred in t1lib"); - RETURN_FALSE; - break; - } - } - - nf_ind->extend = 1; - l_ind = zend_list_insert(nf_ind, GD_GLOBAL(le_ps_font)); - RETURN_LONG(l_ind); -} -*/ -/* }}} */ - -/* {{{ proto bool imagepsfreefont(int font_index) - Free memory used by a font */ -PHP_FUNCTION(imagepsfreefont) -{ - zval **fnt; - int type; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &fnt) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_long_ex(fnt); - - zend_list_find(Z_LVAL_PP(fnt), &type); - - if (type != T1_GLOBAL(le_ps_font)) { - php_error(E_WARNING, "%d is not a Type 1 font index", Z_LVAL_PP(fnt)); - RETURN_FALSE; - } - - zend_list_delete(Z_LVAL_PP(fnt)); - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto bool imagepsencodefont(int font_index, string filename) - To change a fonts character encoding vector */ -PHP_FUNCTION(imagepsencodefont) -{ - zval **fnt, **enc; - char **enc_vector; - int type; - int f_ind; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &fnt, &enc) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_long_ex(fnt); - convert_to_string_ex(enc); - - f_ind = zend_list_find(Z_LVAL_PP(fnt), &type); - - if (type != T1_GLOBAL(le_ps_font)) { - php_error(E_WARNING, "%d is not a Type 1 font index", Z_LVAL_PP(fnt)); - RETURN_FALSE; - } - - if ((enc_vector = T1_LoadEncoding(Z_STRVAL_PP(enc))) == NULL) { - php_error(E_WARNING, "Couldn't load encoding vector from %s", Z_STRVAL_PP(enc)); - RETURN_FALSE; - } - - T1_DeleteAllSizes(f_ind); - if (T1_ReencodeFont(f_ind, enc_vector)) { - T1_DeleteEncoding(enc_vector); - php_error(E_WARNING, "Couldn't reencode font"); - RETURN_FALSE; - } - zend_list_insert(enc_vector, T1_GLOBAL(le_ps_enc)); - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto bool imagepsextendfont(int font_index, float extend) - Extend or or condense (if extend < 1) a font */ -PHP_FUNCTION(imagepsextendfont) -{ - zval **fnt, **ext; - int type; - int f_ind; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &fnt, &ext) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_long_ex(fnt); - convert_to_double_ex(ext); - - f_ind = zend_list_find(Z_LVAL_PP(fnt), &type); - - if (type != T1_GLOBAL(le_ps_font)) { - php_error(E_WARNING, "%d is not a Type 1 font index", Z_LVAL_PP(fnt)); - RETURN_FALSE; - } - - if (T1_ExtendFont(f_ind, Z_DVAL_PP(ext)) != 0) RETURN_FALSE; - /* - f_ind->extend = Z_DVAL_P(ext); - */ - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto bool imagepsslantfont(int font_index, float slant) - Slant a font */ -PHP_FUNCTION(imagepsslantfont) -{ - zval **fnt, **slt; - int type; - int f_ind; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &fnt, &slt) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_long_ex(fnt); - convert_to_double_ex(slt); - - f_ind = zend_list_find(Z_LVAL_PP(fnt), &type); - - if (type != T1_GLOBAL(le_ps_font)) { - php_error(E_WARNING, "%d is not a Type 1 font index", Z_LVAL_PP(fnt)); - RETURN_FALSE; - } - - if (T1_SlantFont(f_ind, Z_DVAL_PP(slt)) != 0) RETURN_FALSE; - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto array imagepstext(int image, string text, int font, int size, int xcoord, int ycoord [, int space, int tightness, float angle, int antialias]) - Rasterize a string over an image */ -PHP_FUNCTION(imagepstext) -{ - zval **img, **str, **fnt, **sz, **fg, **bg, **sp, **px, **py, **aas, **wd, **ang; - int i, j, x, y; - int space, type; - 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; - int aa[16], aa_steps; - int width, amount_kern, add_width; - double angle; - unsigned long aa_greys[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; - gdImagePtr bg_img; - GLYPH *str_img; - T1_OUTLINE *char_path, *str_path; - T1_TMATRIX *transform = NULL; - - switch(ZEND_NUM_ARGS()) { - case 8: - if (zend_get_parameters_ex(8, &img, &str, &fnt, &sz, &fg, &bg, &px, &py) == FAILURE) { - RETURN_FALSE; - } - convert_to_string_ex(str); - convert_to_long_ex(fnt); - convert_to_long_ex(sz); - convert_to_long_ex(fg); - convert_to_long_ex(bg); - convert_to_long_ex(px); - convert_to_long_ex(py); - x = Z_LVAL_PP(px); - y = Z_LVAL_PP(py); - space = 0; - aa_steps = 4; - width = 0; - angle = 0; - break; - case 12: - if (zend_get_parameters_ex(12, &img, &str, &fnt, &sz, &fg, &bg, &px, &py, &sp, &wd, &ang, &aas) == FAILURE) { - RETURN_FALSE; - } - convert_to_string_ex(str); - convert_to_long_ex(fnt); - convert_to_long_ex(sz); - convert_to_long_ex(sp); - convert_to_long_ex(fg); - convert_to_long_ex(bg); - convert_to_long_ex(px); - convert_to_long_ex(py); - x = Z_LVAL_PP(px); - y = Z_LVAL_PP(py); - convert_to_long_ex(sp); - space = Z_LVAL_PP(sp); - convert_to_long_ex(aas); - aa_steps = Z_LVAL_PP(aas); - convert_to_long_ex(wd); - width = Z_LVAL_PP(wd); - convert_to_double_ex(ang); - angle = Z_DVAL_PP(ang); - break; - default: - WRONG_PARAM_COUNT; - } - - bg_img = zend_list_find(Z_LVAL_PP(img), &type); - - if (!bg_img || type != GD_GLOBAL(le_gd)) { - php_error(E_WARNING, "Unable to find image pointer"); - RETURN_FALSE; - } - - f_ind = zend_list_find(Z_LVAL_P(fnt), &type); - - if (!f_ind || type != GD_GLOBAL(le_ps_font)) { - php_error(E_WARNING, "%d is not a Type 1 font index", Z_LVAL_P(fnt)); - RETURN_FALSE; - } - - fg_rd = gdImageRed(bg_img, Z_LVAL_P(fg)); - fg_gr = gdImageGreen(bg_img, Z_LVAL_P(fg)); - fg_bl = gdImageBlue(bg_img, Z_LVAL_P(fg)); - bg_rd = gdImageRed(bg_img, Z_LVAL_P(bg)); - bg_gr = gdImageGreen(bg_img, Z_LVAL_P(bg)); - bg_bl = gdImageBlue(bg_img, Z_LVAL_P(bg)); - - 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); - aa[i] = gdImageColorResolve(bg_img, rd, gr, bl); - } - - T1_AASetBitsPerPixel(8); - - switch (aa_steps) { - case 4: - T1_AASetGrayValues(0, 1, 2, 3, 4); - T1_AASetLevel(T1_AA_LOW); - break; - case 16: - T1_AAHSetGrayValues(aa_greys); - T1_AASetLevel(T1_AA_HIGH); - break; - default: - php_error(E_WARNING, "Invalid value %d as number of steps for antialiasing", aa_steps); - RETURN_FALSE; - } - - if (angle) { - transform = T1_RotateMatrix(NULL, angle); - } - - if (width) { -#ifdef HAVE_LIBT1_OUTLINE - str_path = T1_GetCharOutline(f_ind->font_id, Z_STRVAL_P(str)[0], Z_LVAL_P(sz), transform); - - for (i = 1; i < Z_STRLEN_P(str); i++) { - amount_kern = (int) T1_GetKerning(f_ind->font_id, Z_STRVAL_P(str)[i-1], Z_STRVAL_P(str)[i]); - amount_kern += Z_STRVAL_P(str)[i-1] == ' ' ? space : 0; - add_width = (int) (amount_kern+width)/f_ind->extend; - - char_path = T1_GetMoveOutline(f_ind->font_id, add_width, 0, 0, Z_LVAL_P(sz), transform); - str_path = T1_ConcatOutlines(str_path, char_path); - - char_path = T1_GetCharOutline(f_ind->font_id, Z_STRVAL_P(str)[i], Z_LVAL_P(sz), transform); - str_path = T1_ConcatOutlines(str_path, char_path); - } - str_img = T1_AAFillOutline(str_path, 0); -#else - php_error(E_WARNING, "Setting space between characters in function ImagePSText is supported only with t1lib version 0.9 or above"); - RETURN_FALSE; -#endif - } else { - str_img = T1_AASetString(f_ind->font_id, Z_STRVAL_P(str), Z_STRLEN_P(str), - space, T1_KERNING, Z_LVAL_P(sz), transform); - } - - if (T1_errno) RETURN_FALSE; - - h_lines = str_img->metrics.ascent - str_img->metrics.descent; - v_lines = str_img->metrics.rightSideBearing - str_img->metrics.leftSideBearing; - - for (i = 0; i < v_lines; i++) { - for (j = 0; j < h_lines; j++) { - switch (str_img->bits[j*v_lines+i]) { - case 0: - break; - default: - c_ind = aa[str_img->bits[j*v_lines+i]-1]; - gdImageSetPixel(bg_img, x+str_img->metrics.leftSideBearing+i, y-str_img->metrics.ascent+j, c_ind); - } - } - } - - if (array_init(return_value) == FAILURE) { - RETURN_FALSE; - } - - add_next_index_long(return_value, str_img->metrics.leftSideBearing); - add_next_index_long(return_value, str_img->metrics.descent); - add_next_index_long(return_value, str_img->metrics.rightSideBearing); - add_next_index_long(return_value, str_img->metrics.ascent); - -} -/* }}} */ - -/* {{{ proto array imagepsbbox(string text, int font, int size [, int space, int tightness, int angle]) - Return the bounding box needed by a string if rasterized */ -PHP_FUNCTION(imagepsbbox) -{ - pval *str, *fnt, *sz, *sp, *wd, *ang; - int i, space, add_width, char_width, amount_kern, type; - int cur_x, cur_y, dx, dy; - int x1, y1, x2, y2, x3, y3, x4, y4; - gd_ps_font *f_ind; - int per_char = 0; - double angle, sin_a, cos_a; - BBox char_bbox, str_bbox = {0, 0, 0, 0}; - - switch(ZEND_NUM_ARGS()) { - case 3: - if (zend_get_parameters(ht, 3, &str, &fnt, &sz) == FAILURE) { - RETURN_FALSE; - } - convert_to_string(str); - convert_to_long(fnt); - convert_to_long(sz); - space = 0; - break; - case 6: - if (zend_get_parameters(ht, 6, &str, &fnt, &sz, &sp, &wd, &ang) == FAILURE) { - RETURN_FALSE; - } - convert_to_string(str); - convert_to_long(fnt); - convert_to_long(sz); - convert_to_long(sp); - space = Z_LVAL_P(sp); - convert_to_long(wd); - add_width = Z_LVAL_P(wd); - convert_to_double(ang); - angle = Z_DVAL_P(ang) * M_PI / 180; - sin_a = sin(angle); - cos_a = cos(angle); - per_char = add_width || angle ? 1 : 0; - break; - default: - WRONG_PARAM_COUNT; - } - - f_ind = zend_list_find(Z_LVAL_P(fnt), &type); - - if (type != GD_GLOBAL(le_ps_font)) { - php_error(E_WARNING, "%d is not a Type 1 font index", Z_LVAL_P(fnt)); - RETURN_FALSE; - } - -#define max(a, b) (a > b ? a : b) -#define min(a, b) (a < b ? a : b) -#define new_x(a, b) (int) ((a) * cos_a - (b) * sin_a) -#define new_y(a, b) (int) ((a) * sin_a + (b) * cos_a) - - if (per_char) { - space += T1_GetCharWidth(f_ind->font_id, ' '); - cur_x = cur_y = 0; - - for (i = 0; i < Z_STRLEN_P(str); i++) { - if (Z_STRVAL_P(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->font_id, Z_STRVAL_P(str)[i]); - char_width = T1_GetCharWidth(f_ind->font_id, Z_STRVAL_P(str)[i]); - } - amount_kern = i ? T1_GetKerning(f_ind->font_id, Z_STRVAL_P(str)[i-1], Z_STRVAL_P(str)[i]) : 0; - - /* Transfer character bounding box to right place */ - x1 = new_x(char_bbox.llx, char_bbox.lly) + cur_x; - y1 = new_y(char_bbox.llx, char_bbox.lly) + cur_y; - x2 = new_x(char_bbox.llx, char_bbox.ury) + cur_x; - y2 = new_y(char_bbox.llx, char_bbox.ury) + cur_y; - x3 = new_x(char_bbox.urx, char_bbox.ury) + cur_x; - y3 = new_y(char_bbox.urx, char_bbox.ury) + cur_y; - x4 = new_x(char_bbox.urx, char_bbox.lly) + cur_x; - y4 = new_y(char_bbox.urx, char_bbox.lly) + cur_y; - - /* Find min & max values and compare them with current bounding box */ - str_bbox.llx = min(str_bbox.llx, min(x1, min(x2, min(x3, x4)))); - str_bbox.lly = min(str_bbox.lly, min(y1, min(y2, min(y3, y4)))); - str_bbox.urx = max(str_bbox.urx, max(x1, max(x2, max(x3, x4)))); - str_bbox.ury = max(str_bbox.ury, max(y1, max(y2, max(y3, y4)))); - - /* Move to the next base point */ - dx = new_x(char_width + add_width + amount_kern, 0); - dy = new_y(char_width + add_width + amount_kern, 0); - cur_x += dx; - cur_y += dy; - /* - printf("%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n", x1, y1, x2, y2, x3, y3, x4, y4, char_bbox.llx, char_bbox.lly, char_bbox.urx, char_bbox.ury, char_width, amount_kern, cur_x, cur_y, dx, dy); - */ - } - - } else { - str_bbox = T1_GetStringBBox(f_ind->font_id, Z_STRVAL_P(str), Z_STRLEN_P(str), space, T1_KERNING); - } - if (T1_errno) RETURN_FALSE; - - if (array_init(return_value) == FAILURE) { - RETURN_FALSE; - } - /* - 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_P(sz)/1000)); - add_next_index_long(return_value, (int) ceil(((double) str_bbox.lly)*Z_LVAL_P(sz)/1000)); - add_next_index_long(return_value, (int) ceil(((double) str_bbox.urx)*Z_LVAL_P(sz)/1000)); - add_next_index_long(return_value, (int) ceil(((double) str_bbox.ury)*Z_LVAL_P(sz)/1000)); -} -/* }}} */ - -#endif /* HAVE_LIBT1 */ - -#endif /* 0 */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/ext/gd/gdt1.h b/ext/gd/gdt1.h deleted file mode 100644 index f9aa9759a6..0000000000 --- a/ext/gd/gdt1.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2002 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Jouni Ahto <jah@mork.net> | - | | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#if HAVE_LIBT1 - -#include <t1lib.h> - -extern void php_free_ps_font(zend_rsrc_list_entry *rsrc TSRMLS_DC); -extern void php_free_ps_enc(zend_rsrc_list_entry *rsrc TSRMLS_DC); - -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/ext/gd/gdttf.c b/ext/gd/gdttf.c deleted file mode 100644 index 393f0bdbf7..0000000000 --- a/ext/gd/gdttf.c +++ /dev/null @@ -1,868 +0,0 @@ -/* gd interface to freetype library */ -/* */ -/* John Ellson ellson@lucent.com */ - -/* $Id$ */ - -#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 *)malloc(sizeof(font_t)); -#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"; - return NULL; - } -#else - a->fontname = (char *)malloc(strlen(b->fontname) + 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"; - } - 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"; - return NULL; - } - - if (TT_Set_Instance_Resolutions(a->instance, RESOLUTION, RESOLUTION)) { - *error = "Could not set device resolutions"; - return NULL; -map_found = 0; -a->have_char_map_Unicode = 0; -a->have_char_map_Big5 = 0; -a->have_char_map_Roman = 0; - } - - if (TT_Set_Instance_CharSize(a->instance, (TT_F26Dot6)(a->ptsize*64))) { - *error = "Could not set character size"; - 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"; - 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); - free(a->fontname); - free( (char *)element ); -} - -/********************************************************************/ -/* 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 *)malloc(sizeof(glyph_t)); - 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"; - 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"; - 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 ); - free( (char *)element ); -} - -/********************************************************************/ -/* 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 *)malloc(sizeof(bitmap_t)); - a->xoffset = b->xoffset; - a->yoffset = b->yoffset; - - b->glyph->Bit.bitmap = a->bitmap = (char *)malloc(b->glyph->Bit.size); - 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; - - free( a->bitmap ); - free( (char *)element ); -} - -/********************************************************************/ -/* 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 *)malloc(sizeof(tweencolor_t)); - 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) -{ - free((char *)element); -} - -/********************************************************************/ -/* 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_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 4f32129702..0000000000 --- a/ext/gd/gdttf.h +++ /dev/null @@ -1,16 +0,0 @@ -/* $Id$ */ - -#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/php_gd.h b/ext/gd/php_gd.h deleted file mode 100644 index 613f624cfd..0000000000 --- a/ext/gd/php_gd.h +++ /dev/null @@ -1,180 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2002 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | - | Stig Bakken <ssb@guardian.no> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_GD_H -#define PHP_GD_H - -#define HAVE_GDIMAGECREATEFROMPNG 1 - -#if HAVE_LIBTTF|HAVE_LIBFREETYPE -#define ENABLE_GD_TTF -#endif - -#if HAVE_LIBGD - -#include <gd.h> - -#if HAVE_LIBT1 -#include "gdt1.h" -#endif - -#define PHP_GDIMG_TYPE_GIF 1 -#define PHP_GDIMG_TYPE_PNG 2 -#define PHP_GDIMG_TYPE_JPG 3 -#define PHP_GDIMG_TYPE_WBM 4 -#define PHP_GDIMG_TYPE_XBM 5 -#define PHP_GDIMG_TYPE_XPM 6 -#define PHP_GDIMG_CONVERT_WBM 7 -#define PHP_GDIMG_TYPE_GD 8 -#define PHP_GDIMG_TYPE_GD2 9 -#define PHP_GDIMG_TYPE_GD2PART 10 - -#ifdef PHP_WIN32 -#define PHP_GD_API __declspec(dllexport) -#else -#define PHP_GD_API -#endif - -PHPAPI extern const char php_sig_gif[3]; -PHPAPI extern const char php_sig_jpg[3]; -PHPAPI extern const char php_sig_png[3]; - -extern zend_module_entry gd_module_entry; -#define phpext_gd_ptr &gd_module_entry - -/* gd.c functions */ -PHP_MINFO_FUNCTION(gd); -PHP_MINIT_FUNCTION(gd); -PHP_MSHUTDOWN_FUNCTION(gd); - -#ifndef HAVE_GDIMAGECOLORRESOLVE -static int gdImageColorResolve(gdImagePtr, int, int, int); -#endif -PHP_FUNCTION(imagearc); -PHP_FUNCTION(imagechar); -PHP_FUNCTION(imagecharup); -PHP_FUNCTION(imagecolorallocate); -PHP_FUNCTION(imagepalettecopy); -PHP_FUNCTION(imagecolorat); -PHP_FUNCTION(imagecolorclosest); -PHP_FUNCTION(imagecolorclosesthwb); -PHP_FUNCTION(imagecolordeallocate); -PHP_FUNCTION(imagecolorresolve); -PHP_FUNCTION(imagecolorexact); -PHP_FUNCTION(imagecolorset); -PHP_FUNCTION(imagecolorstotal); -PHP_FUNCTION(imagecolorsforindex); -PHP_FUNCTION(imagecolortransparent); -PHP_FUNCTION(imagecopy); -PHP_FUNCTION(imagecopymerge); -PHP_FUNCTION(imagecopyresized); -PHP_FUNCTION(imagetypes); -PHP_FUNCTION(imagecreate); -PHP_FUNCTION(imageftbbox); -PHP_FUNCTION(imagefttext); - -PHP_FUNCTION(imagecreatetruecolor); -PHP_FUNCTION(imagetruecolortopalette); -PHP_FUNCTION(imagesetthickness); -PHP_FUNCTION(imageellipse); -PHP_FUNCTION(imagefilledellipse); -PHP_FUNCTION(imagefilledarc); -PHP_FUNCTION(imagealphablending); -PHP_FUNCTION(imagecolorresolvealpha); -PHP_FUNCTION(imagecolorclosestalpha); -PHP_FUNCTION(imagecolorexactalpha); -PHP_FUNCTION(imagecopyresampled); -PHP_FUNCTION(imagesetthickness); -PHP_FUNCTION(imagesettile); -PHP_FUNCTION(imagecopymergegray); -PHP_FUNCTION(imagesetbrush); -PHP_FUNCTION(imagesettile); -PHP_FUNCTION(imagesetstyle); - -PHP_FUNCTION(imagecreatefromstring); -PHP_FUNCTION(imagecreatefromgif); -PHP_FUNCTION(imagecreatefromjpeg); -PHP_FUNCTION(imagecreatefromxbm); -PHP_FUNCTION(imagecreatefromxpm); -PHP_FUNCTION(imagecreatefrompng); -PHP_FUNCTION(imagecreatefromwbmp); -PHP_FUNCTION(imagecreatefromgd); -PHP_FUNCTION(imagecreatefromgd2); -PHP_FUNCTION(imagecreatefromgd2part); - -PHP_FUNCTION(imagegammacorrect); -PHP_FUNCTION(imagedestroy); -PHP_FUNCTION(imagefill); -PHP_FUNCTION(imagefilledpolygon); -PHP_FUNCTION(imagefilledrectangle); -PHP_FUNCTION(imagefilltoborder); -PHP_FUNCTION(imagefontwidth); -PHP_FUNCTION(imagefontheight); - -PHP_FUNCTION(imagegif ); -PHP_FUNCTION(imagejpeg ); -PHP_FUNCTION(imagepng); -PHP_FUNCTION(imagewbmp); -PHP_FUNCTION(imagegd); -PHP_FUNCTION(imagegd2); - -PHP_FUNCTION(imageinterlace); -PHP_FUNCTION(imageline); -PHP_FUNCTION(imageloadfont); -PHP_FUNCTION(imagepolygon); -PHP_FUNCTION(imagerectangle); -PHP_FUNCTION(imagesetpixel); -PHP_FUNCTION(imagestring); -PHP_FUNCTION(imagestringup); -PHP_FUNCTION(imagesx); -PHP_FUNCTION(imagesy); -PHP_FUNCTION(imagedashedline); -PHP_FUNCTION(imagettfbbox); -PHP_FUNCTION(imagettftext); -PHP_FUNCTION(imagepsloadfont); -/* -PHP_FUNCTION(imagepscopyfont); -*/ -PHP_FUNCTION(imagepsfreefont); -PHP_FUNCTION(imagepsencodefont); -PHP_FUNCTION(imagepsextendfont); -PHP_FUNCTION(imagepsslantfont); -PHP_FUNCTION(imagepstext); -PHP_FUNCTION(imagepsbbox); - -PHP_FUNCTION(jpeg2wbmp); -PHP_FUNCTION(png2wbmp); -PHP_FUNCTION(image2wbmp); - -PHP_GD_API int phpi_get_le_gd(void); - -/* This is missing from gd.h */ -#if HAVE_COLORCLOSESTHWB -int gdImageColorClosestHWB(gdImagePtr im, int r, int g, int b); -#endif - -#else - -#define phpext_gd_ptr NULL - -#endif - -#endif /* PHP_GD_H */ diff --git a/ext/gd/setup.stub b/ext/gd/setup.stub deleted file mode 100644 index 64668ae0fb..0000000000 --- a/ext/gd/setup.stub +++ /dev/null @@ -1,6 +0,0 @@ -define_option with-gd 'GD support?' yesnodir \ - "yes /usr GD install" \ -' Whether to include GD support. If PHP can find the GD libraries\n - on your system, it will be included automatically. You should enter\n - something here if you do not want to include GD support or if you\n - have installed GD in some unusual directory.' |