cvs: /php3/functions gd.c
| From: | Hartmut Holzgraefe | Date: | Tue, 02 May 2000 14:41:44 +0000 |
| Subject: | cvs: /php3/functions gd.c | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-18352@lists.php.net to get a copy of this message | ||
hholzgra Tue May 2 07:41:44 2000 EDT
Modified files:
/php3/functions gd.c
Log:
calling a function that is not supported in the current build due to a
missing library or unsupported feature (especially GIF-Output)
will now give a slightly more usefull error message than eg.
" Call to undefined function: imagegif()"
(this seemed to confuse a lot of users ....)
Index: php3/functions/gd.c
diff -u php3/functions/gd.c:1.152 php3/functions/gd.c:1.153
--- php3/functions/gd.c:1.152 Mon May 1 15:15:56 2000
+++ php3/functions/gd.c Tue May 2 07:41:44 2000
@@ -29,7 +29,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: gd.c,v 1.152 2000/05/01 22:15:56 rasmus Exp $ */
+/* $Id: gd.c,v 1.153 2000/05/02 14:41:44 hholzgra Exp $ */
/* gd 1.2 is copyright 1994, 1995, Quest Protein Database Center,
Cold Spring Harbor Labs. */
@@ -97,18 +97,12 @@
{"imagecopy", php3_imagecopy, NULL},
{"imagecopyresized", php3_imagecopyresized, NULL},
{"imagecreate", php3_imagecreate, NULL},
-#if HAVE_GD_GIF
{"imagecreatefromgif", php3_imagecreatefromgif, NULL},
{"imagegif", php3_imagegif, NULL},
-#endif
-#if HAVE_GD_PNG
- {"imagecreatefrompng", php3_imagecreatefrompng, NULL},
- {"imagepng", php3_imagepng,
NULL},
-#endif
-#if HAVE_GD_JPG
- {"imagecreatefromjpeg", php3_imagecreatefromjpeg, NULL},
- {"imagejpeg", php3_imagejpeg,
NULL},
-#endif
+ {"imagecreatefrompng", php3_imagecreatefrompng, NULL},
+ {"imagepng", php3_imagepng,
NULL},
+ {"imagecreatefromjpeg", php3_imagecreatefromjpeg, NULL},
+ {"imagejpeg", php3_imagejpeg,
NULL},
{"imagewbmp", php3_imagewbmp, NULL},
{"imagedestroy", php3_imagedestroy, NULL},
{"imagefill", php3_imagefill, NULL},
@@ -129,11 +123,8 @@
{"imagesy", php3_imagesyfn, NULL},
{"imagedashedline", php3_imagedashedline, NULL},
{"imagegammacorrect", php3_imagegammacorrect, NULL},
-#if HAVE_LIBTTF|HAVE_LIBFREETYPE
{"imagettfbbox", php3_imagettfbbox, NULL},
{"imagettftext", php3_imagettftext, NULL},
-#endif
-#if HAVE_LIBT1
{"imagepsloadfont", php3_imagepsloadfont, NULL},
{"imagepsfreefont", php3_imagepsfreefont, NULL},
/* The function in t1lib which this function uses seem to be buggy...
@@ -144,7 +135,6 @@
{"imagepsslantfont", php3_imagepsslantfont, NULL},
{"imagepsbbox", php3_imagepsbbox, NULL},
{"imagepstext", php3_imagepstext, NULL},
-#endif
{NULL, NULL, NULL}
};
@@ -378,10 +368,10 @@
}
/* }}} */
-#if HAVE_GD_GIF
/* {{{ proto int imagecreatefromgif(string filename)
Create a new image from GIF file or URL */
void php3_imagecreatefromgif (INTERNAL_FUNCTION_PARAMETERS) {
+#if HAVE_GD_GIF
pval *file;
int ind;
gdImagePtr im;
@@ -422,14 +412,18 @@
ind = php3_list_insert(im, GD_GLOBAL(le_gd));
RETURN_LONG(ind);
+#else /* HAVE_GD_GIF */
+ php3_error(E_WARNING, "ImageCreateFromGif: No GIF support in this PHP build");
+ RETURN_FALSE;
+#endif /* HAVE_GD_GIF */
}
/* }}} */
-#endif /* HAVE_GD_GIF */
-#if HAVE_GD_PNG
+
/* {{{ proto int imagecreatefrompng(string filename)
Create a new image from PNG file or URL */
void php3_imagecreatefrompng (INTERNAL_FUNCTION_PARAMETERS) {
+#if HAVE_GD_PNG
pval *file;
int ind;
gdImagePtr im;
@@ -469,14 +463,17 @@
ind = php3_list_insert(im, GD_GLOBAL(le_gd));
RETURN_LONG(ind);
+#else /* HAVE_GD_PNG */
+ php3_error(E_WARNING, "ImageCreateFromPng: No PNG support in this PHP build");
+ RETURN_FALSE;
+#endif /* HAVE_GD_PNG */
}
/* }}} */
-#endif /* HAVE_GD_PNG */
-#if HAVE_GD_JPG
/* {{{ proto int imagecreatefromjpeg(string filename)
Create a new image from JPEG file or URL */
void php3_imagecreatefromjpeg (INTERNAL_FUNCTION_PARAMETERS) {
+#if HAVE_GD_JPG
pval *file;
int ind;
gdImagePtr im;
@@ -518,9 +515,12 @@
ind = php3_list_insert(im, GD_GLOBAL(le_gd));
RETURN_LONG(ind);
+#else /* HAVE_GD_JPG */
+ php3_error(E_WARNING, "ImageCreateFromJpeg: No JPG support in this PHP build");
+ RETURN_FALSE;
+#endif /* HAVE_GD_JPG */
}
/* }}} */
-#endif /* HAVE_GD_JPG */
/* {{{ proto int imagedestroy(int im)
Destroy an image */
@@ -830,10 +830,10 @@
}
/* }}} */
-#if HAVE_GD_GIF
/* {{{ proto int imagegif(int im [, string filename])
Output GIF image to browser or file */
void php3_imagegif (INTERNAL_FUNCTION_PARAMETERS) {
+#if HAVE_GD_GIF
pval *imgind, *file;
gdImagePtr im;
char *fn=NULL;
@@ -913,14 +913,17 @@
}
RETURN_TRUE;
+#else /* HAVE_GD_GIF */
+ php3_error(E_WARNING, "ImageGif: No GIF support in this PHP build");
+ RETURN_FALSE;
+#endif /* HAVE_GD_GIF */
}
/* }}} */
-#endif /* HAVE_GD_GIF */
-#if HAVE_GD_PNG
/* {{{ proto int imagepng(int im [, string filename])
Output PNG image to browser or file */
void php3_imagepng (INTERNAL_FUNCTION_PARAMETERS) {
+#if HAVE_GD_PNG
pval *imgind, *file;
gdImagePtr im;
char *fn=NULL;
@@ -992,14 +995,17 @@
}
RETURN_TRUE;
+#else /* HAVE_GD_PNG */
+ php3_error(E_WARNING, "ImagePng: No PNG support in this PHP build");
+ RETURN_FALSE;
+#endif /* HAVE_GD_PNG */
}
/* }}} */
-#endif /* HAVE_GD_PNG */
-#if HAVE_GD_JPG
/* {{{ proto int imagejpeg(int im [, string filename [, int quality]])
Output JPEG image to browser or file */
void php3_imagejpeg (INTERNAL_FUNCTION_PARAMETERS) {
+#if HAVE_GD_JPG
pval *imgind, *file, *qual;
gdImagePtr im;
char *fn=NULL;
@@ -1076,9 +1082,12 @@
}
RETURN_TRUE;
+#else /* HAVE_GD_JPG */
+ php3_error(E_WARNING, "ImageJpg: No JPG support in this PHP build");
+ RETURN_FALSE;
+#endif /* HAVE_GD_JPG */
}
/* }}} */
-#endif
/* {{{ proto int imagewbmp(int im [, string filename])
Output WBMP image to browser or file */
@@ -2120,15 +2129,20 @@
/* }}} */
#if HAVE_LIBTTF|HAVE_LIBFREETYPE
-
#define TTFTEXT_DRAW 0
#define TTFTEXT_BBOX 1
+#endif
/* {{{ proto array imagettfbbox(int size, int angle, string font_file, string text)
Give the bounding box of a text using TrueType fonts */
void php3_imagettfbbox(INTERNAL_FUNCTION_PARAMETERS)
{
+#if HAVE_LIBTTF|HAVE_LIBFREETYPE
php3_imagettftext_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, TTFTEXT_BBOX);
+#else
+ php3_error(E_WARNING, "ImageTtfBBox: No TTF support in this PHP build");
+ RETURN_FALSE;
+#endif
}
/* }}} */
@@ -2136,10 +2150,17 @@
Write text to the image using a TrueType font */
void php3_imagettftext(INTERNAL_FUNCTION_PARAMETERS)
{
+#if HAVE_LIBTTF|HAVE_LIBFREETYPE
php3_imagettftext_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, TTFTEXT_DRAW);
+#else
+ php3_error(E_WARNING, "ImageTtfBBox: No TTF support in this PHP build");
+ RETURN_FALSE;
+#endif
}
/* }}} */
+#if HAVE_LIBTTF|HAVE_LIBFREETYPE
+
static
void php3_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int mode)
{
@@ -2225,9 +2246,12 @@
T1_DeleteEncoding(enc);
}
+#endif
+
/* {{{ proto int imagepsloadfont(string pathname)
Load a new font from specified file */
void php3_imagepsloadfont(INTERNAL_FUNCTION_PARAMETERS) {
+#if HAVE_LIBT1
pval *file;
int l_ind;
gd_ps_font *f_ind;
@@ -2265,6 +2289,10 @@
f_ind->extend = 1;
l_ind = php3_list_insert(f_ind, GD_GLOBAL(le_ps_font));
RETURN_LONG(l_ind);
+#else /* HAVE_LIBT1 */
+ php3_error(E_WARNING, "ImagePsLoadFont: No T1lib support in this PHP build");
+ RETURN_FALSE;
+#endif /* HAVE_LIBT1 */
}
/* }}} */
@@ -2273,6 +2301,7 @@
Make a copy of a font for purposes like extending or reenconding */
/*
void php3_imagepscopyfont(INTERNAL_FUNCTION_PARAMETERS) {
+#if HAVE_LIBT1
pval *fnt;
int l_ind, type;
gd_ps_font *nf_ind, *of_ind;
@@ -2319,6 +2348,10 @@
nf_ind->extend = 1;
l_ind = php3_list_insert(nf_ind, GD_GLOBAL(le_ps_font));
RETURN_LONG(l_ind);
+#else
+ php3_error(E_WARNING, "ImagePsCopyFont: No T1lib support in this PHP build");
+ RETURN_FALSE;
+#endif
}
*/
/* }}} */
@@ -2326,6 +2359,7 @@
/* {{{ proto bool imagepsfreefont(int font_index)
Free memory used by a font */
void php3_imagepsfreefont(INTERNAL_FUNCTION_PARAMETERS) {
+#if HAVE_LIBT1
pval *fnt;
int type;
@@ -2344,12 +2378,17 @@
php3_list_delete(fnt->value.lval);
RETURN_TRUE;
+#else
+ php3_error(E_WARNING, "ImagePsFreeFont: No T1lib support in this PHP build");
+ RETURN_FALSE;
+#endif
}
/* }}} */
/* {{{ proto bool imagepsencodefont(int font_index, string filename)
To change a fonts character encoding vector */
void php3_imagepsencodefont(INTERNAL_FUNCTION_PARAMETERS) {
+#if HAVE_LIBT1
pval *fnt, *enc;
char **enc_vector;
int type;
@@ -2382,12 +2421,17 @@
}
php3_list_insert(enc_vector, GD_GLOBAL(le_ps_enc));
RETURN_TRUE;
+#else
+ php3_error(E_WARNING, "ImagePsEncodeFont: No T1lib support in this PHP build");
+ RETURN_FALSE;
+#endif
}
/* }}} */
/* {{{ proto bool imagepsextendfont(int font_index, double extend)
Extend or or condense (if extend < 1) a font */
void php3_imagepsextendfont(INTERNAL_FUNCTION_PARAMETERS) {
+#if HAVE_LIBT1
pval *fnt, *ext;
int type;
gd_ps_font *f_ind;
@@ -2409,12 +2453,17 @@
if (T1_ExtendFont(f_ind->font_id, ext->value.dval) != 0) RETURN_FALSE;
f_ind->extend = ext->value.dval;
RETURN_TRUE;
+#else
+ php3_error(E_WARNING, "ImagePsExtendFont: No T1lib support in this PHP build");
+ RETURN_FALSE;
+#endif
}
/* }}} */
/* {{{ proto bool imagepsslantfont(int font_index, double slant)
Slant a font */
void php3_imagepsslantfont(INTERNAL_FUNCTION_PARAMETERS) {
+#if HAVE_LIBT1
pval *fnt, *slt;
int type;
gd_ps_font*f_ind;
@@ -2435,12 +2484,17 @@
if (T1_SlantFont(f_ind->font_id, slt->value.dval) != 0) RETURN_FALSE;
RETURN_TRUE;
+#else
+ php3_error(E_WARNING, "ImagePsSlantFont: No T1lib support in this PHP build");
+ RETURN_FALSE;
+#endif
}
/* }}} */
/* {{{ proto array imagepstext(int image, string text, int font, int size, int xcoord, int ycoord
[, int space, int tightness, double angle, int antialias])
Rasterize a string over an image */
void php3_imagepstext(INTERNAL_FUNCTION_PARAMETERS) {
+#if HAVE_LIBT1
pval *img, *str, *fnt, *sz, *fg, *bg, *sp, *px, *py, *aas, *wd, *ang;
int i, j, x, y;
int space, type;
@@ -2603,12 +2657,17 @@
add_next_index_long(return_value, str_img->metrics.rightSideBearing);
add_next_index_long(return_value, str_img->metrics.ascent);
+#else
+ php3_error(E_WARNING, "ImagePsText: No T1lib support in this PHP build");
+ RETURN_FALSE;
+#endif
}
/* }}} */
/* {{{ proto array imagepsbbox(string text, int font, int size [, int space, int tightness, int
angle])
Return the bounding box needed by a string if rasterized */
void php3_imagepsbbox(INTERNAL_FUNCTION_PARAMETERS) {
+#if HAVE_LIBT1
pval *str, *fnt, *sz, *sp, *wd, *ang;
int i, space, add_width, char_width, amount_kern, type;
int cur_x, cur_y, dx, dy;
@@ -2716,10 +2775,13 @@
add_next_index_long(return_value, (int) ceil(((double) str_bbox.lly)*sz->value.lval/1000));
add_next_index_long(return_value, (int) ceil(((double) str_bbox.urx)*sz->value.lval/1000));
add_next_index_long(return_value, (int) ceil(((double) str_bbox.ury)*sz->value.lval/1000));
+#else
+ php3_error(E_WARNING, "ImagePsBBox: No T1lib support in this PHP build");
+ RETURN_FALSE;
+#endif
}
/* }}} */
-#endif /* HAVE_LIBT1 */
#endif