cvs: /php4/ext/gd config.m4 gd.c php_gd.h /php4/ext/pdf config.m4

From: Date: Mon, 13 Mar 2000 05:58:50 +0000
Subject: cvs: /php4/ext/gd config.m4 gd.c php_gd.h /php4/ext/pdf config.m4
Groups: php.version4 
Request: Send a blank email to php-version4+get-12017@lists.php.net to get a copy of this message
rasmus Sun Mar 12 21:58:50 2000 EDT Modified files: /php4/ext/gd config.m4 gd.c php_gd.h /php4/ext/pdf config.m4 Log: gd-jpeg support @Add GD-JPEG Support (Rasmus) Index: php4/ext/gd/config.m4 diff -u php4/ext/gd/config.m4:1.25 php4/ext/gd/config.m4:1.26 --- php4/ext/gd/config.m4:1.25 Sun Mar 12 07:52:14 2000 +++ php4/ext/gd/config.m4 Sun Mar 12 21:58:49 2000 @@ -36,6 +36,26 @@ AC_ADD_LIBRARY(png) AC_ADD_LIBRARY(z) fi + + AC_MSG_CHECKING([for libjpeg (needed by gd-1.8+)]) + AC_ARG_WITH(jpeg-dir, + [ --with-jpeg-dir[=DIR] jpeg dir for gd-1.8+],[ + AC_MSG_RESULT(yes) + if test -z $withval; then + withval="/usr/local" + fi + old_LIBS=$LIBS + LIBS="$LIBS -L$withval/lib" + AC_CHECK_LIB(jpeg,jpeg_read_header, [LIBS="$LIBS -L$withval/lib -ljpeg"],[AC_MSG_RESULT(no)],) + LIBS=$old_LIBS + AC_ADD_LIBRARY_WITH_PATH(jpeg, $withval/lib) + LIBS="$LIBS -L$withval/lib -ljpeg" + ],[ + AC_MSG_RESULT(no) + AC_MSG_WARN(If configure fails try --with-jpeg-dir=<DIR>) + ]) + AC_CHECK_LIB(gd, gdImageCreateFromJpeg, [AC_DEFINE(HAVE_GD_JPG, 1, [ ])]) + ac_cv_lib_gd_gdImageLine=yes ;; *) Index: php4/ext/gd/gd.c diff -u php4/ext/gd/gd.c:1.43 php4/ext/gd/gd.c:1.44 --- php4/ext/gd/gd.c:1.43 Sat Mar 4 06:21:22 2000 +++ php4/ext/gd/gd.c Sun Mar 12 21:58:50 2000 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: gd.c,v 1.43 2000/03/04 14:21:22 sas Exp $ */ +/* $Id: gd.c,v 1.44 2000/03/13 05:58:50 rasmus Exp $ */ /* gd 1.2 is copyright 1994, 1995, Quest Protein Database Center, Cold Spring Harbor Labs. */ @@ -116,6 +116,10 @@ PHP_FE(imagecreatefromgif, NULL) PHP_FE(imagegif, NULL) #endif +#ifdef HAVE_GD_JPG + PHP_FE(imagecreatefromjpeg, NULL) + PHP_FE(imagejpeg, NULL) +#endif PHP_FE(imagedestroy, NULL) PHP_FE(imagefill, NULL) PHP_FE(imagefilledpolygon, NULL) @@ -634,6 +638,116 @@ /* }}} */ #endif /* HAVE_GD_GIF */ + +#ifdef HAVE_GD_JPG + +/* {{{ proto int imagecreatefromjpeg(string filename) + Create a new image from JPEG file or URL */ +PHP_FUNCTION(imagecreatefromjpeg) +{ + zval **file; + gdImagePtr im; + char *fn=NULL; + FILE *fp; + int issock=0, socketd=0; + GDLS_FETCH(); + + if (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &file) == FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_string_ex(file); + fn = (*file)->value.str.val; +#if WIN32|WINNT + fp = fopen((*file)->value.str.val, "rb"); +#else + fp = php_fopen_wrapper((*file)->value.str.val, "r", IGNORE_PATH|IGNORE_URL_WIN, &issock, &socketd, NULL); +#endif + if (!fp) { + php_strip_url_passwd(fn); + php_error(E_WARNING, + "ImageCreateFromJpeg: Unable to open %s for reading", fn); + RETURN_FALSE; + } + im = gdImageCreateFromJpeg(fp); + fflush(fp); + fclose(fp); + + ZEND_REGISTER_RESOURCE(return_value, im, GDG(le_gd)); +} +/* }}} */ + +/* {{{ proto int imagejpeg(int im [, string filename [, int quality]]) + Output image to browser or file */ +PHP_FUNCTION(imagejpeg) +{ + zval **imgind, **file, **qual; + gdImagePtr im; + char *fn=NULL; + FILE *fp; + int argc; + int output=1, q=-1; + GDLS_FETCH(); + + argc = ARG_COUNT(ht); + if (argc < 1 || argc > 3 || zend_get_parameters_ex(argc, &imgind, &file, &qual) == FAILURE) { + WRONG_PARAM_COUNT; + } + ZEND_FETCH_RESOURCE(im, gdImagePtr, imgind, -1, "Image", GDG(le_gd)); + + if (argc == 3) { + convert_to_long_ex(qual); + q = (*qual)->value.lval; + } + + if (argc > 1) { + convert_to_string_ex(file); + fn = (*file)->value.str.val; + if (fn && strlen(fn) && php_check_open_basedir(fn)) { + php_error(E_WARNING, "ImageJpeg: Invalid filename"); + RETURN_FALSE; + } + } + + if (argc > 1 && strlen(fn)) { + fp = fopen(fn, "wb"); + if (!fp) { + php_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) { + php_error(E_WARNING, "Unable to open temporary file"); + RETURN_FALSE; + } + output = php_header(); + if (output) { + gdImageJpeg(im, tmp, q); + fseek(tmp, 0, SEEK_SET); +#if APACHE && defined(CHARSET_EBCDIC) + SLS_FETCH(); + /* 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) { + php_write(buf, b); + } + } + fclose(tmp); + /* the temporary file is automatically deleted */ + } + RETURN_TRUE; +} +/* }}} */ + +#endif /* {{{ proto int imagedestroy(int im) Destroy an image */ Index: php4/ext/gd/php_gd.h diff -u php4/ext/gd/php_gd.h:1.5 php4/ext/gd/php_gd.h:1.6 --- php4/ext/gd/php_gd.h:1.5 Mon Feb 28 08:52:03 2000 +++ php4/ext/gd/php_gd.h Sun Mar 12 21:58:50 2000 @@ -29,7 +29,7 @@ */ -/* $Id: php_gd.h,v 1.5 2000/02/28 16:52:03 jah Exp $ */ +/* $Id: php_gd.h,v 1.6 2000/03/13 05:58:50 rasmus Exp $ */ #ifndef _PHP_GD_H #define _PHP_GD_H @@ -90,6 +90,7 @@ PHP_FUNCTION(imagecopyresized); PHP_FUNCTION(imagecreate); PHP_FUNCTION(imagecreatefromgif ); +PHP_FUNCTION(imagecreatefromjpeg ); PHP_FUNCTION(imagedestroy); PHP_FUNCTION(imagefill); PHP_FUNCTION(imagefilledpolygon); @@ -98,6 +99,7 @@ PHP_FUNCTION(imagefontwidth); PHP_FUNCTION(imagefontheight); PHP_FUNCTION(imagegif ); +PHP_FUNCTION(imagejpeg ); PHP_FUNCTION(imageinterlace); PHP_FUNCTION(imageline); PHP_FUNCTION(imageloadfont); Index: php4/ext/pdf/config.m4 diff -u php4/ext/pdf/config.m4:1.11 php4/ext/pdf/config.m4:1.12 --- php4/ext/pdf/config.m4:1.11 Thu Mar 9 06:41:14 2000 +++ php4/ext/pdf/config.m4 Sun Mar 12 21:58:50 2000 @@ -1,4 +1,4 @@ -dnl $Id: config.m4,v 1.11 2000/03/09 14:41:14 steinm Exp $ +dnl $Id: config.m4,v 1.12 2000/03/13 05:58:50 rasmus Exp $ AC_MSG_CHECKING(whether to include Pdflib 3.x support) AC_ARG_WITH(pdflib, @@ -17,7 +17,7 @@ old_LIBS=$LIBS LIBS="$LIBS -ltiff -ljpeg -lpng -lz" AC_CHECK_LIB(pdf, PDF_show_boxed, [AC_DEFINE(HAVE_PDFLIB,1,[ ])], - [AC_MSG_ERROR(pdflib extension requires at least pdflib 3.x. You may as well need libtiff and libjpeg. In such a case use the options --with-tiff-dir=<DIR> and --with-jpeg-dir=<DIR>)]) + [AC_MSG_ERROR(pdflib extension requires at least pdflib 3.x. You may also need libtiff and libjpeg. If so, use the options --with-tiff-dir=<DIR> and --with-jpeg-dir=<DIR>)]) LIBS=$old_LIBS LDFLAGS=$old_LDFLAGS AC_ADD_LIBRARY(pdf)

« previous php.version4 (#12017) next »