From: Sascha Schumann Date: Sun, 17 Oct 1999 14:57:49 +0000 (+0000) Subject: Add PNG support. Tested with gd 1.7.3. X-Git-Tag: php-4.0b3_RC2~144 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=51b1d2af6ae92cd27726dee3b066d7843eff5235;p=php Add PNG support. Tested with gd 1.7.3. --- diff --git a/ext/gd/Makefile.am b/ext/gd/Makefile.am index d767120564..4c6825eac3 100644 --- a/ext/gd/Makefile.am +++ b/ext/gd/Makefile.am @@ -1,7 +1,7 @@ ## Process this file with automake to produce Makefile.in SRC=gd.c gdcache.c gdttf.c -INCLUDES=@INCLUDES@ @GD_INCLUDES@ -I@top_srcdir@ -I@top_srcdir@/libzend +INCLUDES=@INCLUDES@ -I@top_srcdir@ -I@top_srcdir@/libzend noinst_LTLIBRARIES=@GD_STATIC@ EXTRA_LTLIBRARIES=libphpext_gd.la gd.la libphpext_gd_la_SOURCES=$(SRC) diff --git a/ext/gd/config.h.stub b/ext/gd/config.h.stub index db06b056cd..d13e8df475 100644 --- a/ext/gd/config.h.stub +++ b/ext/gd/config.h.stub @@ -4,6 +4,8 @@ /* Define if you have the gd version 1.3 library (-lgd). */ #define HAVE_LIBGD13 0 +#undef HAVE_GDIMAGECOLORRESOLVE #undef FREETYPE_4BIT_ANTIALIAS_HACK #undef HAVE_LIBFREETYPE #undef HAVE_LIBTTF +#undef HAVE_GD_PNG diff --git a/ext/gd/config.m4 b/ext/gd/config.m4 index 60ff629311..d2148f93b6 100644 --- a/ext/gd/config.m4 +++ b/ext/gd/config.m4 @@ -56,7 +56,20 @@ dnl A whole whack of possible places where this might be AC_MSG_RESULT(yes (static)) AC_ADD_LIBRARY_WITH_PATH(gd, $GD_LIB) fi + old_LDFLAGS=$LDFLAGS + LDFLAGS="$LDFLAGS -L$GD_LIB" + old_LIBS=$LIBS AC_CHECK_LIB(gd, gdImageString16, [ AC_DEFINE(HAVE_LIBGD13) ]) + LIBS="$LIBS -lpng -lz" + AC_CHECK_LIB(gd, gdImageColorResolve, [AC_DEFINE(HAVE_GDIMAGECOLORRESOLVE,1)]) + AC_CHECK_LIB(gd, gdImageCreateFromPng, [AC_DEFINE(HAVE_GD_PNG, 1)]) + + LIBS=$old_LIBS + LDFLAGS=$old_LDFLAGS + if test "$ac_cv_lib_gd_gdImageCreateFromPng" = "yes"; then + AC_ADD_LIBRARY(png) + AC_ADD_LIBRARY(z) + fi ac_cv_lib_gd_gdImageLine=yes else AC_MSG_ERROR([Unable to find libgd.(a|so) anywhere under $withval]) @@ -92,11 +105,10 @@ if test "$ac_cv_lib_gd_gdImageLine" = "yes"; then if test "$shared" = "yes"; then GD_LIBS="$GD_LIBS -lfreetype" GD_LFLAGS="$GD_LFLAGS -L$FREETYPE_DIR/lib" - GD_INCLUDES="$GD_INCLUDES -I$FREETYPE_DIR/include" else AC_ADD_LIBRARY_WITH_PATH(freetype, $FREETYPE_DIR/lib) - AC_ADD_INCLUDE($FREETYPE_DIR/include) fi + AC_ADD_INCLUDE($FREETYPE_DIR/include) AC_MSG_RESULT(yes) else if test -n "$TTF_DIR" ; then @@ -104,11 +116,10 @@ if test "$ac_cv_lib_gd_gdImageLine" = "yes"; then if test "$shared" = "yes"; then GD_LIBS="$GD_LIBS -lttf" GD_LFLAGS="$GD_LFLAGS -L$TTF_DIR/lib" - GD_INCLUDES="$GD_INCLUDES -I$TTF_DIR/include" else AC_ADD_LIBRARY_WITH_PATH(ttf, $TTF_DIR/lib) - AC_ADD_INCLUDE($TTF_DIR/include) fi + AC_ADD_INCLUDE($TTF_DIR/include) AC_MSG_RESULT(yes) else AC_MSG_RESULT(no) @@ -136,21 +147,17 @@ if test "$ac_cv_lib_gd_gdImageLine" = "yes"; then AC_MSG_RESULT(no) ]) + AC_EXPAND_PATH($GD_INCLUDE, GD_INCLUDE) + AC_ADD_INCLUDE($GD_INCLUDE) PHP_EXTENSION(gd, $shared) if test "$shared" != "yes"; then - AC_ADD_INCLUDE($GD_INCLUDE) GD_STATIC="libphpext_gd.la" else - AC_EXPAND_PATH($GD_INCLUDE, GD_INCLUDE) - if test -n "$GD_INCLUDE"; then - GD_INCLUDES="$GD_INCLUDES -I$GD_INCLUDE" - fi GD_SHARED="gd.la" fi fi AC_SUBST(GD_LFLAGS) AC_SUBST(GD_LIBS) -AC_SUBST(GD_INCLUDES) AC_SUBST(GD_STATIC) AC_SUBST(GD_SHARED) diff --git a/ext/gd/gd.c b/ext/gd/gd.c index f3d3eae22e..91cfc1f505 100644 --- a/ext/gd/gd.c +++ b/ext/gd/gd.c @@ -98,7 +98,13 @@ function_entry gd_functions[] = { PHP_FE(imagecopy, NULL) PHP_FE(imagecopyresized, NULL) PHP_FE(imagecreate, NULL) +#ifdef HAVE_GD_PNG + PHP_FE(imagecreatefrompng, NULL) + PHP_FE(imagepng, NULL) +#else PHP_FE(imagecreatefromgif, NULL) + PHP_FE(imagegif, NULL) +#endif PHP_FE(imagedestroy, NULL) PHP_FE(imagefill, NULL) PHP_FE(imagefilledpolygon, NULL) @@ -106,7 +112,6 @@ function_entry gd_functions[] = { PHP_FE(imagefilltoborder, NULL) PHP_FE(imagefontwidth, NULL) PHP_FE(imagefontheight, NULL) - PHP_FE(imagegif, NULL) PHP_FE(imageinterlace, NULL) PHP_FE(imageline, NULL) PHP_FE(imageloadfont, NULL) @@ -204,6 +209,8 @@ PHPAPI int phpi_get_le_gd(void){ return GD_GLOBAL(le_gd); } +#ifndef HAVE_GDIMAGECOLORRESOLVE + /********************************************************************/ /* gdImageColorResolve is a replacement for the old fragment: */ /* */ @@ -254,6 +261,8 @@ gdImageColorResolve(gdImagePtr im, int r, int g, int b) return op; /* Return newly allocated color */ } +#endif + void php3_free_gd_font(gdFontPtr fp) { if (fp->data) { @@ -367,6 +376,111 @@ PHP_FUNCTION(imagecreate) } /* }}} */ +#ifdef HAVE_GD_PNG + +/* {{{ proto int imagecreatefrompng(string filename) +Create a new image from file or URL */ +void php3_imagecreatefrompng (INTERNAL_FUNCTION_PARAMETERS) { + pval *file; + int ind; + gdImagePtr im; + char *fn=NULL; + FILE *fp; + int issock=0, socketd=0; + GD_TLS_VARS; + if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &file) == FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_string(file); + fn = file->value.str.val; +#if WIN32|WINNT + fp = fopen(file->value.str.val, "rb"); +#else + fp = php3_fopen_wrapper(file->value.str.val, "r", IGNORE_PATH|IGNORE_URL_WIN, &issock, &socketd); +#endif + if (!fp) { + php3_strip_url_passwd(fn); + php3_error(E_WARNING, + "ImageCreateFromPng: Unable to open %s for reading", fn); + RETURN_FALSE; + } + im = gdImageCreateFromPng (fp); + fflush(fp); + fclose(fp); + ind = php3_list_insert(im, GD_GLOBAL(le_gd)); + RETURN_LONG(ind); +} +/* }}} */ + +/* {{{ proto int imagepng(int im, string filename) +Output image to browser or file */ +void php3_imagepng (INTERNAL_FUNCTION_PARAMETERS) { + pval *imgind, *file; + gdImagePtr im; + char *fn=NULL; + FILE *fp; + int argc; + int ind_type; + int output=1; + GD_TLS_VARS; + argc = ARG_COUNT(ht); + if (argc < 1 || argc > 2 || getParameters(ht, argc, &imgind, &file) == FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_long(imgind); + if (argc == 2) { + convert_to_string(file); + fn = file->value.str.val; + if (!fn || fn == empty_string || _php3_check_open_basedir(fn)) { + php3_error(E_WARNING, "ImagePng: Invalid filename"); + RETURN_FALSE; + } + } + im = php3_list_find(imgind->value.lval, &ind_type); + if (!im || ind_type != GD_GLOBAL(le_gd)) { + php3_error(E_WARNING, "ImagePng: unable to find image pointer"); + RETURN_FALSE; + } + if (argc == 2) { + fp = fopen(fn, "wb"); + if (!fp) { + php3_error(E_WARNING, "ImagePng: unable to open %s for writing", fn); + RETURN_FALSE; + } + gdImagePng (im,fp); + fflush(fp); + fclose(fp); + } + else { + int b; + FILE *tmp; + char buf[4096]; + tmp = tmpfile(); + if (tmp == NULL) { + php3_error(E_WARNING, "Unable to open temporary file"); + RETURN_FALSE; + } + output = php3_header(); + if (output) { + gdImagePng (im, tmp); + fseek(tmp, 0, SEEK_SET); +#if APACHE && defined(CHARSET_EBCDIC) + /* 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) { + php3_write(buf, b); + } + } + fclose(tmp); + /* the temporary file is automatically deleted */ + } + RETURN_TRUE; +} +/* }}} */ + +#else + /* {{{ proto int imagecreatefromgif(string filename) Create a new image from file or URL */ PHP_FUNCTION(imagecreatefromgif ) @@ -410,6 +524,88 @@ PHP_FUNCTION(imagecreatefromgif ) } /* }}} */ +/* {{{ proto int imagegif(int im, string filename) +Output image to browser or file */ +PHP_FUNCTION(imagegif ) +{ + pval *imgind, *file; + gdImagePtr im; + char *fn=NULL; + FILE *fp; + int argc; + int ind_type; + int output=1; + GD_TLS_VARS; + + argc = ARG_COUNT(ht); + if (argc < 1 || argc > 2 || getParameters(ht, argc, &imgind, &file) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(imgind); + + if (argc == 2) { + convert_to_string(file); + fn = file->value.str.val; + if (!fn || fn == empty_string || _php3_check_open_basedir(fn)) { + php_error(E_WARNING, "ImageGif: Invalid filename"); + RETURN_FALSE; + } + } + + im = php3_list_find(imgind->value.lval, &ind_type); + if (!im || ind_type != GD_GLOBAL(le_gd)) { + php_error(E_WARNING, "ImageGif: unable to find image pointer"); + RETURN_FALSE; + } + + if (argc == 2) { + fp = fopen(fn, "wb"); + if (!fp) { + php_error(E_WARNING, "ImageGif: unable to open %s for writing", fn); + RETURN_FALSE; + } + gdImageGif (im,fp); + fflush(fp); + fclose(fp); + } + else { + int b; + FILE *tmp; + char buf[4096]; + + tmp = tmpfile(); + if (tmp == NULL) { + php_error(E_WARNING, "Unable to open temporary file"); + RETURN_FALSE; + } + + output = php3_header(); + + if (output) { + SLS_FETCH(); + + gdImageGif (im, tmp); + fseek(tmp, 0, SEEK_SET); +#if APACHE && defined(CHARSET_EBCDIC) + /* This is a binary file already: avoid EBCDIC->ASCII conversion */ + ap_bsetflag(((request_rec *) SG(server_context))->connection->client, B_EBCDIC2ASCII, 0); +#endif + while ((b = fread(buf, 1, sizeof(buf), tmp)) > 0) { + php3_write(buf, b); + } + } + + fclose(tmp); + /* the temporary file is automatically deleted */ + } + + RETURN_TRUE; +} +/* }}} */ + +#endif /* HAVE_IMAGECREATEFROMPNG */ + /* {{{ proto int imagedestroy(int im) Destroy an image */ PHP_FUNCTION(imagedestroy) @@ -727,86 +923,6 @@ PHP_FUNCTION(imagecolorsforindex) } /* }}} */ -/* {{{ proto int imagegif(int im, string filename) -Output image to browser or file */ -PHP_FUNCTION(imagegif ) -{ - pval *imgind, *file; - gdImagePtr im; - char *fn=NULL; - FILE *fp; - int argc; - int ind_type; - int output=1; - GD_TLS_VARS; - - argc = ARG_COUNT(ht); - if (argc < 1 || argc > 2 || getParameters(ht, argc, &imgind, &file) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_long(imgind); - - if (argc == 2) { - convert_to_string(file); - fn = file->value.str.val; - if (!fn || fn == empty_string || _php3_check_open_basedir(fn)) { - php_error(E_WARNING, "ImageGif: Invalid filename"); - RETURN_FALSE; - } - } - - im = php3_list_find(imgind->value.lval, &ind_type); - if (!im || ind_type != GD_GLOBAL(le_gd)) { - php_error(E_WARNING, "ImageGif: unable to find image pointer"); - RETURN_FALSE; - } - - if (argc == 2) { - fp = fopen(fn, "wb"); - if (!fp) { - php_error(E_WARNING, "ImageGif: unable to open %s for writing", fn); - RETURN_FALSE; - } - gdImageGif (im,fp); - fflush(fp); - fclose(fp); - } - else { - int b; - FILE *tmp; - char buf[4096]; - - tmp = tmpfile(); - if (tmp == NULL) { - php_error(E_WARNING, "Unable to open temporary file"); - RETURN_FALSE; - } - - output = php3_header(); - - if (output) { - SLS_FETCH(); - - gdImageGif (im, tmp); - fseek(tmp, 0, SEEK_SET); -#if APACHE && defined(CHARSET_EBCDIC) - /* This is a binary file already: avoid EBCDIC->ASCII conversion */ - ap_bsetflag(((request_rec *) SG(server_context))->connection->client, B_EBCDIC2ASCII, 0); -#endif - while ((b = fread(buf, 1, sizeof(buf), tmp)) > 0) { - php3_write(buf, b); - } - } - - fclose(tmp); - /* the temporary file is automatically deleted */ - } - - RETURN_TRUE; -} -/* }}} */ - /* {{{ proto int imagesetpixel(int im, int x, int y, int col) Set a single pixel */ PHP_FUNCTION(imagesetpixel) diff --git a/ext/gd/php3_gd.h b/ext/gd/php3_gd.h index d15ff9b9e7..a6d349e252 100644 --- a/ext/gd/php3_gd.h +++ b/ext/gd/php3_gd.h @@ -34,6 +34,7 @@ #ifndef _PHP3_GD_H #define _PHP3_GD_H +#define HAVE_GDIMAGECREATEFROMPNG 1 #if HAVE_LIBTTF|HAVE_LIBFREETYPE #define ENABLE_GD_TTF @@ -92,6 +93,8 @@ PHP_FUNCTION(imagestring); PHP_FUNCTION(imagestringup); PHP_FUNCTION(imagesx); PHP_FUNCTION(imagesy); +PHP_FUNCTION(imagecreatefrompng); +PHP_FUNCTION(imagepng); void php3_free_gd_font(gdFontPtr); void _php3_gdimagecharup(gdImagePtr, gdFontPtr, int, int, int, int); PHP_FUNCTION(imagedashedline);