Bug #1956: Missing PNG functions for GD

From: Date: Wed, 04 Aug 1999 11:08:58 +0000
Subject: Bug #1956: Missing PNG functions for GD
Groups: php.dev 
Request: Send a blank email to php-dev+get-9494@lists.php.net to get a copy of this message
From: drew@elysium.ltd.uk Operating system: Linux RH6.0 PHP version: PHP Bug Type: Bug description: Missing PNG functions for GD The functions ImageCreateFromPng, and ImagePng are missing so generated grahics cannot be used with GD1.6 and above. Please find attached a diff which adds these functions. Hope this help - Drew diff -rNc php-3.0.12/functions/gd.c php-3.0.12-png/functions/gd.c *** php-3.0.12/functions/gd.c Sat Jul 17 09:11:15 1999 --- php-3.0.12-png/functions/gd.c Wed Aug 4 13:03:45 1999 *************** *** 132,137 **** --- 132,140 ---- /* GIF support is gone from gd-1.6 */ {"imagecreatefromgif", php3_imagecreatefromgif, NULL}, {"imagegif", php3_imagegif, NULL}, + #else + {"imagecreatefrompng", php3_imagecreatefrompng, NULL}, + {"imagepng", php3_imagepng, NULL}, #endif {"imagedestroy", php3_imagedestroy, NULL}, {"imagefill", php3_imagefill, NULL}, *************** *** 481,486 **** --- 484,531 ---- RETURN_LONG(ind); } /* }}} */ + #else + /* {{{ 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); + } + /* }}} */ #endif /* {{{ proto int imagedestroy(int im) *************** *** 851,856 **** --- 896,978 ---- if (output) { 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(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 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 */ diff -rNc php-3.0.12/functions/php3_gd.h php-3.0.12-png/functions/php3_gd.h *** php-3.0.12/functions/php3_gd.h Mon Jul 12 19:34:15 1999 --- php-3.0.12-png/functions/php3_gd.h Wed Aug 4 13:03:54 1999 *************** *** 72,77 **** --- 72,78 ---- extern void php3_imagecopyresized(INTERNAL_FUNCTION_PARAMETERS); extern void php3_imagecreate(INTERNAL_FUNCTION_PARAMETERS); extern void php3_imagecreatefromgif (INTERNAL_FUNCTION_PARAMETERS); + extern void php3_imagecreatefrompng (INTERNAL_FUNCTION_PARAMETERS); extern void php3_imagedestroy(INTERNAL_FUNCTION_PARAMETERS); extern void php3_imagefill(INTERNAL_FUNCTION_PARAMETERS); extern void php3_imagefilledpolygon(INTERNAL_FUNCTION_PARAMETERS); *************** *** 80,85 **** --- 81,87 ---- extern void php3_imagefontwidth(INTERNAL_FUNCTION_PARAMETERS); extern void php3_imagefontheight(INTERNAL_FUNCTION_PARAMETERS); extern void php3_imagegif (INTERNAL_FUNCTION_PARAMETERS); + extern void php3_imagepng (INTERNAL_FUNCTION_PARAMETERS); extern void php3_imageinterlace(INTERNAL_FUNCTION_PARAMETERS); extern void php3_imageline(INTERNAL_FUNCTION_PARAMETERS); extern void php3_imageloadfont(INTERNAL_FUNCTION_PARAMETERS);

« previous php.dev (#9494) next »