cvs: php4 /ext/gd/ gd.c php_gd.h
| From: | Jouni Ahto | Date: | Wed, 07 Jun 2000 23:04:39 +0000 |
| Subject: | cvs: php4 /ext/gd/ gd.c php_gd.h | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-79@lists.php.net to get a copy of this message | ||
jah Wed Jun 7 16:04:39 2000 EDT
Modified files:
/php4/ext/gd gd.c php_gd.h
Log:
- Fixed typo in _php_image_output (s/fp/tmp/) causing segfault.
- Fixed bug when calling imagejpeg() with 3 arguments, the second one empty,
introduced yesterday.
- Nuked even more code.
Index: php4/ext/gd/gd.c
diff -u php4/ext/gd/gd.c:1.65 php4/ext/gd/gd.c:1.66
--- php4/ext/gd/gd.c:1.65 Tue Jun 6 17:37:49 2000
+++ php4/ext/gd/gd.c Wed Jun 7 16:04:39 2000
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: gd.c,v 1.65 2000/06/07 00:37:49 jah Exp $ */
+/* $Id: gd.c,v 1.66 2000/06/07 23:04:39 jah Exp $ */
/* gd 1.2 is copyright 1994, 1995, Quest Protein Database Center,
Cold Spring Harbor Labs. */
@@ -424,10 +424,10 @@
/* }}} */
-static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type) {
+static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn,
gdImagePtr (*func_p)()) {
zval **file;
gdImagePtr im;
- char *fn=NULL, *tn=NULL;
+ char *fn=NULL;
FILE *fp;
int issock=0, socketd=0;
GDLS_FETCH();
@@ -444,53 +444,17 @@
#endif
if (!fp) {
php_strip_url_passwd(fn);
- php_error(E_WARNING,
- "ImageCreateFromPng: Unable to open %s for reading", fn);
+ php_error(E_WARNING, "%s: Unable to open '%s' for reading",
get_active_function_name(), fn);
RETURN_FALSE;
}
- switch (image_type) {
-#ifdef HAVE_GD_GIF
- case PHP_GDIMG_TYPE_GIF:
- im = gdImageCreateFromGif(fp);
- tn = "Gif";
- break;
-#endif
-#ifdef HAVE_GD_PNG
- case PHP_GDIMG_TYPE_PNG:
- im = gdImageCreateFromPng(fp);
- tn = "Png";
- break;
-#endif
-#ifdef HAVE_GD_JPG
- case PHP_GDIMG_TYPE_JPG:
- im = gdImageCreateFromJpeg(fp);
- tn = "Jpeg";
- break;
-#endif
-#ifdef HAVE_GD_XBM
- case PHP_GDIMG_TYPE_XBM:
- im = gdImageCreateFromXbm(fp);
- tn = "Xbm";
- break;
-#endif
-#if 0 /* Heck, gd.h misses prototype... fix later.
- Anyway, it wants a filename, not a file pointer,
- so need a tmp file if it's not local. Or easier,
- just document it not accepting URLs...
- */
-#ifdef HAVE_GD_XPM
- case PHP_GDIMG_TYPE_XPM:
- im = gdImageCreateFromXpm(fn);
- tn = "Xpm";
- break;
-#endif
-#endif
- }
+
+ im = (*func_p)(fp);
+
fflush(fp);
fclose(fp);
if (!im) {
- php_error(E_WARNING,"ImageCreateFrom%s: %s is not a valid %s file", tn, fn, tn);
+ php_error(E_WARNING,"%s: '%s' is not a valid %s file",
get_active_function_name, fn, tn);
RETURN_FALSE;
}
@@ -502,9 +466,9 @@
PHP_FUNCTION(imagecreatefromgif)
{
#ifdef HAVE_GD_GIF
- _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_GIF);
+ _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_GIF, "GIF",
gdImageCreateFromGif);
#else /* HAVE_GD_GIF */
- php_error(E_WARNING, "ImageCreateFromGIF: No GIF support in this PHP build");
+ php_error(E_WARNING, "ImageCreateFromGif: No GIF support in this PHP build");
RETURN_FALSE;
#endif /* HAVE_GD_GIF */
}
@@ -515,7 +479,7 @@
PHP_FUNCTION(imagecreatefromjpeg)
{
#ifdef HAVE_GD_JPG
- _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_JPG);
+ _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_JPG, "JPEG",
gdImageCreateFromJpeg);
#else /* HAVE_GD_JPG */
php_error(E_WARNING, "ImageCreateFromJpeg: No JPEG support in this PHP build");
RETURN_FALSE;
@@ -528,7 +492,7 @@
PHP_FUNCTION(imagecreatefrompng)
{
#ifdef HAVE_GD_PNG
- _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_PNG);
+ _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_PNG, "PNG",
gdImageCreateFromPng);
#else /* HAVE_GD_PNG */
php_error(E_WARNING, "ImageCreateFromPng: No PNG support in this PHP build");
RETURN_FALSE;
@@ -541,7 +505,7 @@
PHP_FUNCTION(imagecreatefromxbm)
{
#ifdef HAVE_GD_XBM
- _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_XBM);
+ _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_XBM, "XBM",
gdImageCreateFromXbm);
#else /* HAVE_GD_XBM */
php_error(E_WARNING, "ImageCreateFromXbm: No XBM support in this PHP build");
RETURN_FALSE;
@@ -555,7 +519,7 @@
{
/*
#ifdef HAVE_GD_XPM
- _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_XPM);
+ _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_XPM, "XPM",
gdImageCreateFromXpm);
#else
*/
php_error(E_WARNING, "ImageCreateFromXpm: No XPM support in this PHP build");
@@ -566,14 +530,13 @@
}
/* }}} */
-static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type) {
+static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, void
(*func_p)()) {
zval **imgind, **file, **quality;
gdImagePtr im;
- char *fn = NULL, *tn = NULL;
+ char *fn = NULL;
FILE *fp;
int argc;
int output = 1, q = -1;
- void (*func_p)();
GDLS_FETCH();
argc = ZEND_NUM_ARGS();
@@ -582,48 +545,24 @@
}
ZEND_FETCH_RESOURCE(im, gdImagePtr, imgind, -1, "Image", GDG(le_gd));
- switch (image_type) {
-#ifdef HAVE_GD_GIF
- case PHP_GDIMG_TYPE_GIF:
- func_p = gdImageGif;
- tn = "Gif";
- break;
-#endif
-#ifdef HAVE_GD_PNG
- case PHP_GDIMG_TYPE_PNG:
- func_p = gdImagePng;
- tn = "Png";
- break;
-#endif
-#ifdef HAVE_GD_JPG
- case PHP_GDIMG_TYPE_JPG:
- func_p = gdImageJpeg;
- tn = "Jpeg";
- break;
-#endif
- case PHP_GDIMG_TYPE_WBM:
- func_p = _php_image_output_wbmp;
- tn = "Wbmp";
- break;
- }
-
- if (argc == 3) {
- convert_to_long_ex(quality);
- q = Z_LVAL_PP(quality);
- argc--;
+ if (argc > 1) {
+ convert_to_string_ex(file);
+ fn = Z_STRVAL_PP(file);
+ if (argc == 3) {
+ convert_to_long_ex(quality);
+ q = Z_LVAL_PP(quality);
+ }
}
- if (argc == 2) {
- convert_to_string_ex(file);
- fn = (*file)->value.str.val;
+ if ((argc == 2) || (argc == 3 && Z_STRLEN_PP(file))) {
if (!fn || fn == empty_string || php_check_open_basedir(fn)) {
- php_error(E_WARNING, "Image%s: Invalid filename", fn);
+ php_error(E_WARNING, "%s: invalid filename '%s'",
get_active_function_name(), fn);
RETURN_FALSE;
}
fp = V_FOPEN(fn, "wb");
if (!fp) {
- php_error(E_WARNING, "Image%s: unable to open %s for writing", tn, fn);
+ php_error(E_WARNING, "%s: unable to open '%s' for writing",
get_active_function_name(), fn);
RETURN_FALSE;
}
if (image_type == PHP_GDIMG_TYPE_JPG) {
@@ -637,17 +576,18 @@
int b;
FILE *tmp;
char buf[4096];
+
tmp = tmpfile();
if (tmp == NULL) {
- php_error(E_WARNING, "Unable to open temporary file");
+ php_error(E_WARNING, "%s: unable to open temporary file", get_active_function_name());
RETURN_FALSE;
}
output = php_header();
if (output) {
if (image_type == PHP_GDIMG_TYPE_JPG) {
- (*func_p)(im, fp, q);
+ (*func_p)(im, tmp, q);
} else {
- (*func_p)(im, fp);
+ (*func_p)(im, tmp);
}
fseek(tmp, 0, SEEK_SET);
#if APACHE && defined(CHARSET_EBCDIC)
@@ -665,12 +605,25 @@
RETURN_TRUE;
}
+/* {{{ proto int imagegif(int im [, string filename])
+ Output GIF image to browser or file */
+PHP_FUNCTION(imagegif)
+{
+#ifdef HAVE_GD_GIF
+ _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_GIF, "GIF",
gdImageGif);
+#else /* HAVE_GD_GIF */
+ php_error(E_WARNING, "ImageGif: No GIF support in this PHP build");
+ RETURN_FALSE;
+#endif /* HAVE_GD_GIF */
+}
+/* }}} */
+
/* {{{ proto int imagepng(int im [, string filename])
Output PNG image to browser or file */
PHP_FUNCTION(imagepng)
{
#ifdef HAVE_GD_PNG
- _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_PNG);
+ _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_PNG, "PNG",
gdImagePng);
#else /* HAVE_GD_PNG */
php_error(E_WARNING, "ImagePng: No PNG support in this PHP build");
RETURN_FALSE;
@@ -679,25 +632,12 @@
/* }}} */
-/* {{{ proto int imagegif(int im [, string filename])
- Output GIF image to browser or file */
-PHP_FUNCTION(imagegif)
-{
-#ifdef HAVE_GD_GIF
- _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_PNG);
-#else /* HAVE_GD_GIF */
- php_error(E_WARNING, "ImageGif: No GIF support in this PHP build");
- RETURN_FALSE;
-#endif /* HAVE_GD_GIF */
-}
-/* }}} */
-
/* {{{ proto int imagejpeg(int im [, string filename [, int quality]])
Output JPEG image to browser or file */
PHP_FUNCTION(imagejpeg)
{
#ifdef HAVE_GD_JPG
- _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_JPG);
+ _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_JPG, "JPEG",
gdImageJpeg);
#else /* HAVE_GD_JPG */
php_error(E_WARNING, "ImageJpeg: No JPG support in this PHP build");
RETURN_FALSE;
@@ -709,7 +649,7 @@
Output WBMP image to browser or file */
PHP_FUNCTION(imagewbmp)
{
- _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_WBM);
+ _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_WBM, "WBMP",
_php_image_output_wbmp);
}
/* }}} */
Index: php4/ext/gd/php_gd.h
diff -u php4/ext/gd/php_gd.h:1.9 php4/ext/gd/php_gd.h:1.10
--- php4/ext/gd/php_gd.h:1.9 Tue Jun 6 17:37:49 2000
+++ php4/ext/gd/php_gd.h Wed Jun 7 16:04:39 2000
@@ -29,7 +29,7 @@
*/
-/* $Id: php_gd.h,v 1.9 2000/06/07 00:37:49 jah Exp $ */
+/* $Id: php_gd.h,v 1.10 2000/06/07 23:04:39 jah Exp $ */
#ifndef _PHP_GD_H
#define _PHP_GD_H
@@ -55,10 +55,10 @@
#define PHP_GDIMG_TYPE_GIF 1
#define PHP_GDIMG_TYPE_PNG 2
-#define PHP_GDIMG_TYPE_JPG 4
-#define PHP_GDIMG_TYPE_WBM 8
-#define PHP_GDIMG_TYPE_XBM 16
-#define PHP_GDIMG_TYPE_XPM 32
+#define PHP_GDIMG_TYPE_JPG 3
+#define PHP_GDIMG_TYPE_WBM 4
+#define PHP_GDIMG_TYPE_XBM 5
+#define PHP_GDIMG_TYPE_XPM 6
extern zend_module_entry gd_module_entry;
@@ -140,8 +140,8 @@
PHP_FUNCTION(imagepsbbox);
PHPAPI int phpi_get_le_gd(void);
-static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type);
-static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type);
+static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn,
gdImagePtr (*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);
#ifdef ZTS