diff options
author | Stanislav Malyshev <stas@php.net> | 2000-09-26 09:08:02 +0000 |
---|---|---|
committer | Stanislav Malyshev <stas@php.net> | 2000-09-26 09:08:02 +0000 |
commit | 9ff7f19e32058cc6dc405c231d99120d060db301 (patch) | |
tree | cdc55a80b855dde5603dea26e91b115563862ca4 /ext/gd | |
parent | 12aca26b5b83c73c642748c704ed7ac1e757b8ce (diff) | |
download | php-git-9ff7f19e32058cc6dc405c231d99120d060db301.tar.gz |
Add URL support for GD
Diffstat (limited to 'ext/gd')
-rw-r--r-- | ext/gd/gd.c | 74 | ||||
-rw-r--r-- | ext/gd/php_gd.h | 2 |
2 files changed, 64 insertions, 12 deletions
diff --git a/ext/gd/gd.c b/ext/gd/gd.c index 3585407390..20933f698d 100644 --- a/ext/gd/gd.c +++ b/ext/gd/gd.c @@ -30,6 +30,7 @@ #include <math.h> #include "SAPI.h" #include "php_gd.h" +#include "ext/standard/fsock.h" #if HAVE_SYS_WAIT_H # include <sys/wait.h> @@ -64,6 +65,19 @@ static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int); #endif +#ifdef GD2_VERS +/* it's >= 1.5, i.e. has IOCtx */ +#define USE_GD_IOCTX 1 +#else +#undef USE_GD_IOCTX +#endif + +#ifndef USE_GD_IOCTX +#define gdImageCreateFromJpegCtx NULL +#define gdImageCreateFromPngCtx NULL +#define gdImageCreateFromWBMPCtx NULL +#endif + #ifdef THREAD_SAFE DWORD GDlibTls; static int numthreads=0; @@ -455,7 +469,7 @@ PHP_FUNCTION(imagetypes) RETURN_LONG(ret); } -static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, gdImagePtr (*func_p)()) { +static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, gdImagePtr (*func_p)(), gdImagePtr (*ioctx_func_p)()) { zval **file; gdImagePtr im; char *fn=NULL; @@ -473,16 +487,54 @@ static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type, #else fp = php_fopen_wrapper(Z_STRVAL_PP(file), "r", IGNORE_PATH|IGNORE_URL_WIN, &issock, &socketd, NULL); #endif - if (!fp) { + if (!fp && !socketd) { php_strip_url_passwd(fn); php_error(E_WARNING, "%s: Unable to open '%s' for reading", get_active_function_name(), fn); RETURN_FALSE; } - im = (*func_p)(fp); +#ifndef USE_GD_IOCTX + ioctx_func_p = NULL; /* don't allow sockets without IOCtx */ +#endif - fflush(fp); - fclose(fp); + if(issock && !ioctx_func_p) { + php_error(E_WARNING, "%s: Sockets are not supported for image type '%s'",get_active_function_name(),tn); + RETURN_FALSE; + } + + if(issock && socketd) { +#ifdef USE_GD_IOCTX + gdIOCtx* io_ctx; +#define CHUNK_SIZE 8192 + int read_len=0,buff_len=0,buff_size=5*CHUNK_SIZE; + char *buff,*buff_cur; + + buff = malloc(buff_size); /* Should be malloc! GD uses free */ + buff_cur = buff; + + do { + if(buff_len > buff_size - CHUNK_SIZE) { + buff_size += CHUNK_SIZE; + buff = realloc(buff, buff_size); + } + read_len = SOCK_FREAD(buff_cur, CHUNK_SIZE, socketd); + buff_len += read_len; + buff_cur += read_len; + } while(read_len>0); + + io_ctx = gdNewDynamicCtx(buff_len,buff); + if(!io_ctx) { + php_error(E_WARNING,"%s: Cannot allocate GD IO context",get_active_function_name()); + } + im = (*ioctx_func_p)(io_ctx); + io_ctx->free(io_ctx); +#endif + } 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(), fn, tn); @@ -497,7 +549,7 @@ static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type, PHP_FUNCTION(imagecreatefromgif) { #ifdef HAVE_GD_GIF - _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_GIF, "GIF", gdImageCreateFromGif); + _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_GIF, "GIF", gdImageCreateFromGif,NULL); #else /* HAVE_GD_GIF */ php_error(E_WARNING, "ImageCreateFromGif: No GIF support in this PHP build"); RETURN_FALSE; @@ -510,7 +562,7 @@ PHP_FUNCTION(imagecreatefromgif) PHP_FUNCTION(imagecreatefromjpeg) { #ifdef HAVE_GD_JPG - _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_JPG, "JPEG", gdImageCreateFromJpeg); + _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; @@ -523,7 +575,7 @@ PHP_FUNCTION(imagecreatefromjpeg) PHP_FUNCTION(imagecreatefrompng) { #ifdef HAVE_GD_PNG - _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_PNG, "PNG", gdImageCreateFromPng); + _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; @@ -536,7 +588,7 @@ PHP_FUNCTION(imagecreatefrompng) PHP_FUNCTION(imagecreatefromxbm) { #ifdef HAVE_GD_XBM - _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_XBM, "XBM", gdImageCreateFromXbm); + _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; @@ -550,7 +602,7 @@ PHP_FUNCTION(imagecreatefromxpm) { /* #ifdef HAVE_GD_XPM - _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_XPM, "XPM", gdImageCreateFromXpm); + _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"); @@ -566,7 +618,7 @@ PHP_FUNCTION(imagecreatefromxpm) PHP_FUNCTION(imagecreatefromwbmp) { #ifdef HAVE_GD_WBMP - _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_WBM, "WBMP", gdImageCreateFromWBMP); + _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; diff --git a/ext/gd/php_gd.h b/ext/gd/php_gd.h index 12a9da88ce..d6e0b904b1 100644 --- a/ext/gd/php_gd.h +++ b/ext/gd/php_gd.h @@ -128,7 +128,7 @@ PHP_FUNCTION(imagepstext); PHP_FUNCTION(imagepsbbox); PHPAPI int phpi_get_le_gd(void); -static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, gdImagePtr (*func_p)()); +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 void _php_image_output_wbmp(gdImagePtr im, FILE *fp); |