cvs: /php3/functions gd.c php3_gd.h

From: Date: Mon, 13 Mar 2000 03:30:56 +0000
Subject: cvs: /php3/functions gd.c php3_gd.h
Groups: php.dev 
Request: Send a blank email to php-dev+get-16735@lists.php.net to get a copy of this message
rasmus Sun Mar 12 19:30:56 2000 EDT Modified files: /php3/functions gd.c php3_gd.h Log: Add GD-JPEG support Index: php3/functions/gd.c diff -u php3/functions/gd.c:1.145 php3/functions/gd.c:1.146 --- php3/functions/gd.c:1.145 Sun Feb 20 12:42:14 2000 +++ php3/functions/gd.c Sun Mar 12 19:30:54 2000 @@ -23,13 +23,13 @@ | If you did not, or have any questions about PHP licensing, please | | contact core@php.net. | +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | + | Authors: Rasmus Lerdorf <rasmus@php.net> | | Stig Bakken <ssb@fast.no> | | Jim Winstead <jimw@php.net> | +----------------------------------------------------------------------+ */ -/* $Id: gd.c,v 1.145 2000/02/20 20:42:14 eschmid Exp $ */ +/* $Id: gd.c,v 1.146 2000/03/13 03:30:54 rasmus Exp $ */ /* gd 1.2 is copyright 1994, 1995, Quest Protein Database Center, Cold Spring Harbor Labs. */ @@ -105,6 +105,10 @@ {"imagecreatefrompng", php3_imagecreatefrompng, NULL}, {"imagepng", php3_imagepng, NULL}, #endif +#if HAVE_GD_JPG + {"imagecreatefromjpeg", php3_imagecreatefromjpeg, NULL}, + {"imagejpeg", php3_imagejpeg, NULL}, +#endif {"imagewbmp", php3_imagewbmp, NULL}, {"imagedestroy", php3_imagedestroy, NULL}, {"imagefill", php3_imagefill, NULL}, @@ -378,7 +382,7 @@ #if HAVE_GD_GIF /* {{{ proto int imagecreatefromgif(string filename) - Create a new image from file or URL */ + Create a new image from GIF file or URL */ void php3_imagecreatefromgif (INTERNAL_FUNCTION_PARAMETERS) { pval *file; int ind; @@ -422,7 +426,7 @@ #if HAVE_GD_PNG /* {{{ proto int imagecreatefrompng(string filename) - Create a new image from file or URL */ + Create a new image from PNG file or URL */ void php3_imagecreatefrompng (INTERNAL_FUNCTION_PARAMETERS) { pval *file; int ind; @@ -464,6 +468,50 @@ /* }}} */ #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) { + 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, + "ImageCreateFromJpeg: Unable to open %s for reading", fn); + RETURN_FALSE; + } + + im = gdImageCreateFromJpeg (fp); + + fflush(fp); + fclose(fp); + + ind = php3_list_insert(im, GD_GLOBAL(le_gd)); + + RETURN_LONG(ind); +} +/* }}} */ +#endif /* HAVE_GD_JPG */ + /* {{{ proto int imagedestroy(int im) Destroy an image */ void php3_imagedestroy(INTERNAL_FUNCTION_PARAMETERS) { @@ -937,6 +985,90 @@ } /* }}} */ #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) { + pval *imgind, *file, *qual; + gdImagePtr im; + char *fn=NULL; + FILE *fp; + int argc; + int ind_type; + int output=1, q=-1; + GD_TLS_VARS; + + argc = ARG_COUNT(ht); + if (argc < 1 || argc > 3 || getParameters(ht, argc, &imgind, &file, &qual) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(imgind); + + if (argc == 3) { + convert_to_long(qual); + q = qual->value.lval; + } + + if (argc > 1) { + convert_to_string(file); + fn = file->value.str.val; + if (fn && strlen(fn) && _php3_check_open_basedir(fn)) { + php3_error(E_WARNING, "ImageJpeg: 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, "ImageJpeg: unable to find image pointer"); + RETURN_FALSE; + } + + if (strlen(fn) && argc > 1) { + fp = fopen(fn, "wb"); + if (!fp) { + php3_error(E_WARNING, "ImageJpeg: unable to open %s for writing", fn); + RETURN_FALSE; + } + gdImageJpeg (im,fp,q); + 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) { + gdImageJpeg (im, tmp, q); + 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; +} +/* }}} */ +#endif /* {{{ proto int imagewbmp(int im [, string filename]) Output wbmp image to browser or file */ Index: php3/functions/php3_gd.h diff -u php3/functions/php3_gd.h:1.42 php3/functions/php3_gd.h:1.43 --- php3/functions/php3_gd.h:1.42 Sun Jan 30 12:48:36 2000 +++ php3/functions/php3_gd.h Sun Mar 12 19:30:55 2000 @@ -29,7 +29,7 @@ */ -/* $Id: php3_gd.h,v 1.42 2000/01/30 20:48:36 markonen Exp $ */ +/* $Id: php3_gd.h,v 1.43 2000/03/13 03:30:55 rasmus Exp $ */ #ifndef _PHP3_GD_H #define _PHP3_GD_H @@ -80,6 +80,10 @@ #if HAVE_GD_PNG extern void php3_imagecreatefrompng (INTERNAL_FUNCTION_PARAMETERS); extern void php3_imagepng(INTERNAL_FUNCTION_PARAMETERS); +#endif +#if HAVE_GD_JPG +extern void php3_imagecreatefromjpeg (INTERNAL_FUNCTION_PARAMETERS); +extern void php3_imagejpeg(INTERNAL_FUNCTION_PARAMETERS); #endif extern void php3_imagewbmp(INTERNAL_FUNCTION_PARAMETERS); extern void php3_imagedestroy(INTERNAL_FUNCTION_PARAMETERS);

« previous php.dev (#16735) next »