#1956 [Com]: Missing PNG functions for GD

From: Date: Sat, 22 Nov 2003 21:56:09 +0000
Subject: #1956 [Com]: Missing PNG functions for GD
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-50853@lists.php.net to get a copy of this message
ID: 1956 Comment by: IceTheNet at hotmail dot com Reported By: drew at elysium dot ltd dot uk Status: Closed Bug Type: Feature/Change Request Operating System: Linux RH6.0 New Comment: same thing happens in windows xp running IIS Warning: imagepng(): Unable to open 'goldengate_thumb.png' for writing in c:\inetpub\wwwroot\GOLDEN.PHP on line 52 Warning: getimagesize(goldengate_thumb.png): failed to open stream: No such file or directory in c:\inetpub\wwwroot\GOLDEN.PHP on line 55 here is the code <?php function describeGDdyn(){ echo "<ul>"; echo "<li>GD support: "; if(function_exists("gd_info")){ echo "<font color=\"#00ff00\">yes</font>"; $info = gd_info(); $keys = array_keys($info); for($i=1;$i<count($keys);$i++){ echo "</li>\n<li>".$keys[$i] .": " . yesNo($info[$keys[$i]]); } }else{ echo "<font color=\"#ff0000\">no</font>"; } echo "</li></ul>"; } function yesNo($bool){ if($bool){ return "<font color=\"#00ff00\"> yes</font>"; }else{ return "<font color=\"#ff0000\"> no</font>"; } } describeGDdyn(); //load the image into memory and get its properties $img = imagecreatefrompng("goldengate.png"); $imgsz = getimagesize("goldengate.png"); //create new image for thumbnail 1/8 the size of the original $thumb = imagecreate($imgsz[0]/8, $imgsz[1]/8); //shrink the original image to 1/8th its size imagecopyresized($thumb, $img, 0, 0, 0, 0, $imgsz[0]/8, $imgsz[1]/8, $imgsz[0], $imgsz[1]); //write the thumbnail to disk imagepng($thumb, "goldengate_thumb.png"); //get the image size of the thumbnail for use in the HTML below $thumbsz = getimagesize("goldengate_thumb.png"); //free resources occupied by the images imagedestroy($img); imagedestroy($thumb); ?> <html> <body> <img src="goldengate.png" <?php echo $imgsz[3] ?>> <img src="goldengate_thumb.png" <?php echo $thumbsz[3] ?>> </body> </html> I have tried everything downgraded or upgraded to slashdots php install still no luck it acctually appears to be a write error but i have given the file permission to Adequately destroy my whole system if a haker gets in. scipt execute read write delete ect. I am a newbie to PHP that is probably why this is in the wrong area but the condition looked simular to what I am facing. I have no ability or knowledge of how to recompile php. Do you have any suggestions. using included php_gd2.dll Previous Comments: ------------------------------------------------------------------------ [1999-09-04 21:51:53] rasmus at cvs dot php dot net weird, the bug type was lost on this one ------------------------------------------------------------------------ [1999-08-04 14:52:23] rasmus at cvs dot php dot net Added - Thanks ------------------------------------------------------------------------ [1999-08-04 07:08:57] drew at elysium dot ltd dot uk 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); ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=1956&edit=1

« previous php.bugs (#50853) next »