php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #1956 Missing PNG functions for GD
Submitted: 1999-08-04 07:08 UTC Modified: 1999-09-04 21:51 UTC
From: drew at elysium dot ltd dot uk Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: OS: Linux RH6.0
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: drew at elysium dot ltd dot uk
New email:
PHP Version: OS:

 

 [1999-08-04 07:08 UTC] 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);

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-08-04 14:52 UTC] rasmus at cvs dot php dot net
Added - Thanks
 [1999-09-04 21:51 UTC] rasmus at cvs dot php dot net
weird, the bug type was lost on this one
 [2003-11-22 16:56 UTC] IceTheNet at hotmail dot com
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
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 19:01:28 2024 UTC