1999-04-16 12:15:38 +00:00
/*
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2004-01-08 08:18:22 +00:00
| PHP Version 5 |
1999-04-16 12:15:38 +00:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2006-01-01 13:10:10 +00:00
| Copyright ( c ) 1997 - 2006 The PHP Group |
1999-04-16 12:15:38 +00:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2006-01-01 13:10:10 +00:00
| This source file is subject to version 3.01 of the PHP license , |
1999-07-16 13:13:16 +00:00
| that is bundled with this package in the file LICENSE , and is |
2003-06-10 20:04:29 +00:00
| available through the world - wide - web at the following url : |
2006-01-01 13:10:10 +00:00
| http : //www.php.net/license/3_01.txt |
1999-07-16 13:13:16 +00:00
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world - wide - web , please send a note to |
| license @ php . net so we can mail you a copy immediately . |
1999-04-16 12:15:38 +00:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2002-02-28 08:29:35 +00:00
| Authors : Rasmus Lerdorf < rasmus @ php . net > |
2003-03-18 12:06:09 +00:00
| Stig Bakken < ssb @ php . net > |
1999-04-16 12:15:38 +00:00
| Jim Winstead < jimw @ php . net > |
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
*/
/* $Id$ */
2003-02-26 23:22:09 +00:00
/* gd 1.2 is copyright 1994, 1995, Quest Protein Database Center,
1999-04-16 12:15:38 +00:00
Cold Spring Harbor Labs . */
/* Note that there is no code from the gd package in this file */
1999-04-23 20:06:01 +00:00
2001-05-24 10:07:29 +00:00
# ifdef HAVE_CONFIG_H
# include "config.h"
# endif
2006-01-27 20:48:42 +00:00
# ifdef HAVE_GD_PNG
/* needs to be first */
# include <png.h>
# endif
1999-04-16 12:15:38 +00:00
# include "php.h"
2006-02-02 20:30:54 +00:00
# include "php_ini.h"
1999-04-22 00:25:57 +00:00
# include "ext/standard/head.h"
1999-04-16 12:15:38 +00:00
# include <math.h>
1999-04-26 17:26:37 +00:00
# include "SAPI.h"
1999-12-04 19:19:57 +00:00
# include "php_gd.h"
2000-11-29 15:25:42 +00:00
# include "ext/standard/info.h"
2004-08-16 23:07:42 +00:00
# include "php_open_temporary_file.h"
1999-04-16 12:15:38 +00:00
# if HAVE_SYS_WAIT_H
# include <sys / wait.h>
# endif
# if HAVE_UNISTD_H
# include <unistd.h>
# endif
2000-06-15 23:45:05 +00:00
# ifdef PHP_WIN32
1999-04-16 12:15:38 +00:00
# include <io.h>
# include <fcntl.h>
# endif
# if HAVE_LIBGD
2000-04-05 22:30:19 +00:00
2000-11-29 15:25:42 +00:00
static int le_gd , le_gd_font ;
# if HAVE_LIBT1
2002-06-28 12:46:07 +00:00
# include <t1lib.h>
2000-11-29 15:25:42 +00:00
static int le_ps_font , le_ps_enc ;
2002-06-28 12:35:30 +00:00
static void php_free_ps_font ( zend_rsrc_list_entry * rsrc TSRMLS_DC ) ;
static void php_free_ps_enc ( zend_rsrc_list_entry * rsrc TSRMLS_DC ) ;
2000-11-29 15:25:42 +00:00
# endif
2000-04-05 22:30:19 +00:00
1999-04-16 12:15:38 +00:00
# include <gd.h>
# include <gdfontt.h> /* 1 Tiny font */
# include <gdfonts.h> /* 2 Small font */
# include <gdfontmb.h> /* 3 Medium bold font */
# include <gdfontl.h> /* 4 Large font */
# include <gdfontg.h> /* 5 Giant font */
2002-06-26 18:32:27 +00:00
# include "libgd/wbmp.h"
2005-12-14 22:33:34 +00:00
1999-07-23 15:18:37 +00:00
# ifdef ENABLE_GD_TTF
2003-09-09 19:08:30 +00:00
# ifdef HAVE_LIBFREETYPE
2003-12-18 08:17:45 +00:00
# include <ft2build.h>
# include FT_FREETYPE_H
2003-09-09 19:08:30 +00:00
# else
# endif
1999-04-16 12:15:38 +00:00
# endif
# ifndef M_PI
# define M_PI 3.14159265358979323846
# endif
1999-07-23 15:18:37 +00:00
# ifdef ENABLE_GD_TTF
2001-07-05 21:23:28 +00:00
static void php_imagettftext_common ( INTERNAL_FUNCTION_PARAMETERS , int , int ) ;
1999-04-16 12:15:38 +00:00
# endif
2001-02-01 15:40:35 +00:00
# include "gd_ctx.c"
2000-09-26 09:08:02 +00:00
2002-06-28 12:35:30 +00:00
# if HAVE_COLORCLOSESTHWB
int gdImageColorClosestHWB ( gdImagePtr im , int r , int g , int b ) ;
# endif
2002-11-13 20:02:58 +00:00
/* Section Filters Declarations */
/* IMPORTANT NOTE FOR NEW FILTER
* Do not forget to update :
* IMAGE_FILTER_MAX : define the last filter index
* IMAGE_FILTER_MAX_ARGS : define the biggest amout of arguments
* image_filter array in PHP_FUNCTION ( imagefilter )
* */
# if HAVE_GD_BUNDLED
# define IMAGE_FILTER_NEGATE 0
# define IMAGE_FILTER_GRAYSCALE 1
# define IMAGE_FILTER_BRIGHTNESS 2
# define IMAGE_FILTER_CONTRAST 3
# define IMAGE_FILTER_COLORIZE 4
# define IMAGE_FILTER_EDGEDETECT 5
# define IMAGE_FILTER_EMBOSS 6
# define IMAGE_FILTER_GAUSSIAN_BLUR 7
# define IMAGE_FILTER_SELECTIVE_BLUR 8
# define IMAGE_FILTER_MEAN_REMOVAL 9
# define IMAGE_FILTER_SMOOTH 10
# define IMAGE_FILTER_MAX 10
# define IMAGE_FILTER_MAX_ARGS 5
static void php_image_filter_negate ( INTERNAL_FUNCTION_PARAMETERS ) ;
static void php_image_filter_grayscale ( INTERNAL_FUNCTION_PARAMETERS ) ;
static void php_image_filter_brightness ( INTERNAL_FUNCTION_PARAMETERS ) ;
static void php_image_filter_contrast ( INTERNAL_FUNCTION_PARAMETERS ) ;
static void php_image_filter_colorize ( INTERNAL_FUNCTION_PARAMETERS ) ;
static void php_image_filter_edgedetect ( INTERNAL_FUNCTION_PARAMETERS ) ;
static void php_image_filter_emboss ( INTERNAL_FUNCTION_PARAMETERS ) ;
static void php_image_filter_gaussian_blur ( INTERNAL_FUNCTION_PARAMETERS ) ;
static void php_image_filter_selective_blur ( INTERNAL_FUNCTION_PARAMETERS ) ;
static void php_image_filter_mean_removal ( INTERNAL_FUNCTION_PARAMETERS ) ;
static void php_image_filter_smooth ( INTERNAL_FUNCTION_PARAMETERS ) ;
# endif
/* End Section filters declarations */
2001-07-30 17:29:57 +00:00
static gdImagePtr _php_image_create_from_string ( zval * * Data , char * tn , gdImagePtr ( * ioctx_func_p ) ( ) TSRMLS_DC ) ;
2001-04-06 18:01:52 +00:00
static void _php_image_create_from ( INTERNAL_FUNCTION_PARAMETERS , int image_type , char * tn , gdImagePtr ( * func_p ) ( ) , gdImagePtr ( * ioctx_func_p ) ( ) ) ;
static void _php_image_output ( INTERNAL_FUNCTION_PARAMETERS , int image_type , char * tn , void ( * func_p ) ( ) ) ;
2003-03-20 01:12:57 +00:00
static int _php_image_type ( char data [ 8 ] ) ;
2001-04-06 18:01:52 +00:00
static void _php_image_convert ( INTERNAL_FUNCTION_PARAMETERS , int image_type ) ;
2001-04-01 05:42:07 +00:00
static void _php_image_bw_convert ( gdImagePtr im_org , gdIOCtx * out , int threshold ) ;
2001-02-01 15:40:35 +00:00
2001-06-05 13:12:10 +00:00
/* {{{ gd_functions[]
*/
2005-12-06 02:28:26 +00:00
zend_function_entry gd_functions [ ] = {
2002-11-12 11:49:11 +00:00
PHP_FE ( gd_info , NULL )
1999-07-27 19:44:46 +00:00
PHP_FE ( imagearc , NULL )
2002-07-26 13:24:45 +00:00
PHP_FE ( imageellipse , NULL )
1999-07-27 19:44:46 +00:00
PHP_FE ( imagechar , NULL )
PHP_FE ( imagecharup , NULL )
2002-12-06 02:16:06 +00:00
PHP_FE ( imagecolorat , NULL )
1999-07-27 19:44:46 +00:00
PHP_FE ( imagecolorallocate , NULL )
2000-06-25 02:55:31 +00:00
PHP_FE ( imagepalettecopy , NULL )
2002-06-27 23:05:11 +00:00
PHP_FE ( imagecreatefromstring , NULL )
1999-07-27 19:44:46 +00:00
PHP_FE ( imagecolorclosest , NULL )
2002-06-24 19:31:44 +00:00
# if HAVE_COLORCLOSESTHWB
2000-06-25 02:55:31 +00:00
PHP_FE ( imagecolorclosesthwb , NULL )
2002-06-24 19:31:44 +00:00
# endif
1999-07-27 19:44:46 +00:00
PHP_FE ( imagecolordeallocate , NULL )
PHP_FE ( imagecolorresolve , NULL )
PHP_FE ( imagecolorexact , NULL )
PHP_FE ( imagecolorset , NULL )
PHP_FE ( imagecolortransparent , NULL )
PHP_FE ( imagecolorstotal , NULL )
PHP_FE ( imagecolorsforindex , NULL )
PHP_FE ( imagecopy , NULL )
2000-06-25 02:55:31 +00:00
PHP_FE ( imagecopymerge , NULL )
2002-06-24 19:31:44 +00:00
PHP_FE ( imagecopymergegray , NULL )
1999-07-27 19:44:46 +00:00
PHP_FE ( imagecopyresized , NULL )
PHP_FE ( imagecreate , NULL )
2001-04-13 12:00:12 +00:00
PHP_FE ( imagecreatetruecolor , NULL )
2002-12-11 20:44:44 +00:00
PHP_FE ( imageistruecolor , NULL )
2001-05-29 07:46:07 +00:00
PHP_FE ( imagetruecolortopalette , NULL )
2001-04-13 12:00:12 +00:00
PHP_FE ( imagesetthickness , NULL )
PHP_FE ( imagefilledarc , NULL )
2002-06-25 09:00:09 +00:00
PHP_FE ( imagefilledellipse , NULL )
2001-04-13 12:00:12 +00:00
PHP_FE ( imagealphablending , NULL )
2003-02-26 23:22:09 +00:00
PHP_FE ( imagesavealpha , NULL )
2003-01-26 01:15:02 +00:00
PHP_FE ( imagecolorallocatealpha , NULL )
2001-05-29 07:46:07 +00:00
PHP_FE ( imagecolorresolvealpha , NULL )
PHP_FE ( imagecolorclosestalpha , NULL )
2001-04-13 12:00:12 +00:00
PHP_FE ( imagecolorexactalpha , NULL )
PHP_FE ( imagecopyresampled , NULL )
2002-06-24 19:31:44 +00:00
2002-10-29 01:15:44 +00:00
# ifdef HAVE_GD_BUNDLED
PHP_FE ( imagerotate , NULL )
2002-12-11 20:44:44 +00:00
PHP_FE ( imageantialias , NULL )
2002-10-29 01:15:44 +00:00
# endif
2002-06-24 19:31:44 +00:00
# if HAVE_GD_IMAGESETTILE
2001-05-29 07:46:07 +00:00
PHP_FE ( imagesettile , NULL )
2002-06-24 19:31:44 +00:00
# endif
2001-04-13 12:00:12 +00:00
2002-06-24 19:31:44 +00:00
# if HAVE_GD_IMAGESETBRUSH
2001-04-13 12:00:12 +00:00
PHP_FE ( imagesetbrush , NULL )
2002-06-24 19:31:44 +00:00
# endif
2001-04-13 12:00:12 +00:00
PHP_FE ( imagesetstyle , NULL )
2002-03-02 12:32:31 +00:00
# ifdef HAVE_GD_PNG
1999-10-17 14:57:49 +00:00
PHP_FE ( imagecreatefrompng , NULL )
2002-03-02 12:32:31 +00:00
# endif
# ifdef HAVE_GD_GIF_READ
1999-07-27 19:44:46 +00:00
PHP_FE ( imagecreatefromgif , NULL )
2002-03-02 12:32:31 +00:00
# endif
# ifdef HAVE_GD_JPG
2000-03-13 05:58:50 +00:00
PHP_FE ( imagecreatefromjpeg , NULL )
2002-03-02 12:32:31 +00:00
# endif
2001-06-07 13:17:02 +00:00
PHP_FE ( imagecreatefromwbmp , NULL )
2002-03-02 12:32:31 +00:00
# ifdef HAVE_GD_XBM
2000-06-07 00:37:49 +00:00
PHP_FE ( imagecreatefromxbm , NULL )
2002-03-02 12:32:31 +00:00
# endif
2002-12-11 22:25:23 +00:00
# if defined(HAVE_GD_XPM) && defined(HAVE_GD_BUNDLED)
2000-06-07 00:37:49 +00:00
PHP_FE ( imagecreatefromxpm , NULL )
2002-03-02 12:32:31 +00:00
# endif
2001-05-29 07:46:07 +00:00
PHP_FE ( imagecreatefromgd , NULL )
PHP_FE ( imagecreatefromgd2 , NULL )
PHP_FE ( imagecreatefromgd2part , NULL )
2002-03-02 12:32:31 +00:00
# ifdef HAVE_GD_PNG
2001-05-29 07:46:07 +00:00
PHP_FE ( imagepng , NULL )
2002-03-02 12:32:31 +00:00
# endif
# ifdef HAVE_GD_GIF_CREATE
2001-05-29 07:46:07 +00:00
PHP_FE ( imagegif , NULL )
2002-03-02 12:32:31 +00:00
# endif
# ifdef HAVE_GD_JPG
2001-05-29 07:46:07 +00:00
PHP_FE ( imagejpeg , NULL )
2002-03-02 12:32:31 +00:00
# endif
2001-05-29 07:46:07 +00:00
PHP_FE ( imagewbmp , NULL )
PHP_FE ( imagegd , NULL )
PHP_FE ( imagegd2 , NULL )
1999-07-27 19:44:46 +00:00
PHP_FE ( imagedestroy , NULL )
2000-05-14 15:25:13 +00:00
PHP_FE ( imagegammacorrect , NULL )
1999-07-27 19:44:46 +00:00
PHP_FE ( imagefill , NULL )
PHP_FE ( imagefilledpolygon , NULL )
PHP_FE ( imagefilledrectangle , NULL )
PHP_FE ( imagefilltoborder , NULL )
PHP_FE ( imagefontwidth , NULL )
PHP_FE ( imagefontheight , NULL )
PHP_FE ( imageinterlace , NULL )
PHP_FE ( imageline , NULL )
PHP_FE ( imageloadfont , NULL )
PHP_FE ( imagepolygon , NULL )
PHP_FE ( imagerectangle , NULL )
PHP_FE ( imagesetpixel , NULL )
PHP_FE ( imagestring , NULL )
PHP_FE ( imagestringup , NULL )
PHP_FE ( imagesx , NULL )
PHP_FE ( imagesy , NULL )
PHP_FE ( imagedashedline , NULL )
2002-06-24 19:31:44 +00:00
2002-03-02 12:32:31 +00:00
# ifdef ENABLE_GD_TTF
1999-07-27 19:44:46 +00:00
PHP_FE ( imagettfbbox , NULL )
PHP_FE ( imagettftext , NULL )
2005-12-27 00:11:16 +00:00
# if HAVE_LIBFREETYPE && HAVE_GD_STRINGFTEX
2002-03-02 12:32:31 +00:00
PHP_FE ( imageftbbox , NULL )
PHP_FE ( imagefttext , NULL )
# endif
2002-06-24 19:31:44 +00:00
# endif
2002-03-02 12:32:31 +00:00
# ifdef HAVE_LIBT1
2000-02-25 06:43:51 +00:00
PHP_FE ( imagepsloadfont , NULL )
/*
PHP_FE ( imagepscopyfont , NULL )
*/
PHP_FE ( imagepsfreefont , NULL )
PHP_FE ( imagepsencodefont , NULL )
PHP_FE ( imagepsextendfont , NULL )
PHP_FE ( imagepsslantfont , NULL )
PHP_FE ( imagepstext , NULL )
PHP_FE ( imagepsbbox , NULL )
2002-03-02 12:32:31 +00:00
# endif
2000-07-14 21:51:31 +00:00
PHP_FE ( imagetypes , NULL )
2003-02-26 23:22:09 +00:00
2005-12-14 22:33:34 +00:00
# if defined(HAVE_GD_JPG)
2001-01-24 09:24:26 +00:00
PHP_FE ( jpeg2wbmp , NULL )
2002-03-02 12:32:31 +00:00
# endif
2005-12-14 22:33:34 +00:00
# if defined(HAVE_GD_PNG)
2001-01-24 09:24:26 +00:00
PHP_FE ( png2wbmp , NULL )
2002-03-02 12:32:31 +00:00
# endif
2001-01-24 09:24:26 +00:00
PHP_FE ( image2wbmp , NULL )
2002-08-22 07:28:26 +00:00
# if HAVE_GD_BUNDLED
PHP_FE ( imagelayereffect , NULL )
PHP_FE ( imagecolormatch , NULL )
2003-06-15 20:00:08 +00:00
PHP_FE ( imagexbm , NULL )
2002-08-22 07:28:26 +00:00
# endif
2002-11-13 20:02:58 +00:00
/* gd filters */
# ifdef HAVE_GD_BUNDLED
PHP_FE ( imagefilter , NULL )
2005-04-16 12:12:24 +00:00
PHP_FE ( imageconvolution , NULL )
2002-11-13 20:02:58 +00:00
# endif
1999-04-16 12:15:38 +00:00
{ NULL , NULL , NULL }
} ;
2001-06-05 13:12:10 +00:00
/* }}} */
1999-04-16 12:15:38 +00:00
1999-12-17 20:55:31 +00:00
zend_module_entry gd_module_entry = {
2001-10-13 13:12:30 +00:00
STANDARD_MODULE_HEADER ,
2001-10-11 23:33:59 +00:00
" gd " ,
2001-10-13 13:12:30 +00:00
gd_functions ,
PHP_MINIT ( gd ) ,
2004-12-29 21:07:59 +00:00
PHP_MSHUTDOWN ( gd ) ,
2001-10-13 13:12:30 +00:00
NULL ,
2005-12-27 00:11:16 +00:00
# if HAVE_GD_STRINGFT && (HAVE_GD_FONTCACHESHUTDOWN || HAVE_GD_FREEFONTCACHE)
2002-11-23 22:11:59 +00:00
PHP_RSHUTDOWN ( gd ) ,
2003-03-31 08:49:19 +00:00
# else
NULL ,
# endif
2001-10-13 13:12:30 +00:00
PHP_MINFO ( gd ) ,
NO_VERSION_YET ,
STANDARD_MODULE_PROPERTIES
1999-04-16 12:15:38 +00:00
} ;
2000-05-23 09:33:51 +00:00
# ifdef COMPILE_DL_GD
2000-05-02 00:30:36 +00:00
ZEND_GET_MODULE ( gd )
1999-04-16 12:15:38 +00:00
# endif
2006-02-02 20:30:54 +00:00
/* {{{ PHP_INI_BEGIN */
PHP_INI_BEGIN ( )
PHP_INI_ENTRY ( " gd.jpeg_ignore_warning " , " 0 " , PHP_INI_ALL , NULL )
PHP_INI_END ( )
/* }}} */
2001-06-05 13:12:10 +00:00
/* {{{ php_free_gd_image
*/
2001-07-31 05:44:11 +00:00
static void php_free_gd_image ( zend_rsrc_list_entry * rsrc TSRMLS_DC )
2000-10-20 18:25:16 +00:00
{
2003-03-20 01:12:57 +00:00
gdImageDestroy ( ( gdImagePtr ) rsrc - > ptr ) ;
2000-10-20 18:25:16 +00:00
}
2001-06-05 13:12:10 +00:00
/* }}} */
1999-04-16 12:15:38 +00:00
2001-06-05 13:12:10 +00:00
/* {{{ php_free_gd_font
*/
2001-07-31 05:44:11 +00:00
static void php_free_gd_font ( zend_rsrc_list_entry * rsrc TSRMLS_DC )
1999-12-17 21:50:07 +00:00
{
2003-03-20 01:12:57 +00:00
gdFontPtr fp = ( gdFontPtr ) rsrc - > ptr ;
2001-07-31 05:44:11 +00:00
1999-12-17 21:50:07 +00:00
if ( fp - > data ) {
efree ( fp - > data ) ;
}
2003-03-20 01:12:57 +00:00
1999-12-17 21:50:07 +00:00
efree ( fp ) ;
}
2001-06-05 13:12:10 +00:00
/* }}} */
1999-12-17 21:50:07 +00:00
2004-12-29 21:07:59 +00:00
/* {{{ PHP_MSHUTDOWN_FUNCTION
*/
PHP_MSHUTDOWN_FUNCTION ( gd )
{
# if HAVE_LIBT1
T1_CloseLib ( ) ;
# endif
return SUCCESS ;
}
/* }}} */
2001-06-05 13:12:10 +00:00
/* {{{ PHP_MINIT_FUNCTION
*/
1999-07-27 19:44:46 +00:00
PHP_MINIT_FUNCTION ( gd )
1999-04-16 12:15:38 +00:00
{
2000-11-29 15:25:42 +00:00
le_gd = zend_register_list_destructors_ex ( php_free_gd_image , NULL , " gd " , module_number ) ;
le_gd_font = zend_register_list_destructors_ex ( php_free_gd_font , NULL , " gd font " , module_number ) ;
2000-02-25 06:43:51 +00:00
# if HAVE_LIBT1
T1_SetBitmapPad ( 8 ) ;
2003-03-20 01:12:57 +00:00
T1_InitLib ( NO_LOGFILE | IGNORE_CONFIGFILE | IGNORE_FONTDATABASE ) ;
2000-02-25 06:43:51 +00:00
T1_SetLogLevel ( T1LOG_DEBUG ) ;
2000-11-29 15:25:42 +00:00
le_ps_font = zend_register_list_destructors_ex ( php_free_ps_font , NULL , " gd PS font " , module_number ) ;
le_ps_enc = zend_register_list_destructors_ex ( php_free_ps_enc , NULL , " gd PS encoding " , module_number ) ;
2000-02-25 06:43:51 +00:00
# endif
2003-03-20 01:12:57 +00:00
2006-02-02 20:30:54 +00:00
REGISTER_INI_ENTRIES ( ) ;
2000-07-14 22:07:57 +00:00
REGISTER_LONG_CONSTANT ( " IMG_GIF " , 1 , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_JPG " , 2 , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_JPEG " , 2 , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_PNG " , 4 , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_WBMP " , 8 , CONST_CS | CONST_PERSISTENT ) ;
2001-07-02 12:49:21 +00:00
REGISTER_LONG_CONSTANT ( " IMG_XPM " , 16 , CONST_CS | CONST_PERSISTENT ) ;
2001-04-13 12:00:12 +00:00
# ifdef gdTiled
/* special colours for gd */
REGISTER_LONG_CONSTANT ( " IMG_COLOR_TILED " , gdTiled , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_COLOR_STYLED " , gdStyled , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_COLOR_BRUSHED " , gdBrushed , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_COLOR_STYLEDBRUSHED " , gdStyledBrushed , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_COLOR_TRANSPARENT " , gdTransparent , CONST_CS | CONST_PERSISTENT ) ;
# endif
/* for imagefilledarc */
2001-05-18 20:52:40 +00:00
REGISTER_LONG_CONSTANT ( " IMG_ARC_ROUNDED " , gdArc , CONST_CS | CONST_PERSISTENT ) ;
2001-04-13 12:00:12 +00:00
REGISTER_LONG_CONSTANT ( " IMG_ARC_PIE " , gdPie , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_ARC_CHORD " , gdChord , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_ARC_NOFILL " , gdNoFill , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_ARC_EDGED " , gdEdged , CONST_CS | CONST_PERSISTENT ) ;
2005-12-27 00:11:16 +00:00
2003-03-12 04:29:51 +00:00
/* GD2 image format types */
# ifdef GD2_FMT_RAW
REGISTER_LONG_CONSTANT ( " IMG_GD2_RAW " , GD2_FMT_RAW , CONST_CS | CONST_PERSISTENT ) ;
# endif
# ifdef GD2_FMT_COMPRESSED
REGISTER_LONG_CONSTANT ( " IMG_GD2_COMPRESSED " , GD2_FMT_COMPRESSED , CONST_CS | CONST_PERSISTENT ) ;
# endif
2002-08-22 07:28:26 +00:00
# if HAVE_GD_BUNDLED
REGISTER_LONG_CONSTANT ( " IMG_EFFECT_REPLACE " , gdEffectReplace , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_EFFECT_ALPHABLEND " , gdEffectAlphaBlend , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_EFFECT_NORMAL " , gdEffectNormal , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_EFFECT_OVERLAY " , gdEffectOverlay , CONST_CS | CONST_PERSISTENT ) ;
2002-10-11 13:09:48 +00:00
REGISTER_LONG_CONSTANT ( " GD_BUNDLED " , 1 , CONST_CS | CONST_PERSISTENT ) ;
2003-03-20 01:12:57 +00:00
/* Section Filters */
2002-11-13 20:02:58 +00:00
REGISTER_LONG_CONSTANT ( " IMG_FILTER_NEGATE " , IMAGE_FILTER_NEGATE , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_FILTER_GRAYSCALE " , IMAGE_FILTER_GRAYSCALE , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_FILTER_BRIGHTNESS " , IMAGE_FILTER_BRIGHTNESS , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_FILTER_CONTRAST " , IMAGE_FILTER_CONTRAST , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_FILTER_COLORIZE " , IMAGE_FILTER_COLORIZE , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_FILTER_EDGEDETECT " , IMAGE_FILTER_EDGEDETECT , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_FILTER_GAUSSIAN_BLUR " , IMAGE_FILTER_GAUSSIAN_BLUR , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_FILTER_SELECTIVE_BLUR " , IMAGE_FILTER_SELECTIVE_BLUR , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_FILTER_EMBOSS " , IMAGE_FILTER_EMBOSS , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_FILTER_MEAN_REMOVAL " , IMAGE_FILTER_MEAN_REMOVAL , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_FILTER_SMOOTH " , IMAGE_FILTER_SMOOTH , CONST_CS | CONST_PERSISTENT ) ;
2003-03-20 01:12:57 +00:00
/* End Section Filters */
2002-10-11 09:49:38 +00:00
# else
2002-10-11 13:09:48 +00:00
REGISTER_LONG_CONSTANT ( " GD_BUNDLED " , 0 , CONST_CS | CONST_PERSISTENT ) ;
2001-04-13 12:00:12 +00:00
# endif
2006-01-27 18:05:26 +00:00
# ifdef HAVE_GD_PNG
/*
* cannot include # include " png.h "
* / usr / include / pngconf . h : 310 : 2 : error : # error png . h already includes setjmp . h with some additional fixup .
* as error , use the values for now . . .
*/
REGISTER_LONG_CONSTANT ( " PNG_NO_FILTER " , 0x00 , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " PNG_FILTER_NONE " , 0x08 , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " PNG_FILTER_SUB " , 0x10 , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " PNG_FILTER_UP " , 0x20 , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " PNG_FILTER_AVG " , 0x40 , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " PNG_FILTER_PAETH " , 0x80 , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " PNG_ALL_FILTERS " , 0x08 | 0x10 | 0x20 | 0x40 | 0x80 , CONST_CS | CONST_PERSISTENT ) ;
# endif
1999-04-16 12:15:38 +00:00
return SUCCESS ;
}
2001-06-05 13:12:10 +00:00
/* }}} */
1999-04-16 12:15:38 +00:00
2002-11-23 22:11:59 +00:00
/* {{{ PHP_RSHUTDOWN_FUNCTION
*/
2005-12-27 00:11:16 +00:00
# if HAVE_GD_STRINGFT && (HAVE_GD_FONTCACHESHUTDOWN || HAVE_GD_FREEFONTCACHE)
2002-11-23 22:11:59 +00:00
PHP_RSHUTDOWN_FUNCTION ( gd )
{
2005-01-04 06:51:45 +00:00
# if HAVE_GD_FONTCACHESHUTDOWN
2003-12-25 22:12:12 +00:00
gdFontCacheShutdown ( ) ;
2003-12-28 21:08:46 +00:00
# else
2002-11-23 22:11:59 +00:00
gdFreeFontCache ( ) ;
2003-12-25 22:12:12 +00:00
# endif
2002-11-23 22:11:59 +00:00
return SUCCESS ;
}
2003-03-31 08:49:19 +00:00
# endif
2002-11-23 22:11:59 +00:00
/* }}} */
2005-12-01 00:36:26 +00:00
# ifdef HAVE_GD_BUNDLED
2004-07-23 02:28:18 +00:00
# define PHP_GD_VERSION_STRING "bundled (2.0.28 compatible)"
2003-04-05 20:43:53 +00:00
# endif
2001-06-05 13:12:10 +00:00
/* {{{ PHP_MINFO_FUNCTION
*/
1999-07-27 19:44:46 +00:00
PHP_MINFO_FUNCTION ( gd )
1999-05-09 13:57:09 +00:00
{
2000-04-05 22:30:19 +00:00
php_info_print_table_start ( ) ;
php_info_print_table_row ( 2 , " GD Support " , " enabled " ) ;
1999-04-16 12:15:38 +00:00
/* need to use a PHPAPI function here because it is external module in windows */
2000-04-05 22:30:19 +00:00
2003-04-05 20:43:53 +00:00
php_info_print_table_row ( 2 , " GD Version " , PHP_GD_VERSION_STRING ) ;
1999-11-29 23:21:52 +00:00
1999-07-23 15:18:37 +00:00
# ifdef ENABLE_GD_TTF
2000-04-05 22:30:19 +00:00
php_info_print_table_row ( 2 , " FreeType Support " , " enabled " ) ;
1999-11-29 23:21:52 +00:00
# if HAVE_LIBFREETYPE
2000-04-05 22:30:19 +00:00
php_info_print_table_row ( 2 , " FreeType Linkage " , " with freetype " ) ;
2003-09-09 19:08:30 +00:00
{
char tmp [ 256 ] ;
2003-09-15 07:27:18 +00:00
# ifdef FREETYPE_PATCH
2003-09-09 19:08:30 +00:00
snprintf ( tmp , sizeof ( tmp ) , " %d.%d.%d " , FREETYPE_MAJOR , FREETYPE_MINOR , FREETYPE_PATCH ) ;
2003-09-15 07:27:18 +00:00
# else
snprintf ( tmp , sizeof ( tmp ) , " %d.%d " , FREETYPE_MAJOR , FREETYPE_MINOR ) ;
# endif
2003-09-09 19:08:30 +00:00
php_info_print_table_row ( 2 , " FreeType Version " , tmp ) ;
}
2000-04-05 22:30:19 +00:00
php_info_print_table_row ( 2 , " FreeType Linkage " , " with unknown library " ) ;
1999-11-29 23:21:52 +00:00
# endif
# endif
2000-06-06 17:12:05 +00:00
# ifdef HAVE_LIBT1
php_info_print_table_row ( 2 , " T1Lib Support " , " enabled " ) ;
2002-09-12 21:42:33 +00:00
# endif
2000-06-06 17:12:05 +00:00
2000-04-05 22:30:19 +00:00
/* this next part is stupid ... if I knew better, I'd put them all on one row (cmv) */
2001-08-24 20:05:58 +00:00
# ifdef HAVE_GD_GIF_READ
php_info_print_table_row ( 2 , " GIF Read Support " , " enabled " ) ;
# endif
2001-08-26 01:10:10 +00:00
# ifdef HAVE_GD_GIF_CREATE
2001-08-24 20:05:58 +00:00
php_info_print_table_row ( 2 , " GIF Create Support " , " enabled " ) ;
1999-11-29 23:21:52 +00:00
# endif
2000-04-07 18:50:08 +00:00
# ifdef HAVE_GD_JPG
php_info_print_table_row ( 2 , " JPG Support " , " enabled " ) ;
2000-07-14 21:51:31 +00:00
# endif
2000-11-01 04:38:28 +00:00
# ifdef HAVE_GD_PNG
php_info_print_table_row ( 2 , " PNG Support " , " enabled " ) ;
# endif
2000-07-14 21:51:31 +00:00
php_info_print_table_row ( 2 , " WBMP Support " , " enabled " ) ;
2003-02-01 23:23:59 +00:00
# if defined(HAVE_GD_XPM) && defined(HAVE_GD_BUNDLED)
php_info_print_table_row ( 2 , " XPM Support " , " enabled " ) ;
# endif
2000-11-01 04:38:28 +00:00
# ifdef HAVE_GD_XBM
php_info_print_table_row ( 2 , " XBM Support " , " enabled " ) ;
2003-04-19 07:44:16 +00:00
# endif
# if defined(USE_GD_JISX0208) && defined(HAVE_GD_BUNDLED)
php_info_print_table_row ( 2 , " JIS-mapped Japanese Font Support " , " enabled " ) ;
1999-04-16 12:15:38 +00:00
# endif
2000-04-05 22:30:19 +00:00
php_info_print_table_end ( ) ;
1999-04-16 12:15:38 +00:00
}
2001-06-05 13:12:10 +00:00
/* }}} */
1999-04-16 12:15:38 +00:00
2002-11-12 11:49:11 +00:00
/* {{{ proto array gd_info()
*/
PHP_FUNCTION ( gd_info )
{
2003-03-20 01:12:57 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 0 ) {
2002-11-12 11:49:11 +00:00
ZEND_WRONG_PARAM_COUNT ( ) ;
RETURN_FALSE ;
}
2003-01-17 21:37:56 +00:00
array_init ( return_value ) ;
2003-04-05 20:43:53 +00:00
add_assoc_string ( return_value , " GD Version " , PHP_GD_VERSION_STRING , 1 ) ;
2002-11-12 11:49:11 +00:00
# ifdef ENABLE_GD_TTF
add_assoc_bool ( return_value , " FreeType Support " , 1 ) ;
# if HAVE_LIBFREETYPE
add_assoc_string ( return_value , " FreeType Linkage " , " with freetype " , 1 ) ;
# else
add_assoc_string ( return_value , " FreeType Linkage " , " with unknown library " , 1 ) ;
# endif
# else
add_assoc_bool ( return_value , " FreeType Support " , 0 ) ;
# endif
# ifdef HAVE_LIBT1
add_assoc_bool ( return_value , " T1Lib Support " , 1 ) ;
# else
add_assoc_bool ( return_value , " T1Lib Support " , 0 ) ;
# endif
# ifdef HAVE_GD_GIF_READ
add_assoc_bool ( return_value , " GIF Read Support " , 1 ) ;
# else
add_assoc_bool ( return_value , " GIF Read Support " , 0 ) ;
# endif
# ifdef HAVE_GD_GIF_CREATE
add_assoc_bool ( return_value , " GIF Create Support " , 1 ) ;
# else
add_assoc_bool ( return_value , " GIF Create Support " , 0 ) ;
# endif
# ifdef HAVE_GD_JPG
add_assoc_bool ( return_value , " JPG Support " , 1 ) ;
# else
add_assoc_bool ( return_value , " JPG Support " , 0 ) ;
# endif
# ifdef HAVE_GD_PNG
add_assoc_bool ( return_value , " PNG Support " , 1 ) ;
# else
add_assoc_bool ( return_value , " PNG Support " , 0 ) ;
# endif
add_assoc_bool ( return_value , " WBMP Support " , 1 ) ;
2003-02-01 23:23:59 +00:00
# if defined(HAVE_GD_XPM) && defined(HAVE_GD_BUNDLED)
add_assoc_bool ( return_value , " XPM Support " , 1 ) ;
# else
add_assoc_bool ( return_value , " XPM Support " , 0 ) ;
# endif
2002-11-12 11:49:11 +00:00
# ifdef HAVE_GD_XBM
add_assoc_bool ( return_value , " XBM Support " , 1 ) ;
# else
add_assoc_bool ( return_value , " XBM Support " , 0 ) ;
# endif
2003-04-19 07:44:16 +00:00
# if defined(USE_GD_JISX0208) && defined(HAVE_GD_BUNDLED)
add_assoc_bool ( return_value , " JIS-mapped Japanese Font Support " , 1 ) ;
# else
add_assoc_bool ( return_value , " JIS-mapped Japanese Font Support " , 0 ) ;
# endif
2002-11-12 11:49:11 +00:00
}
/* }}} */
2005-12-04 23:27:23 +00:00
/* Need this for cpdf. See also comment in file.c phpi_get_le_fp() */
2001-02-20 18:00:44 +00:00
PHP_GD_API int phpi_get_le_gd ( void )
1999-12-17 21:50:07 +00:00
{
2000-11-29 15:25:42 +00:00
return le_gd ;
1999-08-05 16:25:10 +00:00
}
2001-03-12 13:57:53 +00:00
# define FLIPWORD(a) (((a & 0xff000000) >> 24) | ((a & 0x00ff0000) >> 8) | ((a & 0x0000ff00) << 8) | ((a & 0x000000ff) << 24))
1999-04-16 12:15:38 +00:00
/* {{{ proto int imageloadfont(string filename)
1999-11-24 22:04:49 +00:00
Load a new font */
2003-02-26 23:22:09 +00:00
PHP_FUNCTION ( imageloadfont )
2000-11-23 14:56:09 +00:00
{
2000-02-28 16:52:03 +00:00
zval * * file ;
1999-04-16 12:15:38 +00:00
int hdr_size = sizeof ( gdFont ) - sizeof ( char * ) ;
2003-03-20 01:12:57 +00:00
int ind , body_size , n = 0 , b , i , body_size_check ;
1999-04-16 12:15:38 +00:00
gdFontPtr font ;
2002-03-16 01:28:57 +00:00
php_stream * stream ;
1999-04-16 12:15:38 +00:00
2000-06-05 19:47:54 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 1 | | zend_get_parameters_ex ( 1 , & file ) = = FAILURE ) {
2001-07-30 17:29:57 +00:00
ZEND_WRONG_PARAM_COUNT ( ) ;
1999-04-16 12:15:38 +00:00
}
2000-02-28 16:52:03 +00:00
convert_to_string_ex ( file ) ;
1999-04-16 12:15:38 +00:00
2006-02-19 04:29:42 +00:00
stream = php_stream_open_wrapper ( Z_STRVAL_PP ( file ) , " rb " , IGNORE_PATH | IGNORE_URL_WIN | REPORT_ERRORS , NULL ) ;
2002-03-15 21:03:08 +00:00
if ( stream = = NULL ) {
1999-04-16 12:15:38 +00:00
RETURN_FALSE ;
}
/* Only supports a architecture-dependent binary dump format
* at the moment .
* The file format is like this on machines with 32 - byte integers :
*
* byte 0 - 3 : ( int ) number of characters in the font
* byte 4 - 7 : ( int ) value of first character in the font ( often 32 , space )
* byte 8 - 11 : ( int ) pixel width of each character
* byte 12 - 15 : ( int ) pixel height of each character
* bytes 16 - : ( char ) array with character data , one byte per pixel
2003-02-26 23:22:09 +00:00
* in each character , for a total of
1999-04-16 12:15:38 +00:00
* ( nchars * width * height ) bytes .
*/
2003-03-20 01:12:57 +00:00
font = ( gdFontPtr ) emalloc ( sizeof ( gdFont ) ) ;
1999-04-16 12:15:38 +00:00
b = 0 ;
2003-03-20 01:12:57 +00:00
while ( b < hdr_size & & ( n = php_stream_read ( stream , ( char * ) & font [ b ] , hdr_size - b ) ) ) {
1999-04-16 12:15:38 +00:00
b + = n ;
2003-03-20 01:12:57 +00:00
}
1999-04-16 12:15:38 +00:00
if ( ! n ) {
efree ( font ) ;
2002-03-15 21:03:08 +00:00
if ( php_stream_eof ( stream ) ) {
2002-08-22 18:38:44 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " End of file while reading header " ) ;
1999-04-16 12:15:38 +00:00
} else {
2002-08-22 18:38:44 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Error while reading header " ) ;
1999-04-16 12:15:38 +00:00
}
2002-08-23 17:45:46 +00:00
php_stream_close ( stream ) ;
1999-04-16 12:15:38 +00:00
RETURN_FALSE ;
}
2002-03-15 21:03:08 +00:00
i = php_stream_tell ( stream ) ;
php_stream_seek ( stream , 0 , SEEK_END ) ;
body_size_check = php_stream_tell ( stream ) - hdr_size ;
php_stream_seek ( stream , i , SEEK_SET ) ;
2003-03-20 01:12:57 +00:00
1999-04-16 12:15:38 +00:00
body_size = font - > w * font - > h * font - > nchars ;
2001-03-12 13:57:53 +00:00
if ( body_size ! = body_size_check ) {
font - > w = FLIPWORD ( font - > w ) ;
font - > h = FLIPWORD ( font - > h ) ;
font - > nchars = FLIPWORD ( font - > nchars ) ;
body_size = font - > w * font - > h * font - > nchars ;
}
2003-03-20 01:12:57 +00:00
2001-03-12 13:57:53 +00:00
if ( body_size ! = body_size_check ) {
2002-08-22 18:38:44 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Error reading font " ) ;
2001-03-12 13:57:53 +00:00
efree ( font ) ;
2004-05-20 23:37:59 +00:00
php_stream_close ( stream ) ;
2001-03-12 13:57:53 +00:00
RETURN_FALSE ;
}
1999-04-16 12:15:38 +00:00
font - > data = emalloc ( body_size ) ;
b = 0 ;
2003-03-20 01:12:57 +00:00
while ( b < body_size & & ( n = php_stream_read ( stream , & font - > data [ b ] , body_size - b ) ) ) {
1999-04-16 12:15:38 +00:00
b + = n ;
2003-03-20 01:12:57 +00:00
}
1999-04-16 12:15:38 +00:00
if ( ! n ) {
efree ( font - > data ) ;
efree ( font ) ;
2002-03-15 21:03:08 +00:00
if ( php_stream_eof ( stream ) ) {
2002-08-22 18:38:44 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " End of file while reading body " ) ;
1999-04-16 12:15:38 +00:00
} else {
2002-08-22 18:38:44 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Error while reading body " ) ;
1999-04-16 12:15:38 +00:00
}
2002-08-23 17:53:03 +00:00
php_stream_close ( stream ) ;
1999-04-16 12:15:38 +00:00
RETURN_FALSE ;
}
2002-03-15 21:03:08 +00:00
php_stream_close ( stream ) ;
1999-04-16 12:15:38 +00:00
/* Adding 5 to the font index so we will never have font indices
* that overlap with the old fonts ( with indices 1 - 5 ) . The first
* list index given out is always 1.
*/
2000-11-29 15:25:42 +00:00
ind = 5 + zend_list_insert ( font , le_gd_font ) ;
1999-04-16 12:15:38 +00:00
RETURN_LONG ( ind ) ;
}
/* }}} */
2003-06-15 15:29:46 +00:00
/* {{{ proto bool imagesetstyle(resource im, array styles)
2001-06-11 14:39:13 +00:00
Set the line drawing styles for use with imageline and IMG_COLOR_STYLED . */
2001-04-13 12:00:12 +00:00
PHP_FUNCTION ( imagesetstyle )
{
2001-05-21 18:50:05 +00:00
zval * * IM , * * styles ;
2001-04-13 12:00:12 +00:00
gdImagePtr im ;
int * stylearr ;
int index ;
HashPosition pos ;
2001-07-30 17:29:57 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 2 | | zend_get_parameters_ex ( 2 , & IM , & styles ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
2001-04-13 12:00:12 +00:00
}
ZEND_FETCH_RESOURCE ( im , gdImagePtr , IM , - 1 , " Image " , le_gd ) ;
2003-03-20 01:12:57 +00:00
2001-06-11 15:21:47 +00:00
convert_to_array_ex ( styles ) ;
2001-04-13 12:00:12 +00:00
/* copy the style values in the stylearr */
2003-08-12 00:58:52 +00:00
stylearr = safe_emalloc ( sizeof ( int ) , zend_hash_num_elements ( HASH_OF ( * styles ) ) , 0 ) ;
2001-04-13 12:00:12 +00:00
zend_hash_internal_pointer_reset_ex ( HASH_OF ( * styles ) , & pos ) ;
2003-02-26 23:22:09 +00:00
2003-03-20 01:12:57 +00:00
for ( index = 0 ; ; zend_hash_move_forward_ex ( HASH_OF ( * styles ) , & pos ) ) {
2001-04-13 12:00:12 +00:00
zval * * item ;
2003-03-20 01:12:57 +00:00
if ( zend_hash_get_current_data_ex ( HASH_OF ( * styles ) , ( void * * ) & item , & pos ) = = FAILURE ) {
2001-04-13 12:00:12 +00:00
break ;
2003-03-20 01:12:57 +00:00
}
2001-04-13 12:00:12 +00:00
convert_to_long_ex ( item ) ;
stylearr [ index + + ] = Z_LVAL_PP ( item ) ;
}
2003-03-20 01:12:57 +00:00
2001-04-13 12:00:12 +00:00
gdImageSetStyle ( im , stylearr , index ) ;
efree ( stylearr ) ;
RETURN_TRUE ;
}
/* }}} */
2003-06-15 15:29:46 +00:00
/* {{{ proto resource imagecreatetruecolor(int x_size, int y_size)
2001-04-13 12:00:12 +00:00
Create a new true color image */
PHP_FUNCTION ( imagecreatetruecolor )
{
zval * * x_size , * * y_size ;
gdImagePtr im ;
if ( ZEND_NUM_ARGS ( ) ! = 2 | | zend_get_parameters_ex ( 2 , & x_size , & y_size ) = = FAILURE ) {
2001-07-30 17:29:57 +00:00
ZEND_WRONG_PARAM_COUNT ( ) ;
2001-04-13 12:00:12 +00:00
}
convert_to_long_ex ( x_size ) ;
convert_to_long_ex ( y_size ) ;
2003-04-03 23:10:08 +00:00
if ( Z_LVAL_PP ( x_size ) < = 0 | | Z_LVAL_PP ( y_size ) < = 0 ) {
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Invalid image dimensions " ) ;
2003-04-03 19:18:57 +00:00
RETURN_FALSE ;
}
2003-12-28 21:08:46 +00:00
2001-04-13 12:00:12 +00:00
im = gdImageCreateTrueColor ( Z_LVAL_PP ( x_size ) , Z_LVAL_PP ( y_size ) ) ;
ZEND_REGISTER_RESOURCE ( return_value , im , le_gd ) ;
}
/* }}} */
2003-06-15 15:29:46 +00:00
/* {{{ proto bool imageistruecolor(resource im)
2002-12-10 19:45:58 +00:00
return true if the image uses truecolor */
PHP_FUNCTION ( imageistruecolor )
{
zval * * IM ;
gdImagePtr im ;
if ( ZEND_NUM_ARGS ( ) ! = 1 | | zend_get_parameters_ex ( 1 , & IM ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
}
2003-02-26 23:22:09 +00:00
2002-12-10 19:45:58 +00:00
ZEND_FETCH_RESOURCE ( im , gdImagePtr , IM , - 1 , " Image " , le_gd ) ;
RETURN_BOOL ( im - > trueColor ) ;
}
/* }}} */
2001-12-06 18:37:05 +00:00
/* {{{ proto void imagetruecolortopalette(resource im, bool ditherFlag, int colorsWanted)
2001-10-08 18:39:42 +00:00
Convert a true colour image to a palette based image with a number of colours , optionally using dithering . */
2001-04-13 12:00:12 +00:00
PHP_FUNCTION ( imagetruecolortopalette )
{
zval * * IM , * * dither , * * ncolors ;
gdImagePtr im ;
2001-07-30 17:29:57 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 3 | | zend_get_parameters_ex ( 3 , & IM , & dither , & ncolors ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
2001-04-13 12:00:12 +00:00
}
ZEND_FETCH_RESOURCE ( im , gdImagePtr , IM , - 1 , " Image " , le_gd ) ;
2003-03-20 01:12:57 +00:00
2001-04-13 12:00:12 +00:00
convert_to_boolean_ex ( dither ) ;
convert_to_long_ex ( ncolors ) ;
2003-02-26 23:22:09 +00:00
2005-10-26 21:35:56 +00:00
if ( Z_LVAL_PP ( ncolors ) < = 0 ) {
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Number of colors has to be greater than zero " ) ;
RETURN_FALSE ;
}
2001-04-13 12:00:12 +00:00
gdImageTrueColorToPalette ( im , Z_LVAL_PP ( dither ) , Z_LVAL_PP ( ncolors ) ) ;
RETURN_TRUE ;
}
/* }}} */
2002-08-22 07:28:26 +00:00
# if HAVE_GD_BUNDLED
2003-06-15 15:29:46 +00:00
/* {{{ proto bool imagecolormatch(resource im1, resource im2)
2002-09-12 21:42:33 +00:00
Makes the colors of the palette version of an image more closely match the true color version */
2002-08-22 07:28:26 +00:00
PHP_FUNCTION ( imagecolormatch )
{
zval * * IM1 , * * IM2 ;
gdImagePtr im1 , im2 ;
int result ;
if ( ZEND_NUM_ARGS ( ) ! = 2 | | zend_get_parameters_ex ( 2 , & IM1 , & IM2 ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
}
ZEND_FETCH_RESOURCE ( im1 , gdImagePtr , IM1 , - 1 , " Image " , le_gd ) ;
ZEND_FETCH_RESOURCE ( im2 , gdImagePtr , IM2 , - 1 , " Image " , le_gd ) ;
result = gdImageColorMatch ( im1 , im2 ) ;
2003-03-20 01:12:57 +00:00
switch ( result ) {
case - 1 :
2005-12-25 20:32:25 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Image1 must be TrueColor " ) ;
2003-03-20 01:12:57 +00:00
RETURN_FALSE ;
break ;
case - 2 :
2005-12-25 20:32:25 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Image2 must be Palette " ) ;
2003-03-20 01:12:57 +00:00
RETURN_FALSE ;
break ;
case - 3 :
2005-12-25 20:32:25 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Image1 and Image2 must be the same size " ) ;
2003-03-20 01:12:57 +00:00
RETURN_FALSE ;
break ;
2005-12-25 19:21:58 +00:00
case - 4 :
2005-12-25 20:32:25 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Image2 must have at least one color " ) ;
2005-12-25 19:21:58 +00:00
RETURN_FALSE ;
break ;
2002-08-22 07:28:26 +00:00
}
RETURN_TRUE ;
}
/* }}} */
# endif
2003-06-15 15:29:46 +00:00
/* {{{ proto bool imagesetthickness(resource im, int thickness)
2001-10-08 18:39:42 +00:00
Set line thickness for drawing lines , ellipses , rectangles , polygons etc . */
2001-04-13 12:00:12 +00:00
PHP_FUNCTION ( imagesetthickness )
{
zval * * IM , * * thick ;
gdImagePtr im ;
2001-07-30 17:29:57 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 2 | | zend_get_parameters_ex ( 2 , & IM , & thick ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
2001-04-13 12:00:12 +00:00
}
ZEND_FETCH_RESOURCE ( im , gdImagePtr , IM , - 1 , " Image " , le_gd ) ;
2001-06-11 13:57:47 +00:00
convert_to_long_ex ( thick ) ;
2003-02-26 23:22:09 +00:00
2001-04-13 12:00:12 +00:00
gdImageSetThickness ( im , Z_LVAL_PP ( thick ) ) ;
RETURN_TRUE ;
}
/* }}} */
2003-06-15 15:29:46 +00:00
/* {{{ proto bool imagefilledellipse(resource im, int cx, int cy, int w, int h, int color)
2001-10-08 18:39:42 +00:00
Draw an ellipse */
2001-04-13 12:00:12 +00:00
PHP_FUNCTION ( imagefilledellipse )
{
zval * * IM , * * cx , * * cy , * * w , * * h , * * color ;
gdImagePtr im ;
2001-07-30 17:29:57 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 6 | | zend_get_parameters_ex ( 6 , & IM , & cx , & cy , & w , & h , & color ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
2001-04-13 12:00:12 +00:00
}
2003-02-26 23:22:09 +00:00
2001-04-13 12:00:12 +00:00
ZEND_FETCH_RESOURCE ( im , gdImagePtr , IM , - 1 , " Image " , le_gd ) ;
convert_to_long_ex ( cx ) ;
convert_to_long_ex ( cy ) ;
convert_to_long_ex ( w ) ;
convert_to_long_ex ( h ) ;
convert_to_long_ex ( color ) ;
gdImageFilledEllipse ( im , Z_LVAL_PP ( cx ) , Z_LVAL_PP ( cy ) , Z_LVAL_PP ( w ) , Z_LVAL_PP ( h ) , Z_LVAL_PP ( color ) ) ;
RETURN_TRUE ;
}
/* }}} */
2003-06-15 15:29:46 +00:00
/* {{{ proto bool imagefilledarc(resource im, int cx, int cy, int w, int h, int s, int e, int col, int style)
2001-04-13 12:00:12 +00:00
Draw a filled partial ellipse */
PHP_FUNCTION ( imagefilledarc )
{
zval * * IM , * * cx , * * cy , * * w , * * h , * * ST , * * E , * * col , * * style ;
gdImagePtr im ;
2001-08-11 16:39:07 +00:00
int e , st ;
2001-04-13 12:00:12 +00:00
2001-07-30 17:29:57 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 9 | | zend_get_parameters_ex ( 9 , & IM , & cx , & cy , & w , & h , & ST , & E , & col , & style ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
2001-04-13 12:00:12 +00:00
}
ZEND_FETCH_RESOURCE ( im , gdImagePtr , IM , - 1 , " Image " , le_gd ) ;
convert_to_long_ex ( cx ) ;
convert_to_long_ex ( cy ) ;
convert_to_long_ex ( w ) ;
convert_to_long_ex ( h ) ;
convert_to_long_ex ( ST ) ;
convert_to_long_ex ( E ) ;
convert_to_long_ex ( col ) ;
convert_to_long_ex ( style ) ;
e = Z_LVAL_PP ( E ) ;
2003-03-20 01:12:57 +00:00
if ( e < 0 ) {
e % = 360 ;
}
2001-04-13 12:00:12 +00:00
2003-03-20 01:12:57 +00:00
st = Z_LVAL_PP ( ST ) ;
if ( st < 0 ) {
st % = 360 ;
}
2001-04-13 12:00:12 +00:00
2001-08-11 16:39:07 +00:00
gdImageFilledArc ( im , Z_LVAL_PP ( cx ) , Z_LVAL_PP ( cy ) , Z_LVAL_PP ( w ) , Z_LVAL_PP ( h ) , st , e , Z_LVAL_PP ( col ) , Z_LVAL_PP ( style ) ) ;
2003-03-20 01:12:57 +00:00
2001-04-13 12:00:12 +00:00
RETURN_TRUE ;
}
2003-02-26 23:22:09 +00:00
/* }}} */
2001-04-13 12:00:12 +00:00
2003-06-15 15:29:46 +00:00
/* {{{ proto bool imagealphablending(resource im, bool on)
2001-04-13 12:00:12 +00:00
Turn alpha blending mode on or off for the given image */
PHP_FUNCTION ( imagealphablending )
{
zval * * IM , * * blend ;
gdImagePtr im ;
2001-07-30 17:29:57 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 2 | | zend_get_parameters_ex ( 2 , & IM , & blend ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
2001-04-13 12:00:12 +00:00
}
ZEND_FETCH_RESOURCE ( im , gdImagePtr , IM , - 1 , " Image " , le_gd ) ;
convert_to_boolean_ex ( blend ) ;
2003-02-26 23:22:09 +00:00
2001-04-13 12:00:12 +00:00
gdImageAlphaBlending ( im , Z_LVAL_PP ( blend ) ) ;
RETURN_TRUE ;
}
/* }}} */
2003-06-15 15:29:46 +00:00
/* {{{ proto bool imagesavealpha(resource im, bool on)
2003-02-26 23:22:09 +00:00
Include alpha channel to a saved image */
PHP_FUNCTION ( imagesavealpha )
{
zval * * IM , * * save ;
gdImagePtr im ;
if ( ZEND_NUM_ARGS ( ) ! = 2 | | zend_get_parameters_ex ( 2 , & IM , & save ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
}
ZEND_FETCH_RESOURCE ( im , gdImagePtr , IM , - 1 , " Image " , le_gd ) ;
convert_to_boolean_ex ( save ) ;
gdImageSaveAlpha ( im , Z_LVAL_PP ( save ) ) ;
RETURN_TRUE ;
}
2002-08-22 07:28:26 +00:00
# if HAVE_GD_BUNDLED
2003-06-15 15:29:46 +00:00
/* {{{ proto bool imagelayereffect(resource im, int effect)
2002-08-22 07:28:26 +00:00
Set the alpha blending flag to use the bundled libgd layering effects */
PHP_FUNCTION ( imagelayereffect )
{
zval * * IM , * * effect ;
gdImagePtr im ;
if ( ZEND_NUM_ARGS ( ) ! = 2 | | zend_get_parameters_ex ( 2 , & IM , & effect ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
}
ZEND_FETCH_RESOURCE ( im , gdImagePtr , IM , - 1 , " Image " , le_gd ) ;
convert_to_long_ex ( effect ) ;
gdImageAlphaBlending ( im , Z_LVAL_PP ( effect ) ) ;
RETURN_TRUE ;
}
/* }}} */
# endif
2003-01-26 01:15:02 +00:00
/* {{{ proto int imagecolorallocatealpha(resource im, int red, int green, int blue, int alpha)
Allocate a color with an alpha level . Works for true color and palette based images */
PHP_FUNCTION ( imagecolorallocatealpha )
{
zval * IM ;
2004-01-28 01:36:53 +00:00
long red , green , blue , alpha ;
2003-01-26 01:15:02 +00:00
gdImagePtr im ;
2006-01-17 16:34:58 +00:00
int ct = ( - 1 ) ;
2003-01-26 01:15:02 +00:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " zllll " , & IM , & red , & green , & blue , & alpha ) = = FAILURE ) {
RETURN_FALSE ;
}
ZEND_FETCH_RESOURCE ( im , gdImagePtr , & IM , - 1 , " Image " , le_gd ) ;
2006-01-17 16:34:58 +00:00
ct = gdImageColorAllocateAlpha ( im , red , green , blue , alpha ) ;
if ( ct < 0 ) {
RETURN_FALSE ;
}
RETURN_LONG ( ct ) ;
2003-01-26 01:15:02 +00:00
}
/* }}} */
2001-04-13 12:00:12 +00:00
/* {{{ proto int imagecolorresolvealpha(resource im, int red, int green, int blue, int alpha)
Resolve / Allocate a colour with an alpha level . Works for true colour and palette based images */
PHP_FUNCTION ( imagecolorresolvealpha )
{
zval * * IM , * * red , * * green , * * blue , * * alpha ;
gdImagePtr im ;
2001-07-30 17:29:57 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 5 | | zend_get_parameters_ex ( 5 , & IM , & red , & green , & blue , & alpha ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
2001-04-13 12:00:12 +00:00
}
2003-02-26 23:22:09 +00:00
2001-04-13 12:00:12 +00:00
ZEND_FETCH_RESOURCE ( im , gdImagePtr , IM , - 1 , " Image " , le_gd ) ;
convert_to_long_ex ( red ) ;
convert_to_long_ex ( green ) ;
convert_to_long_ex ( blue ) ;
convert_to_long_ex ( alpha ) ;
RETURN_LONG ( gdImageColorResolveAlpha ( im , Z_LVAL_PP ( red ) , Z_LVAL_PP ( green ) , Z_LVAL_PP ( blue ) , Z_LVAL_PP ( alpha ) ) ) ;
}
/* }}} */
/* {{{ proto int imagecolorclosestalpha(resource im, int red, int green, int blue, int alpha)
2001-10-08 18:39:42 +00:00
Find the closest matching colour with alpha transparency */
2001-04-13 12:00:12 +00:00
PHP_FUNCTION ( imagecolorclosestalpha )
{
zval * * IM , * * red , * * green , * * blue , * * alpha ;
gdImagePtr im ;
2001-07-30 17:29:57 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 5 | | zend_get_parameters_ex ( 5 , & IM , & red , & green , & blue , & alpha ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
2001-04-13 12:00:12 +00:00
}
2003-02-26 23:22:09 +00:00
2001-04-13 12:00:12 +00:00
ZEND_FETCH_RESOURCE ( im , gdImagePtr , IM , - 1 , " Image " , le_gd ) ;
convert_to_long_ex ( red ) ;
convert_to_long_ex ( green ) ;
convert_to_long_ex ( blue ) ;
convert_to_long_ex ( alpha ) ;
RETURN_LONG ( gdImageColorClosestAlpha ( im , Z_LVAL_PP ( red ) , Z_LVAL_PP ( green ) , Z_LVAL_PP ( blue ) , Z_LVAL_PP ( alpha ) ) ) ;
}
/* }}} */
/* {{{ proto int imagecolorexactalpha(resource im, int red, int green, int blue, int alpha)
2001-10-08 18:39:42 +00:00
Find exact match for colour with transparency */
2001-04-13 12:00:12 +00:00
PHP_FUNCTION ( imagecolorexactalpha )
{
zval * * IM , * * red , * * green , * * blue , * * alpha ;
gdImagePtr im ;
2001-07-30 17:29:57 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 5 | | zend_get_parameters_ex ( 5 , & IM , & red , & green , & blue , & alpha ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
2001-04-13 12:00:12 +00:00
}
2003-02-26 23:22:09 +00:00
2001-04-13 12:00:12 +00:00
ZEND_FETCH_RESOURCE ( im , gdImagePtr , IM , - 1 , " Image " , le_gd ) ;
convert_to_long_ex ( red ) ;
convert_to_long_ex ( green ) ;
convert_to_long_ex ( blue ) ;
convert_to_long_ex ( alpha ) ;
2003-02-26 23:22:09 +00:00
2001-04-13 12:00:12 +00:00
RETURN_LONG ( gdImageColorExactAlpha ( im , Z_LVAL_PP ( red ) , Z_LVAL_PP ( green ) , Z_LVAL_PP ( blue ) , Z_LVAL_PP ( alpha ) ) ) ;
}
/* }}} */
2003-06-15 15:29:46 +00:00
/* {{{ proto bool imagecopyresampled(resource dst_im, resource src_im, int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h)
2001-04-13 12:00:12 +00:00
Copy and resize part of an image using resampling to help ensure clarity */
PHP_FUNCTION ( imagecopyresampled )
{
zval * * SIM , * * DIM , * * SX , * * SY , * * SW , * * SH , * * DX , * * DY , * * DW , * * DH ;
gdImagePtr im_dst , im_src ;
int srcH , srcW , dstH , dstW , srcY , srcX , dstY , dstX ;
2003-03-20 01:12:57 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 10 | | zend_get_parameters_ex ( 10 , & DIM , & SIM , & DX , & DY , & SX , & SY , & DW , & DH , & SW , & SH ) = = FAILURE ) {
2001-07-30 17:29:57 +00:00
ZEND_WRONG_PARAM_COUNT ( ) ;
2001-04-13 12:00:12 +00:00
}
ZEND_FETCH_RESOURCE ( im_dst , gdImagePtr , DIM , - 1 , " Image " , le_gd ) ;
ZEND_FETCH_RESOURCE ( im_src , gdImagePtr , SIM , - 1 , " Image " , le_gd ) ;
convert_to_long_ex ( SX ) ;
convert_to_long_ex ( SY ) ;
convert_to_long_ex ( SW ) ;
convert_to_long_ex ( SH ) ;
convert_to_long_ex ( DX ) ;
convert_to_long_ex ( DY ) ;
convert_to_long_ex ( DW ) ;
convert_to_long_ex ( DH ) ;
srcX = Z_LVAL_PP ( SX ) ;
srcY = Z_LVAL_PP ( SY ) ;
srcH = Z_LVAL_PP ( SH ) ;
srcW = Z_LVAL_PP ( SW ) ;
dstX = Z_LVAL_PP ( DX ) ;
dstY = Z_LVAL_PP ( DY ) ;
dstH = Z_LVAL_PP ( DH ) ;
dstW = Z_LVAL_PP ( DW ) ;
gdImageCopyResampled ( im_dst , im_src , dstX , dstY , srcX , srcY , dstW , dstH , srcW , srcH ) ;
2002-10-29 01:15:44 +00:00
2003-03-20 01:12:57 +00:00
RETURN_TRUE ;
2002-10-29 01:15:44 +00:00
}
/* }}} */
# ifdef HAVE_GD_BUNDLED
2003-06-15 15:29:46 +00:00
/* {{{ proto resource imagerotate(resource src_im, float angle, int bgdcolor)
2002-10-29 01:15:44 +00:00
Rotate an image using a custom angle */
PHP_FUNCTION ( imagerotate )
{
2005-03-27 23:43:52 +00:00
zval * SIM ;
2002-10-29 01:15:44 +00:00
gdImagePtr im_dst , im_src ;
double degrees ;
long color ;
2005-03-27 23:43:52 +00:00
long ignoretransparent = 0 ;
2002-10-29 01:15:44 +00:00
2005-03-27 23:43:52 +00:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " rdl|l " , & SIM , & degrees , & color , & ignoretransparent ) = = FAILURE ) {
RETURN_FALSE ;
2002-10-29 01:15:44 +00:00
}
2005-03-27 23:43:52 +00:00
ZEND_FETCH_RESOURCE ( im_src , gdImagePtr , & SIM , - 1 , " Image " , le_gd ) ;
2002-10-29 01:15:44 +00:00
2005-03-27 23:43:52 +00:00
im_dst = gdImageRotate ( im_src , degrees , color , ignoretransparent ) ;
2002-10-29 01:15:44 +00:00
if ( im_dst ! = NULL ) {
ZEND_REGISTER_RESOURCE ( return_value , im_dst , le_gd ) ;
} else {
RETURN_FALSE ;
}
2001-04-13 12:00:12 +00:00
}
2002-06-24 19:31:44 +00:00
/* }}} */
# endif
2001-04-13 12:00:12 +00:00
2002-06-24 19:31:44 +00:00
# if HAVE_GD_IMAGESETTILE
2003-06-15 15:29:46 +00:00
/* {{{ proto bool imagesettile(resource image, resource tile)
2001-10-08 18:39:42 +00:00
Set the tile image to $ tile when filling $ image with the " IMG_COLOR_TILED " color */
2001-04-13 12:00:12 +00:00
PHP_FUNCTION ( imagesettile )
{
zval * * IM , * * TILE ;
gdImagePtr im , tile ;
2001-07-30 17:29:57 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 2 | | zend_get_parameters_ex ( 2 , & IM , & TILE ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
2001-04-13 12:00:12 +00:00
}
ZEND_FETCH_RESOURCE ( im , gdImagePtr , IM , - 1 , " Image " , le_gd ) ;
ZEND_FETCH_RESOURCE ( tile , gdImagePtr , TILE , - 1 , " Image " , le_gd ) ;
2001-08-11 16:39:07 +00:00
gdImageSetTile ( im , tile ) ;
2001-04-13 12:00:12 +00:00
RETURN_TRUE ;
}
/* }}} */
2002-06-24 19:31:44 +00:00
# endif
2001-04-13 12:00:12 +00:00
2002-06-24 19:31:44 +00:00
# if HAVE_GD_IMAGESETBRUSH
2003-06-15 15:29:46 +00:00
/* {{{ proto bool imagesetbrush(resource image, resource brush)
2001-10-08 18:39:42 +00:00
Set the brush image to $ brush when filling $ image with the " IMG_COLOR_BRUSHED " color */
2001-04-13 12:00:12 +00:00
PHP_FUNCTION ( imagesetbrush )
{
zval * * IM , * * TILE ;
gdImagePtr im , tile ;
2001-07-30 17:29:57 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 2 | | zend_get_parameters_ex ( 2 , & IM , & TILE ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
2001-04-13 12:00:12 +00:00
}
ZEND_FETCH_RESOURCE ( im , gdImagePtr , IM , - 1 , " Image " , le_gd ) ;
ZEND_FETCH_RESOURCE ( tile , gdImagePtr , TILE , - 1 , " Image " , le_gd ) ;
2001-08-11 16:39:07 +00:00
gdImageSetBrush ( im , tile ) ;
2001-04-13 12:00:12 +00:00
RETURN_TRUE ;
}
/* }}} */
2002-06-24 19:31:44 +00:00
# endif
2001-04-13 12:00:12 +00:00
2003-06-15 15:29:46 +00:00
/* {{{ proto resource imagecreate(int x_size, int y_size)
1999-11-24 22:04:49 +00:00
Create a new image */
1999-07-23 16:03:18 +00:00
PHP_FUNCTION ( imagecreate )
{
2000-02-28 16:52:03 +00:00
zval * * x_size , * * y_size ;
1999-04-16 12:15:38 +00:00
gdImagePtr im ;
2000-06-05 19:47:54 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 2 | | zend_get_parameters_ex ( 2 , & x_size , & y_size ) = = FAILURE ) {
2001-07-30 17:29:57 +00:00
ZEND_WRONG_PARAM_COUNT ( ) ;
1999-04-16 12:15:38 +00:00
}
2000-02-28 16:52:03 +00:00
convert_to_long_ex ( x_size ) ;
convert_to_long_ex ( y_size ) ;
1999-04-16 12:15:38 +00:00
2003-04-03 23:10:08 +00:00
if ( Z_LVAL_PP ( x_size ) < = 0 | | Z_LVAL_PP ( y_size ) < = 0 ) {
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Invalid image dimensions " ) ;
2003-04-03 19:18:57 +00:00
RETURN_FALSE ;
}
2000-11-23 14:56:09 +00:00
im = gdImageCreate ( Z_LVAL_PP ( x_size ) , Z_LVAL_PP ( y_size ) ) ;
1999-04-16 12:15:38 +00:00
2000-11-29 15:25:42 +00:00
ZEND_REGISTER_RESOURCE ( return_value , im , le_gd ) ;
1999-04-16 12:15:38 +00:00
}
/* }}} */
2000-07-14 21:51:31 +00:00
/* {{{ proto int imagetypes(void)
2001-05-29 07:46:07 +00:00
Return the types of images supported in a bitfield - 1 = GIF , 2 = JPEG , 4 = PNG , 8 = WBMP , 16 = XPM */
2000-07-14 21:51:31 +00:00
PHP_FUNCTION ( imagetypes )
{
2003-02-26 23:22:09 +00:00
int ret = 0 ;
2002-02-01 08:53:47 +00:00
# ifdef HAVE_GD_GIF_CREATE
2000-07-14 21:51:31 +00:00
ret = 1 ;
# endif
# ifdef HAVE_GD_JPG
ret | = 2 ;
# endif
# ifdef HAVE_GD_PNG
ret | = 4 ;
# endif
ret | = 8 ;
2003-02-01 23:23:59 +00:00
# if defined(HAVE_GD_XPM) && defined(HAVE_GD_BUNDLED)
2001-05-29 07:46:07 +00:00
ret | = 16 ;
2000-07-14 21:51:31 +00:00
# endif
2003-03-20 01:12:57 +00:00
2001-08-13 07:55:39 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 0 ) {
WRONG_PARAM_COUNT ;
}
2001-08-13 06:43:47 +00:00
2000-07-14 21:51:31 +00:00
RETURN_LONG ( ret ) ;
}
2001-06-05 13:12:10 +00:00
/* }}} */
1999-10-17 14:57:49 +00:00
2001-06-05 13:12:10 +00:00
/* {{{ _php_image_type
*/
2001-08-07 16:35:35 +00:00
static const char php_sig_gd2 [ 3 ] = { ' g ' , ' d ' , ' 2 ' } ;
2000-11-03 20:31:36 +00:00
static int _php_image_type ( char data [ 8 ] )
2000-11-03 19:53:42 +00:00
{
2003-01-08 18:11:40 +00:00
/* Based on ext/standard/image.c */
2000-11-03 19:53:42 +00:00
2003-03-20 01:12:57 +00:00
if ( data = = NULL ) {
2000-11-03 20:31:36 +00:00
return - 1 ;
2003-03-20 01:12:57 +00:00
}
2000-11-03 20:31:36 +00:00
2003-03-20 01:12:57 +00:00
if ( ! memcmp ( data , php_sig_gd2 , 3 ) ) {
2001-08-07 16:15:45 +00:00
return PHP_GDIMG_TYPE_GD2 ;
2003-03-20 01:12:57 +00:00
} else if ( ! memcmp ( data , php_sig_jpg , 3 ) ) {
2000-11-03 20:31:36 +00:00
return PHP_GDIMG_TYPE_JPG ;
2006-03-05 18:26:12 +00:00
} else if ( ! memcmp ( data , php_sig_png , 8 ) ) {
return PHP_GDIMG_TYPE_PNG ;
2003-03-20 01:12:57 +00:00
} else if ( ! memcmp ( data , php_sig_gif , 3 ) ) {
2000-11-03 20:31:36 +00:00
return PHP_GDIMG_TYPE_GIF ;
2003-03-20 01:12:57 +00:00
}
2000-11-03 20:31:36 +00:00
else {
gdIOCtx * io_ctx ;
2004-07-27 00:27:06 +00:00
io_ctx = gdNewDynamicCtxEx ( 8 , data , 0 ) ;
2000-11-03 20:31:36 +00:00
if ( io_ctx ) {
2003-03-20 01:12:57 +00:00
if ( getmbi ( ( int ( * ) ( void * ) ) gdGetC , io_ctx ) = = 0 & & skipheader ( ( int ( * ) ( void * ) ) gdGetC , io_ctx ) = = 0 ) {
2002-10-29 23:08:01 +00:00
io_ctx - > gd_free ( io_ctx ) ;
2000-11-03 20:31:36 +00:00
return PHP_GDIMG_TYPE_WBM ;
2002-10-30 01:05:16 +00:00
} else {
2002-10-29 23:08:01 +00:00
io_ctx - > gd_free ( io_ctx ) ;
2003-02-26 23:22:09 +00:00
}
2000-11-03 20:31:36 +00:00
}
}
2000-11-03 19:53:42 +00:00
return - 1 ;
}
2001-06-05 13:12:10 +00:00
/* }}} */
2000-11-03 19:53:42 +00:00
2001-06-05 13:12:10 +00:00
/* {{{ _php_image_create_from_string
*/
2001-07-30 17:29:57 +00:00
gdImagePtr _php_image_create_from_string ( zval * * data , char * tn , gdImagePtr ( * ioctx_func_p ) ( ) TSRMLS_DC )
2000-11-03 20:31:36 +00:00
{
gdImagePtr im ;
gdIOCtx * io_ctx ;
2002-09-12 21:42:33 +00:00
2004-07-27 00:27:06 +00:00
io_ctx = gdNewDynamicCtxEx ( Z_STRLEN_PP ( data ) , Z_STRVAL_PP ( data ) , 0 ) ;
2002-09-12 21:42:33 +00:00
if ( ! io_ctx ) {
2000-11-03 20:31:36 +00:00
return NULL ;
2000-11-03 19:53:42 +00:00
}
2002-09-12 21:42:33 +00:00
2000-11-03 19:53:42 +00:00
im = ( * ioctx_func_p ) ( io_ctx ) ;
2000-11-03 20:31:36 +00:00
if ( ! im ) {
2002-08-22 18:38:44 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Passed data is not in '%s' format " , tn ) ;
2000-11-03 20:31:36 +00:00
return NULL ;
}
2003-03-20 01:12:57 +00:00
2003-01-08 18:11:40 +00:00
io_ctx - > gd_free ( io_ctx ) ;
2003-03-20 01:12:57 +00:00
2000-11-03 20:31:36 +00:00
return im ;
2000-11-03 19:53:42 +00:00
}
2001-06-05 13:12:10 +00:00
/* }}} */
2000-11-03 19:53:42 +00:00
2003-06-15 15:29:46 +00:00
/* {{{ proto resource imagecreatefromstring(string image)
2000-11-03 20:31:36 +00:00
Create a new image from the image stream in the string */
2001-07-30 17:29:57 +00:00
PHP_FUNCTION ( imagecreatefromstring )
2000-11-03 19:53:42 +00:00
{
2000-11-03 20:31:36 +00:00
zval * * data ;
gdImagePtr im ;
int imtype ;
char sig [ 8 ] ;
2000-11-03 19:53:42 +00:00
2001-07-30 17:29:57 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 1 | | zend_get_parameters_ex ( 1 , & data ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-11-23 14:56:09 +00:00
}
2003-02-26 23:22:09 +00:00
2000-11-23 14:56:09 +00:00
convert_to_string_ex ( data ) ;
2005-12-16 19:02:07 +00:00
if ( Z_STRLEN_PP ( data ) < 8 ) {
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Empty string or invalid image " ) ;
RETURN_FALSE ;
}
2000-11-23 14:56:09 +00:00
memcpy ( sig , Z_STRVAL_PP ( data ) , 8 ) ;
2000-11-03 20:31:36 +00:00
2003-03-20 01:12:57 +00:00
imtype = _php_image_type ( sig ) ;
2000-11-03 20:31:36 +00:00
switch ( imtype ) {
case PHP_GDIMG_TYPE_JPG :
# ifdef HAVE_GD_JPG
2003-03-20 01:12:57 +00:00
im = _php_image_create_from_string ( data , " JPEG " , gdImageCreateFromJpegCtx TSRMLS_CC ) ;
2000-11-03 20:31:36 +00:00
# else
2002-08-22 18:38:44 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " No JPEG support in this PHP build " ) ;
2000-11-04 20:43:53 +00:00
RETURN_FALSE ;
2000-11-03 20:31:36 +00:00
# endif
break ;
case PHP_GDIMG_TYPE_PNG :
# ifdef HAVE_GD_PNG
2003-03-20 01:12:57 +00:00
im = _php_image_create_from_string ( data , " PNG " , gdImageCreateFromPngCtx TSRMLS_CC ) ;
2000-11-03 20:31:36 +00:00
# else
2002-08-22 18:38:44 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " No PNG support in this PHP build " ) ;
2000-11-04 20:43:53 +00:00
RETURN_FALSE ;
2000-11-03 20:31:36 +00:00
# endif
break ;
2003-02-26 23:22:09 +00:00
2000-11-03 20:31:36 +00:00
case PHP_GDIMG_TYPE_GIF :
2001-08-24 20:05:58 +00:00
# ifdef HAVE_GD_GIF_READ
2003-03-20 01:12:57 +00:00
im = _php_image_create_from_string ( data , " GIF " , gdImageCreateFromGifCtx TSRMLS_CC ) ;
2000-11-03 20:31:36 +00:00
# else
2002-08-22 18:38:44 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " No GIF support in this PHP build " ) ;
2000-11-04 20:43:53 +00:00
RETURN_FALSE ;
2000-11-03 20:31:36 +00:00
# endif
break ;
case PHP_GDIMG_TYPE_WBM :
2003-03-20 01:12:57 +00:00
im = _php_image_create_from_string ( data , " WBMP " , gdImageCreateFromWBMPCtx TSRMLS_CC ) ;
2001-08-07 16:15:45 +00:00
break ;
case PHP_GDIMG_TYPE_GD2 :
2003-03-20 01:12:57 +00:00
im = _php_image_create_from_string ( data , " GD2 " , gdImageCreateFromGd2Ctx TSRMLS_CC ) ;
2001-08-07 16:15:45 +00:00
break ;
2000-11-03 20:31:36 +00:00
default :
2005-12-16 19:02:07 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Data is not in a recognized format " ) ;
2002-09-12 21:42:33 +00:00
RETURN_FALSE ;
2000-11-03 20:31:36 +00:00
}
2002-09-12 21:42:33 +00:00
2000-11-03 20:31:36 +00:00
if ( ! im ) {
2002-08-22 18:38:44 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Couldn't create GD Image Stream out of Data " ) ;
2000-11-03 19:53:42 +00:00
RETURN_FALSE ;
2000-11-03 20:31:36 +00:00
}
2000-11-03 19:53:42 +00:00
2000-11-29 15:25:42 +00:00
ZEND_REGISTER_RESOURCE ( return_value , im , le_gd ) ;
2000-11-03 19:53:42 +00:00
}
2000-11-03 20:31:36 +00:00
/* }}} */
2000-11-03 19:53:42 +00:00
2001-06-05 13:12:10 +00:00
/* {{{ _php_image_create_from
*/
2003-02-26 23:22:09 +00:00
static void _php_image_create_from ( INTERNAL_FUNCTION_PARAMETERS , int image_type , char * tn , gdImagePtr ( * func_p ) ( ) , gdImagePtr ( * ioctx_func_p ) ( ) )
2000-11-23 14:56:09 +00:00
{
2001-05-29 07:46:07 +00:00
zval * * file , * * srcx , * * srcy , * * width , * * height ;
2002-03-15 21:03:08 +00:00
gdImagePtr im = NULL ;
2000-06-07 23:04:39 +00:00
char * fn = NULL ;
2002-03-16 01:28:57 +00:00
php_stream * stream ;
2002-03-15 21:03:08 +00:00
FILE * fp = NULL ;
2001-05-29 07:46:07 +00:00
int argc = ZEND_NUM_ARGS ( ) ;
2006-02-02 20:30:54 +00:00
long ignore_warning ;
2002-06-04 02:33:10 +00:00
if ( ( image_type = = PHP_GDIMG_TYPE_GD2PART & & argc ! = 5 ) | |
2003-02-26 23:22:09 +00:00
( image_type ! = PHP_GDIMG_TYPE_GD2PART & & argc ! = 1 ) | |
2002-06-04 02:33:10 +00:00
zend_get_parameters_ex ( argc , & file , & srcx , & srcy , & width , & height ) = = FAILURE ) {
2001-07-30 17:29:57 +00:00
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-02-28 16:52:03 +00:00
}
2003-02-26 23:22:09 +00:00
2000-02-28 16:52:03 +00:00
convert_to_string_ex ( file ) ;
2000-11-23 14:56:09 +00:00
2002-09-20 01:25:55 +00:00
if ( argc = = 5 & & image_type = = PHP_GDIMG_TYPE_GD2PART ) {
2001-05-29 07:46:07 +00:00
multi_convert_to_long_ex ( 4 , srcx , srcy , width , height ) ;
}
2003-02-26 23:22:09 +00:00
2000-11-23 14:56:09 +00:00
fn = Z_STRVAL_PP ( file ) ;
2006-02-19 04:29:42 +00:00
stream = php_stream_open_wrapper ( fn , " rb " , REPORT_ERRORS | IGNORE_PATH | IGNORE_URL_WIN , NULL ) ;
2002-03-15 21:03:08 +00:00
if ( stream = = NULL ) {
2000-02-28 16:52:03 +00:00
RETURN_FALSE ;
}
2000-06-07 23:04:39 +00:00
2002-03-15 21:03:08 +00:00
/* try and avoid allocating a FILE* if the stream is not naturally a FILE* */
if ( php_stream_is ( stream , PHP_STREAM_IS_STDIO ) ) {
2002-03-21 22:35:02 +00:00
if ( FAILURE = = php_stream_cast ( stream , PHP_STREAM_AS_STDIO , ( void * * ) & fp , REPORT_ERRORS ) ) {
goto out_err ;
}
2003-03-20 01:12:57 +00:00
} else if ( ioctx_func_p ) {
2005-12-26 20:34:42 +00:00
2002-03-15 21:03:08 +00:00
/* we can create an io context */
2000-09-26 09:08:02 +00:00
gdIOCtx * io_ctx ;
2001-04-01 05:42:07 +00:00
size_t buff_size ;
2002-03-15 21:03:08 +00:00
char * buff ;
2000-09-26 09:08:02 +00:00
2002-03-15 21:03:08 +00:00
/* needs to be malloc (persistent) - GD will free() it later */
2002-03-16 13:48:57 +00:00
buff_size = php_stream_copy_to_mem ( stream , & buff , PHP_STREAM_COPY_ALL , 1 ) ;
2000-09-26 09:08:02 +00:00
2003-03-20 01:17:05 +00:00
if ( ! buff_size ) {
2002-08-22 18:38:44 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Cannot read image data " ) ;
2002-03-15 21:03:08 +00:00
goto out_err ;
2001-02-01 15:40:35 +00:00
}
2003-02-26 23:22:09 +00:00
2004-07-27 00:27:06 +00:00
io_ctx = gdNewDynamicCtxEx ( buff_size , buff , 0 ) ;
2003-03-20 01:17:05 +00:00
if ( ! io_ctx ) {
2002-08-22 18:38:44 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Cannot allocate GD IO context " ) ;
2002-03-15 21:03:08 +00:00
goto out_err ;
2000-09-26 09:08:02 +00:00
}
2003-03-20 01:12:57 +00:00
2001-05-29 07:46:07 +00:00
if ( image_type = = PHP_GDIMG_TYPE_GD2PART ) {
im = ( * ioctx_func_p ) ( io_ctx , Z_LVAL_PP ( srcx ) , Z_LVAL_PP ( srcy ) , Z_LVAL_PP ( width ) , Z_LVAL_PP ( height ) ) ;
} else {
im = ( * ioctx_func_p ) ( io_ctx ) ;
}
2002-10-29 23:08:01 +00:00
io_ctx - > gd_free ( io_ctx ) ;
2005-12-26 20:34:42 +00:00
} else {
2002-03-15 21:03:08 +00:00
/* try and force the stream to be FILE* */
2003-03-20 01:12:57 +00:00
if ( FAILURE = = php_stream_cast ( stream , PHP_STREAM_AS_STDIO | PHP_STREAM_CAST_TRY_HARD , ( void * * ) & fp , REPORT_ERRORS ) ) {
2002-03-15 21:03:08 +00:00
goto out_err ;
2003-03-20 01:12:57 +00:00
}
2002-03-15 21:03:08 +00:00
}
2003-02-26 23:22:09 +00:00
2003-03-20 01:12:57 +00:00
if ( ! im & & fp ) {
2002-12-04 20:58:04 +00:00
switch ( image_type ) {
case PHP_GDIMG_TYPE_GD2PART :
im = ( * func_p ) ( fp , Z_LVAL_PP ( srcx ) , Z_LVAL_PP ( srcy ) , Z_LVAL_PP ( width ) , Z_LVAL_PP ( height ) ) ;
break ;
2002-12-11 22:25:23 +00:00
# if defined(HAVE_GD_XPM) && defined(HAVE_GD_BUNDLED)
2002-12-04 20:58:04 +00:00
case PHP_GDIMG_TYPE_XPM :
im = gdImageCreateFromXpm ( fn ) ;
break ;
2002-12-04 23:21:30 +00:00
# endif
2006-02-05 15:53:02 +00:00
# ifdef HAVE_GD_JPG
2006-02-02 20:30:54 +00:00
case PHP_GDIMG_TYPE_JPG :
ignore_warning = INI_INT ( " gd.jpeg_ignore_warning " ) ;
2006-03-10 18:15:21 +00:00
# ifdef HAVE_GD_BUNDLED
2006-02-02 20:30:54 +00:00
im = gdImageCreateFromJpeg ( fp , ignore_warning ) ;
2006-03-10 18:15:21 +00:00
# else
im = gdImageCreateFromJpeg ( fp ) ;
# endif
2006-02-02 20:30:54 +00:00
break ;
2006-02-05 15:53:02 +00:00
# endif
2006-02-02 20:30:54 +00:00
2002-12-04 20:58:04 +00:00
default :
im = ( * func_p ) ( fp ) ;
break ;
2001-05-29 07:46:07 +00:00
}
2000-09-26 09:08:02 +00:00
fflush ( fp ) ;
}
2000-02-28 16:52:03 +00:00
2002-03-15 21:03:08 +00:00
if ( im ) {
ZEND_REGISTER_RESOURCE ( return_value , im , le_gd ) ;
2002-06-15 17:46:44 +00:00
php_stream_close ( stream ) ;
2002-03-15 21:03:08 +00:00
return ;
2000-04-21 02:23:16 +00:00
}
2000-06-07 00:37:49 +00:00
2002-08-22 18:38:44 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " '%s' is not a valid %s file " , fn , tn ) ;
2002-03-15 21:03:08 +00:00
out_err :
php_stream_close ( stream ) ;
RETURN_FALSE ;
2000-06-07 00:37:49 +00:00
}
2001-06-05 13:12:10 +00:00
/* }}} */
2000-06-07 00:37:49 +00:00
2002-06-24 19:31:44 +00:00
# ifdef HAVE_GD_GIF_READ
2003-06-15 15:29:46 +00:00
/* {{{ proto resource imagecreatefromgif(string filename)
2000-06-07 00:37:49 +00:00
Create a new image from GIF file or URL */
PHP_FUNCTION ( imagecreatefromgif )
{
2001-08-11 16:39:07 +00:00
_php_image_create_from ( INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GDIMG_TYPE_GIF , " GIF " , gdImageCreateFromGif , gdImageCreateFromGifCtx ) ;
2000-06-07 00:37:49 +00:00
}
/* }}} */
2002-06-24 19:31:44 +00:00
# endif /* HAVE_GD_GIF_READ */
2000-06-07 00:37:49 +00:00
2002-06-24 19:31:44 +00:00
# ifdef HAVE_GD_JPG
2003-06-15 15:29:46 +00:00
/* {{{ proto resource imagecreatefromjpeg(string filename)
2000-06-07 00:37:49 +00:00
Create a new image from JPEG file or URL */
PHP_FUNCTION ( imagecreatefromjpeg )
{
2001-08-11 16:39:07 +00:00
_php_image_create_from ( INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GDIMG_TYPE_JPG , " JPEG " , gdImageCreateFromJpeg , gdImageCreateFromJpegCtx ) ;
2000-06-07 00:37:49 +00:00
}
/* }}} */
2002-06-24 19:31:44 +00:00
# endif /* HAVE_GD_JPG */
2000-06-07 00:37:49 +00:00
2002-06-24 19:31:44 +00:00
# ifdef HAVE_GD_PNG
2003-06-15 15:29:46 +00:00
/* {{{ proto resource imagecreatefrompng(string filename)
2000-06-07 00:37:49 +00:00
Create a new image from PNG file or URL */
PHP_FUNCTION ( imagecreatefrompng )
{
2001-08-11 16:39:07 +00:00
_php_image_create_from ( INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GDIMG_TYPE_PNG , " PNG " , gdImageCreateFromPng , gdImageCreateFromPngCtx ) ;
1999-10-17 14:57:49 +00:00
}
/* }}} */
2002-06-24 19:31:44 +00:00
# endif /* HAVE_GD_PNG */
1999-10-17 14:57:49 +00:00
2002-06-24 19:31:44 +00:00
# ifdef HAVE_GD_XBM
2003-06-15 15:29:46 +00:00
/* {{{ proto resource imagecreatefromxbm(string filename)
2000-06-07 00:37:49 +00:00
Create a new image from XBM file or URL */
PHP_FUNCTION ( imagecreatefromxbm )
1999-12-17 21:50:07 +00:00
{
2001-08-11 16:39:07 +00:00
_php_image_create_from ( INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GDIMG_TYPE_XBM , " XBM " , gdImageCreateFromXbm , NULL ) ;
2000-06-07 00:37:49 +00:00
}
/* }}} */
2002-06-24 19:31:44 +00:00
# endif /* HAVE_GD_XBM */
2000-06-07 00:37:49 +00:00
2002-12-11 22:25:23 +00:00
# if defined(HAVE_GD_XPM) && defined(HAVE_GD_BUNDLED)
2003-06-15 15:29:46 +00:00
/* {{{ proto resource imagecreatefromxpm(string filename)
2000-06-07 00:37:49 +00:00
Create a new image from XPM file or URL */
PHP_FUNCTION ( imagecreatefromxpm )
{
2001-08-11 16:39:07 +00:00
_php_image_create_from ( INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GDIMG_TYPE_XPM , " XPM " , gdImageCreateFromXpm , NULL ) ;
2000-06-07 00:37:49 +00:00
}
/* }}} */
2002-12-04 20:58:04 +00:00
# endif
2000-06-07 00:37:49 +00:00
2003-06-15 15:29:46 +00:00
/* {{{ proto resource imagecreatefromwbmp(string filename)
2000-06-25 01:44:15 +00:00
Create a new image from WBMP file or URL */
PHP_FUNCTION ( imagecreatefromwbmp )
{
2001-08-11 16:39:07 +00:00
_php_image_create_from ( INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GDIMG_TYPE_WBM , " WBMP " , gdImageCreateFromWBMP , gdImageCreateFromWBMPCtx ) ;
2000-06-25 01:44:15 +00:00
}
/* }}} */
2003-06-15 15:29:46 +00:00
/* {{{ proto resource imagecreatefromgd(string filename)
2001-05-29 07:46:07 +00:00
Create a new image from GD file or URL */
PHP_FUNCTION ( imagecreatefromgd )
{
2001-08-11 16:39:07 +00:00
_php_image_create_from ( INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GDIMG_TYPE_GD , " GD " , gdImageCreateFromGd , gdImageCreateFromGdCtx ) ;
2001-05-29 07:46:07 +00:00
}
/* }}} */
2003-06-15 15:29:46 +00:00
/* {{{ proto resource imagecreatefromgd2(string filename)
2001-05-29 07:46:07 +00:00
Create a new image from GD2 file or URL */
PHP_FUNCTION ( imagecreatefromgd2 )
{
2001-08-11 16:39:07 +00:00
_php_image_create_from ( INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GDIMG_TYPE_GD2 , " GD2 " , gdImageCreateFromGd2 , gdImageCreateFromGd2Ctx ) ;
2001-05-29 07:46:07 +00:00
}
/* }}} */
2003-06-15 15:29:46 +00:00
/* {{{ proto resource imagecreatefromgd2part(string filename, int srcX, int srcY, int width, int height)
2001-05-29 07:46:07 +00:00
Create a new image from a given part of GD2 file or URL */
PHP_FUNCTION ( imagecreatefromgd2part )
{
2001-08-11 16:39:07 +00:00
_php_image_create_from ( INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GDIMG_TYPE_GD2PART , " GD2 " , gdImageCreateFromGd2Part , gdImageCreateFromGd2PartCtx ) ;
2001-05-29 07:46:07 +00:00
}
/* }}} */
2001-06-05 13:12:10 +00:00
/* {{{ _php_image_output
*/
2003-02-26 23:22:09 +00:00
static void _php_image_output ( INTERNAL_FUNCTION_PARAMETERS , int image_type , char * tn , void ( * func_p ) ( ) )
2000-11-23 14:56:09 +00:00
{
2003-01-17 18:34:07 +00:00
zval * * imgind , * * file , * * quality , * * type ;
2000-02-28 16:52:03 +00:00
gdImagePtr im ;
2000-06-07 23:04:39 +00:00
char * fn = NULL ;
2000-02-28 16:52:03 +00:00
FILE * fp ;
2000-11-23 14:56:09 +00:00
int argc = ZEND_NUM_ARGS ( ) ;
2003-01-17 18:34:07 +00:00
int q = - 1 , i , t = 1 ;
2000-02-28 16:52:03 +00:00
2001-04-01 05:42:07 +00:00
/* The quality parameter for Wbmp stands for the threshold when called from image2wbmp() */
/* When called from imagewbmp() the quality parameter stands for the foreground color. Default: black. */
2003-01-17 18:34:07 +00:00
/* The quality parameter for gd2 stands for chunk size */
2001-01-24 09:24:26 +00:00
2003-01-17 18:34:07 +00:00
if ( argc < 1 | | argc > 4 | | zend_get_parameters_ex ( argc , & imgind , & file , & quality , & type ) = = FAILURE ) {
2001-07-30 17:29:57 +00:00
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-02-28 16:52:03 +00:00
}
2000-11-23 14:56:09 +00:00
2000-11-29 15:25:42 +00:00
ZEND_FETCH_RESOURCE ( im , gdImagePtr , imgind , - 1 , " Image " , le_gd ) ;
2000-02-28 16:52:03 +00:00
2000-06-07 23:04:39 +00:00
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 ) ;
}
2003-01-17 18:34:07 +00:00
if ( argc = = 4 ) {
convert_to_long_ex ( type ) ;
t = Z_LVAL_PP ( type ) ;
}
2000-06-07 00:37:49 +00:00
}
2003-03-12 04:15:28 +00:00
if ( ( argc = = 2 ) | | ( argc > 2 & & Z_STRLEN_PP ( file ) ) ) {
2005-11-01 17:04:29 +00:00
PHP_GD_CHECK_OPEN_BASEDIR ( fn , " Invalid filename " ) ;
2000-02-28 16:52:03 +00:00
2001-04-30 12:45:02 +00:00
fp = VCWD_FOPEN ( fn , " wb " ) ;
2000-02-28 16:52:03 +00:00
if ( ! fp ) {
2002-08-22 18:38:44 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Unable to open '%s' for writing " , fn ) ;
2000-02-28 16:52:03 +00:00
RETURN_FALSE ;
}
2003-02-26 23:22:09 +00:00
2003-03-20 01:17:05 +00:00
switch ( image_type ) {
2001-04-01 05:42:07 +00:00
case PHP_GDIMG_CONVERT_WBM :
2004-02-22 18:03:09 +00:00
if ( q = = - 1 ) {
q = 0 ;
} else if ( q < 0 | | q > 255 ) {
2002-08-22 18:38:44 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Invalid threshold value '%d'. It must be between 0 and 255 " , q ) ;
2004-02-21 16:49:39 +00:00
q = 0 ;
2001-04-01 05:42:07 +00:00
}
2004-02-17 21:30:00 +00:00
gdImageWBMP ( im , q , fp ) ;
break ;
2001-01-24 09:24:26 +00:00
case PHP_GDIMG_TYPE_JPG :
( * func_p ) ( im , fp , q ) ;
break ;
case PHP_GDIMG_TYPE_WBM :
2003-03-20 01:12:57 +00:00
for ( i = 0 ; i < gdImageColorsTotal ( im ) ; i + + ) {
if ( gdImageRed ( im , i ) = = 0 ) break ;
2001-01-24 09:24:26 +00:00
}
2001-04-01 05:42:07 +00:00
( * func_p ) ( im , i , fp ) ;
2001-01-24 09:24:26 +00:00
break ;
2002-12-04 02:37:21 +00:00
case PHP_GDIMG_TYPE_GD :
2003-03-20 01:12:57 +00:00
if ( im - > trueColor ) {
2002-12-04 02:48:23 +00:00
gdImageTrueColorToPalette ( im , 1 , 256 ) ;
2002-12-04 02:37:21 +00:00
}
( * func_p ) ( im , fp ) ;
break ;
2001-01-24 09:24:26 +00:00
default :
2003-01-17 18:34:07 +00:00
if ( q = = - 1 ) {
q = 128 ;
}
( * func_p ) ( im , fp , q , t ) ;
2001-01-24 09:24:26 +00:00
break ;
2000-06-07 00:37:49 +00:00
}
2000-02-28 16:52:03 +00:00
fflush ( fp ) ;
fclose ( fp ) ;
2000-06-07 00:37:49 +00:00
} else {
2000-02-28 16:52:03 +00:00
int b ;
FILE * tmp ;
char buf [ 4096 ] ;
2004-11-02 16:41:41 +00:00
char * path ;
2000-06-07 23:04:39 +00:00
2005-05-06 16:48:30 +00:00
tmp = php_open_temporary_file ( NULL , NULL , & path TSRMLS_CC ) ;
2000-02-28 16:52:03 +00:00
if ( tmp = = NULL ) {
2002-08-22 18:38:44 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Unable to open temporary file " ) ;
2000-02-28 16:52:03 +00:00
RETURN_FALSE ;
}
2001-01-24 09:24:26 +00:00
2003-03-20 01:12:57 +00:00
switch ( image_type ) {
2001-04-01 05:42:07 +00:00
case PHP_GDIMG_CONVERT_WBM :
2004-02-22 18:03:09 +00:00
if ( q = = - 1 ) {
q = 0 ;
} else if ( q < 0 | | q > 255 ) {
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Invalid threshold value '%d'. It must be between 0 and 255 " , q ) ;
q = 0 ;
}
2004-02-17 21:30:00 +00:00
gdImageWBMP ( im , q , tmp ) ;
break ;
2001-02-15 14:49:01 +00:00
case PHP_GDIMG_TYPE_JPG :
( * func_p ) ( im , tmp , q ) ;
break ;
case PHP_GDIMG_TYPE_WBM :
2003-03-20 01:12:57 +00:00
for ( i = 0 ; i < gdImageColorsTotal ( im ) ; i + + ) {
if ( gdImageRed ( im , i ) = = 0 ) {
break ;
}
2001-02-15 14:49:01 +00:00
}
( * func_p ) ( im , q , tmp ) ;
break ;
2002-12-04 16:29:48 +00:00
case PHP_GDIMG_TYPE_GD :
if ( im - > trueColor ) {
gdImageTrueColorToPalette ( im , 1 , 256 ) ;
}
( * func_p ) ( im , tmp ) ;
break ;
2001-02-15 14:49:01 +00:00
default :
( * func_p ) ( im , tmp ) ;
break ;
}
fseek ( tmp , 0 , SEEK_SET ) ;
while ( ( b = fread ( buf , 1 , sizeof ( buf ) , tmp ) ) > 0 ) {
2001-08-05 16:21:33 +00:00
php_write ( buf , b TSRMLS_CC ) ;
2001-02-15 14:49:01 +00:00
}
2002-09-12 21:42:33 +00:00
fclose ( tmp ) ;
2004-11-02 16:41:41 +00:00
VCWD_UNLINK ( ( const char * ) path ) ; /* make sure that the temporary file is removed */
efree ( path ) ;
2000-06-07 00:37:49 +00:00
}
2002-09-12 21:42:33 +00:00
RETURN_TRUE ;
2000-06-07 00:37:49 +00:00
}
2001-06-05 13:12:10 +00:00
/* }}} */
2000-06-07 00:37:49 +00:00
2003-06-15 20:00:08 +00:00
/* {{{ proto int imagexbm(int im, string filename [, int foreground])
Output XBM image to browser or file */
# if HAVE_GD_BUNDLED
PHP_FUNCTION ( imagexbm )
{
_php_image_output_ctx ( INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GDIMG_TYPE_XBM , " XBM " , gdImageXbmCtx ) ;
}
# endif
/* }}} */
2002-06-24 19:31:44 +00:00
# ifdef HAVE_GD_GIF_CREATE
2003-06-15 15:29:46 +00:00
/* {{{ proto bool imagegif(resource im [, string filename])
2000-06-07 23:04:39 +00:00
Output GIF image to browser or file */
PHP_FUNCTION ( imagegif )
{
2001-05-21 19:28:22 +00:00
# ifdef HAVE_GD_GIF_CTX
2001-02-01 15:40:35 +00:00
_php_image_output_ctx ( INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GDIMG_TYPE_GIF , " GIF " , gdImageGifCtx ) ;
# else
2000-06-07 23:04:39 +00:00
_php_image_output ( INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GDIMG_TYPE_GIF , " GIF " , gdImageGif ) ;
2001-02-01 15:40:35 +00:00
# endif
2000-06-07 23:04:39 +00:00
}
/* }}} */
2002-06-24 19:31:44 +00:00
# endif /* HAVE_GD_GIF_CREATE */
2000-06-07 23:04:39 +00:00
2002-06-24 19:31:44 +00:00
# ifdef HAVE_GD_PNG
2005-10-08 19:29:04 +00:00
/* {{{ proto bool imagepng(resource im [, string filename [, int quality]])
2000-06-07 00:37:49 +00:00
Output PNG image to browser or file */
PHP_FUNCTION ( imagepng )
{
2005-10-08 19:29:04 +00:00
_php_image_output_ctx ( INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GDIMG_TYPE_PNG , " PNG " , gdImagePngCtxEx ) ;
1999-10-17 14:57:49 +00:00
}
/* }}} */
2002-06-24 19:31:44 +00:00
# endif /* HAVE_GD_PNG */
1999-10-17 14:57:49 +00:00
2002-06-24 19:31:44 +00:00
# ifdef HAVE_GD_JPG
2003-06-15 15:29:46 +00:00
/* {{{ proto bool imagejpeg(resource im [, string filename [, int quality]])
2000-06-07 00:37:49 +00:00
Output JPEG image to browser or file */
PHP_FUNCTION ( imagejpeg )
2000-03-13 05:58:50 +00:00
{
2001-02-01 15:40:35 +00:00
_php_image_output_ctx ( INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GDIMG_TYPE_JPG , " JPEG " , gdImageJpegCtx ) ;
2000-03-13 05:58:50 +00:00
}
/* }}} */
2002-06-24 19:31:44 +00:00
# endif /* HAVE_GD_JPG */
2000-03-13 05:58:50 +00:00
2003-06-15 15:29:46 +00:00
/* {{{ proto bool imagewbmp(resource im [, string filename, [, int foreground]])
2000-06-07 00:37:49 +00:00
Output WBMP image to browser or file */
PHP_FUNCTION ( imagewbmp )
2000-03-13 05:58:50 +00:00
{
2001-04-01 05:42:07 +00:00
_php_image_output_ctx ( INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GDIMG_TYPE_WBM , " WBMP " , gdImageWBMPCtx ) ;
2000-03-13 05:58:50 +00:00
}
/* }}} */
2003-06-15 15:29:46 +00:00
/* {{{ proto bool imagegd(resource im [, string filename])
2001-05-29 07:46:07 +00:00
Output GD image to browser or file */
PHP_FUNCTION ( imagegd )
{
_php_image_output ( INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GDIMG_TYPE_GD , " GD " , gdImageGd ) ;
}
/* }}} */
2003-06-15 15:29:46 +00:00
/* {{{ proto bool imagegd2(resource im [, string filename, [, int chunk_size, [, int type]]])
2001-05-29 07:46:07 +00:00
Output GD2 image to browser or file */
PHP_FUNCTION ( imagegd2 )
{
_php_image_output ( INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GDIMG_TYPE_GD2 , " GD2 " , gdImageGd2 ) ;
}
/* }}} */
2003-06-15 15:29:46 +00:00
/* {{{ proto bool imagedestroy(resource im)
1999-11-24 22:04:49 +00:00
Destroy an image */
1999-07-23 16:03:18 +00:00
PHP_FUNCTION ( imagedestroy )
{
2000-11-23 14:56:09 +00:00
zval * * IM ;
2000-02-28 16:52:03 +00:00
gdImagePtr im ;
1999-04-16 12:15:38 +00:00
2000-11-23 14:56:09 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 1 | | zend_get_parameters_ex ( 1 , & IM ) = = FAILURE ) {
2001-07-30 17:29:57 +00:00
ZEND_WRONG_PARAM_COUNT ( ) ;
1999-04-16 12:15:38 +00:00
}
2000-11-29 15:25:42 +00:00
ZEND_FETCH_RESOURCE ( im , gdImagePtr , IM , - 1 , " Image " , le_gd ) ;
1999-04-16 12:15:38 +00:00
2000-11-23 14:56:09 +00:00
zend_list_delete ( Z_LVAL_PP ( IM ) ) ;
1999-04-16 12:15:38 +00:00
RETURN_TRUE ;
}
/* }}} */
2002-12-06 02:16:06 +00:00
2003-06-15 15:29:46 +00:00
/* {{{ proto int imagecolorallocate(resource im, int red, int green, int blue)
1999-11-24 22:04:49 +00:00
Allocate a color for an image */
1999-07-23 16:03:18 +00:00
PHP_FUNCTION ( imagecolorallocate )
{
2000-11-23 14:56:09 +00:00
zval * * IM , * * red , * * green , * * blue ;
1999-04-16 12:15:38 +00:00
gdImagePtr im ;
2006-01-17 16:34:58 +00:00
int ct = ( - 1 ) ;
1999-04-16 12:15:38 +00:00
2001-07-30 17:29:57 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 4 | | zend_get_parameters_ex ( 4 , & IM , & red , & green , & blue ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
1999-04-16 12:15:38 +00:00
}
2003-02-26 23:22:09 +00:00
2000-11-29 15:25:42 +00:00
ZEND_FETCH_RESOURCE ( im , gdImagePtr , IM , - 1 , " Image " , le_gd ) ;
2000-02-28 16:52:03 +00:00
convert_to_long_ex ( red ) ;
convert_to_long_ex ( green ) ;
convert_to_long_ex ( blue ) ;
2006-01-17 16:34:58 +00:00
ct = gdImageColorAllocate ( im , Z_LVAL_PP ( red ) , Z_LVAL_PP ( green ) , Z_LVAL_PP ( blue ) ) ;
if ( ct < 0 ) {
RETURN_FALSE ;
}
2003-02-26 23:22:09 +00:00
2006-01-17 16:34:58 +00:00
RETURN_LONG ( ct ) ;
1999-04-16 12:15:38 +00:00
}
/* }}} */
2003-06-15 15:29:46 +00:00
/* {{{ proto void imagepalettecopy(resource dst, resource src)
2000-06-25 02:55:31 +00:00
Copy the palette from the src image onto the dst image */
PHP_FUNCTION ( imagepalettecopy )
{
zval * * dstim , * * srcim ;
gdImagePtr dst , src ;
2001-07-30 17:29:57 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 2 | | zend_get_parameters_ex ( 2 , & dstim , & srcim ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-06-25 02:55:31 +00:00
}
2003-02-26 23:22:09 +00:00
2000-11-29 15:25:42 +00:00
ZEND_FETCH_RESOURCE ( dst , gdImagePtr , dstim , - 1 , " Image " , le_gd ) ;
ZEND_FETCH_RESOURCE ( src , gdImagePtr , srcim , - 1 , " Image " , le_gd ) ;
2000-06-25 02:55:31 +00:00
gdImagePaletteCopy ( dst , src ) ;
}
/* }}} */
2003-06-15 15:29:46 +00:00
/* {{{ proto int imagecolorat(resource im, int x, int y)
1999-11-24 22:04:49 +00:00
Get the index of the color of a pixel */
1999-07-23 16:03:18 +00:00
PHP_FUNCTION ( imagecolorat )
{
2000-11-23 14:56:09 +00:00
zval * * IM , * * x , * * y ;
1999-04-16 12:15:38 +00:00
gdImagePtr im ;
2001-07-30 17:29:57 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 3 | | zend_get_parameters_ex ( 3 , & IM , & x , & y ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
1999-04-16 12:15:38 +00:00
}
2003-02-26 23:22:09 +00:00
2000-11-29 15:25:42 +00:00
ZEND_FETCH_RESOURCE ( im , gdImagePtr , IM , - 1 , " Image " , le_gd ) ;
2000-11-23 14:56:09 +00:00
2000-02-28 16:52:03 +00:00
convert_to_long_ex ( x ) ;
convert_to_long_ex ( y ) ;
2003-03-20 01:17:05 +00:00
if ( gdImageTrueColor ( im ) ) {
2001-11-10 15:06:09 +00:00
if ( im - > tpixels & & gdImageBoundsSafe ( im , Z_LVAL_PP ( x ) , Z_LVAL_PP ( y ) ) ) {
2001-11-16 11:59:04 +00:00
RETURN_LONG ( gdImageTrueColorPixel ( im , Z_LVAL_PP ( x ) , Z_LVAL_PP ( y ) ) ) ;
2001-11-10 15:06:09 +00:00
} else {
2002-08-22 18:38:44 +00:00
php_error_docref ( NULL TSRMLS_CC , E_NOTICE , " %ld,%ld is out of bounds " , Z_LVAL_PP ( x ) , Z_LVAL_PP ( y ) ) ;
2001-11-10 15:06:09 +00:00
RETURN_FALSE ;
}
} else {
if ( im - > pixels & & gdImageBoundsSafe ( im , Z_LVAL_PP ( x ) , Z_LVAL_PP ( y ) ) ) {
RETURN_LONG ( im - > pixels [ Z_LVAL_PP ( y ) ] [ Z_LVAL_PP ( x ) ] ) ;
} else {
2002-08-22 18:38:44 +00:00
php_error_docref ( NULL TSRMLS_CC , E_NOTICE , " %ld,%ld is out of bounds " , Z_LVAL_PP ( x ) , Z_LVAL_PP ( y ) ) ;
2001-11-10 15:06:09 +00:00
RETURN_FALSE ;
}
1999-04-16 12:15:38 +00:00
}
}
/* }}} */
2003-06-15 15:29:46 +00:00
/* {{{ proto int imagecolorclosest(resource im, int red, int green, int blue)
1999-11-24 22:04:49 +00:00
Get the index of the closest color to the specified color */
1999-07-23 16:03:18 +00:00
PHP_FUNCTION ( imagecolorclosest )
{
2000-11-23 14:56:09 +00:00
zval * * IM , * * red , * * green , * * blue ;
1999-04-16 12:15:38 +00:00
gdImagePtr im ;
2001-07-30 17:29:57 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 4 | | zend_get_parameters_ex ( 4 , & IM , & red , & green , & blue ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
1999-04-16 12:15:38 +00:00
}
2003-02-26 23:22:09 +00:00
2000-11-29 15:25:42 +00:00
ZEND_FETCH_RESOURCE ( im , gdImagePtr , IM , - 1 , " Image " , le_gd ) ;
2000-02-28 16:52:03 +00:00
convert_to_long_ex ( red ) ;
convert_to_long_ex ( green ) ;
convert_to_long_ex ( blue ) ;
2003-02-26 23:22:09 +00:00
2000-11-23 14:56:09 +00:00
RETURN_LONG ( gdImageColorClosest ( im , Z_LVAL_PP ( red ) , Z_LVAL_PP ( green ) , Z_LVAL_PP ( blue ) ) ) ;
1999-04-16 12:15:38 +00:00
}
/* }}} */
2002-06-24 19:31:44 +00:00
# if HAVE_COLORCLOSESTHWB
2003-06-15 15:29:46 +00:00
/* {{{ proto int imagecolorclosesthwb(resource im, int red, int green, int blue)
2000-06-25 02:55:31 +00:00
Get the index of the color which has the hue , white and blackness nearest to the given color */
PHP_FUNCTION ( imagecolorclosesthwb )
{
2000-11-23 14:56:09 +00:00
zval * * IM , * * red , * * green , * * blue ;
2000-06-25 02:55:31 +00:00
gdImagePtr im ;
2003-02-26 23:22:09 +00:00
2001-07-30 17:29:57 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 4 | | zend_get_parameters_ex ( 4 , & IM , & red , & green , & blue ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-06-25 02:55:31 +00:00
}
2000-11-29 15:25:42 +00:00
ZEND_FETCH_RESOURCE ( im , gdImagePtr , IM , - 1 , " Image " , le_gd ) ;
2003-02-26 23:22:09 +00:00
2000-11-23 14:56:09 +00:00
convert_to_long_ex ( red ) ;
convert_to_long_ex ( green ) ;
convert_to_long_ex ( blue ) ;
2000-06-25 02:55:31 +00:00
2000-11-23 14:56:09 +00:00
RETURN_LONG ( gdImageColorClosestHWB ( im , Z_LVAL_PP ( red ) , Z_LVAL_PP ( green ) , Z_LVAL_PP ( blue ) ) ) ;
2000-06-25 02:55:31 +00:00
}
/* }}} */
2002-06-24 19:31:44 +00:00
# endif
2000-06-25 02:55:31 +00:00
2003-06-15 15:29:46 +00:00
/* {{{ proto bool imagecolordeallocate(resource im, int index)
1999-11-24 22:04:49 +00:00
De - allocate a color for an image */
1999-07-23 16:03:18 +00:00
PHP_FUNCTION ( imagecolordeallocate )
{
2000-11-23 14:56:09 +00:00
zval * * IM , * * index ;
2000-02-28 16:52:03 +00:00
int col ;
1999-04-16 12:15:38 +00:00
gdImagePtr im ;
2001-07-30 17:29:57 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 2 | | zend_get_parameters_ex ( 2 , & IM , & index ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
1999-04-16 12:15:38 +00:00
}
2000-11-29 15:25:42 +00:00
ZEND_FETCH_RESOURCE ( im , gdImagePtr , IM , - 1 , " Image " , le_gd ) ;
1999-04-16 12:15:38 +00:00
2002-11-22 23:25:14 +00:00
/* We can return right away for a truecolor image as deallocating colours is meaningless here */
if ( gdImageTrueColor ( im ) ) {
RETURN_TRUE ;
}
2000-02-28 16:52:03 +00:00
convert_to_long_ex ( index ) ;
2000-11-23 14:56:09 +00:00
col = Z_LVAL_PP ( index ) ;
1999-04-16 12:15:38 +00:00
if ( col > = 0 & & col < gdImageColorsTotal ( im ) ) {
gdImageColorDeallocate ( im , col ) ;
RETURN_TRUE ;
2000-11-23 14:56:09 +00:00
} else {
2002-08-22 19:14:27 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Color index %d out of range " , col ) ;
2000-02-28 16:52:03 +00:00
RETURN_FALSE ;
}
1999-04-16 12:15:38 +00:00
}
/* }}} */
2003-06-15 15:29:46 +00:00
/* {{{ proto int imagecolorresolve(resource im, int red, int green, int blue)
1999-11-24 22:04:49 +00:00
Get the index of the specified color or its closest possible alternative */
1999-07-23 16:03:18 +00:00
PHP_FUNCTION ( imagecolorresolve )
{
2000-11-23 14:56:09 +00:00
zval * * IM , * * red , * * green , * * blue ;
1999-04-16 12:15:38 +00:00
gdImagePtr im ;
2001-07-30 17:29:57 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 4 | | zend_get_parameters_ex ( 4 , & IM , & red , & green , & blue ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
1999-04-16 12:15:38 +00:00
}
2003-02-26 23:22:09 +00:00
2000-11-29 15:25:42 +00:00
ZEND_FETCH_RESOURCE ( im , gdImagePtr , IM , - 1 , " Image " , le_gd ) ;
2000-02-28 16:52:03 +00:00
convert_to_long_ex ( red ) ;
convert_to_long_ex ( green ) ;
convert_to_long_ex ( blue ) ;
2003-02-26 23:22:09 +00:00
2000-11-23 14:56:09 +00:00
RETURN_LONG ( gdImageColorResolve ( im , Z_LVAL_PP ( red ) , Z_LVAL_PP ( green ) , Z_LVAL_PP ( blue ) ) ) ;
1999-04-16 12:15:38 +00:00
}
/* }}} */
2003-06-15 15:29:46 +00:00
/* {{{ proto int imagecolorexact(resource im, int red, int green, int blue)
1999-11-24 22:04:49 +00:00
Get the index of the specified color */
1999-07-23 16:03:18 +00:00
PHP_FUNCTION ( imagecolorexact )
{
2000-11-23 14:56:09 +00:00
zval * * IM , * * red , * * green , * * blue ;
1999-04-16 12:15:38 +00:00
gdImagePtr im ;
2001-07-30 17:29:57 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 4 | | zend_get_parameters_ex ( 4 , & IM , & red , & green , & blue ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
1999-04-16 12:15:38 +00:00
}
2003-02-26 23:22:09 +00:00
2000-11-29 15:25:42 +00:00
ZEND_FETCH_RESOURCE ( im , gdImagePtr , IM , - 1 , " Image " , le_gd ) ;
2000-02-28 16:52:03 +00:00
convert_to_long_ex ( red ) ;
convert_to_long_ex ( green ) ;
convert_to_long_ex ( blue ) ;
2003-02-26 23:22:09 +00:00
2000-11-23 14:56:09 +00:00
RETURN_LONG ( gdImageColorExact ( im , Z_LVAL_PP ( red ) , Z_LVAL_PP ( green ) , Z_LVAL_PP ( blue ) ) ) ;
1999-04-16 12:15:38 +00:00
}
/* }}} */
2003-06-15 15:29:46 +00:00
/* {{{ proto void imagecolorset(resource im, int col, int red, int green, int blue)
1999-11-24 22:04:49 +00:00
Set the color for the specified palette index */
1999-07-23 16:03:18 +00:00
PHP_FUNCTION ( imagecolorset )
{
2000-11-23 14:56:09 +00:00
zval * * IM , * * color , * * red , * * green , * * blue ;
1999-04-16 12:15:38 +00:00
int col ;
gdImagePtr im ;
2001-07-30 17:29:57 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 5 | | zend_get_parameters_ex ( 5 , & IM , & color , & red , & green , & blue ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
1999-04-16 12:15:38 +00:00
}
2003-02-26 23:22:09 +00:00
2000-11-29 15:25:42 +00:00
ZEND_FETCH_RESOURCE ( im , gdImagePtr , IM , - 1 , " Image " , le_gd ) ;
2000-02-28 16:52:03 +00:00
convert_to_long_ex ( color ) ;
convert_to_long_ex ( red ) ;
convert_to_long_ex ( green ) ;
convert_to_long_ex ( blue ) ;
2003-02-26 23:22:09 +00:00
2000-11-23 14:56:09 +00:00
col = Z_LVAL_PP ( color ) ;
2003-02-26 23:22:09 +00:00
1999-04-16 12:15:38 +00:00
if ( col > = 0 & & col < gdImageColorsTotal ( im ) ) {
2000-11-23 14:56:09 +00:00
im - > red [ col ] = Z_LVAL_PP ( red ) ;
im - > green [ col ] = Z_LVAL_PP ( green ) ;
im - > blue [ col ] = Z_LVAL_PP ( blue ) ;
} else {
1999-04-16 12:15:38 +00:00
RETURN_FALSE ;
}
}
/* }}} */
2003-06-15 15:29:46 +00:00
/* {{{ proto array imagecolorsforindex(resource im, int col)
1999-11-24 22:04:49 +00:00
Get the colors for an index */
1999-07-23 16:03:18 +00:00
PHP_FUNCTION ( imagecolorsforindex )
{
2000-11-23 14:56:09 +00:00
zval * * IM , * * index ;
2000-02-28 16:52:03 +00:00
int col ;
1999-04-16 12:15:38 +00:00
gdImagePtr im ;
2001-07-30 17:29:57 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 2 | | zend_get_parameters_ex ( 2 , & IM , & index ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
1999-04-16 12:15:38 +00:00
}
2003-02-26 23:22:09 +00:00
2000-11-29 15:25:42 +00:00
ZEND_FETCH_RESOURCE ( im , gdImagePtr , IM , - 1 , " Image " , le_gd ) ;
1999-04-16 12:15:38 +00:00
2000-02-28 16:52:03 +00:00
convert_to_long_ex ( index ) ;
2000-11-23 14:56:09 +00:00
col = Z_LVAL_PP ( index ) ;
2005-12-27 00:11:16 +00:00
2001-11-10 15:06:09 +00:00
if ( ( col > = 0 & & gdImageTrueColor ( im ) ) | | ( ! gdImageTrueColor ( im ) & & col > = 0 & & col < gdImageColorsTotal ( im ) ) ) {
2003-01-17 21:37:56 +00:00
array_init ( return_value ) ;
2001-11-10 15:06:09 +00:00
add_assoc_long ( return_value , " red " , gdImageRed ( im , col ) ) ;
add_assoc_long ( return_value , " green " , gdImageGreen ( im , col ) ) ;
add_assoc_long ( return_value , " blue " , gdImageBlue ( im , col ) ) ;
add_assoc_long ( return_value , " alpha " , gdImageAlpha ( im , col ) ) ;
2005-12-27 00:11:16 +00:00
} else {
2002-08-22 19:14:27 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Color index %d out of range " , col ) ;
1999-04-16 12:15:38 +00:00
RETURN_FALSE ;
}
}
/* }}} */
2003-06-15 15:29:46 +00:00
/* {{{ proto bool imagegammacorrect(resource im, float inputgamma, float outputgamma)
2000-05-23 22:28:07 +00:00
Apply a gamma correction to a GD image */
2000-05-14 15:25:13 +00:00
PHP_FUNCTION ( imagegammacorrect )
{
zval * * IM , * * inputgamma , * * outputgamma ;
gdImagePtr im ;
int i ;
2000-11-23 14:56:09 +00:00
double input , output ;
2000-05-14 15:25:13 +00:00
2001-07-30 17:29:57 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 3 | | zend_get_parameters_ex ( 3 , & IM , & inputgamma , & outputgamma ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-05-14 15:25:13 +00:00
}
convert_to_double_ex ( inputgamma ) ;
convert_to_double_ex ( outputgamma ) ;
2000-11-23 14:56:09 +00:00
input = Z_DVAL_PP ( inputgamma ) ;
output = Z_DVAL_PP ( outputgamma ) ;
2000-11-29 15:25:42 +00:00
ZEND_FETCH_RESOURCE ( im , gdImagePtr , IM , - 1 , " Image " , le_gd ) ;
2000-05-14 15:25:13 +00:00
2001-07-05 21:23:28 +00:00
if ( gdImageTrueColor ( im ) ) {
int x , y , c ;
for ( y = 0 ; y < gdImageSY ( im ) ; y + + ) {
for ( x = 0 ; x < gdImageSX ( im ) ; x + + ) {
c = gdImageGetPixel ( im , x , y ) ;
2003-02-26 23:22:09 +00:00
gdImageSetPixel ( im , x , y ,
2003-03-20 01:12:57 +00:00
gdTrueColor (
( int ) ( ( pow ( ( pow ( ( gdTrueColorGetRed ( c ) / 255.0 ) , input ) ) , 1.0 / output ) * 255 ) + .5 ) ,
( int ) ( ( pow ( ( pow ( ( gdTrueColorGetGreen ( c ) / 255.0 ) , input ) ) , 1.0 / output ) * 255 ) + .5 ) ,
( int ) ( ( pow ( ( pow ( ( gdTrueColorGetBlue ( c ) / 255.0 ) , input ) ) , 1.0 / output ) * 255 ) + .5 )
)
) ;
2001-07-05 21:23:28 +00:00
}
}
RETURN_TRUE ;
}
2000-05-14 15:25:13 +00:00
for ( i = 0 ; i < gdImageColorsTotal ( im ) ; i + + ) {
2003-03-20 01:12:57 +00:00
im - > red [ i ] = ( int ) ( ( pow ( ( pow ( ( im - > red [ i ] / 255.0 ) , input ) ) , 1.0 / output ) * 255 ) + .5 ) ;
im - > green [ i ] = ( int ) ( ( pow ( ( pow ( ( im - > green [ i ] / 255.0 ) , input ) ) , 1.0 / output ) * 255 ) + .5 ) ;
im - > blue [ i ] = ( int ) ( ( pow ( ( pow ( ( im - > blue [ i ] / 255.0 ) , input ) ) , 1.0 / output ) * 255 ) + .5 ) ;
2000-05-14 15:25:13 +00:00
}
RETURN_TRUE ;
}
2000-05-23 22:28:07 +00:00
/* }}} */
2000-05-14 15:25:13 +00:00
2003-06-15 15:29:46 +00:00
/* {{{ proto bool imagesetpixel(resource im, int x, int y, int col)
1999-11-24 22:04:49 +00:00
Set a single pixel */
1999-07-23 16:03:18 +00:00
PHP_FUNCTION ( imagesetpixel )
{
2000-11-23 14:56:09 +00:00
zval * * IM , * * x , * * y , * * col ;
1999-04-16 12:15:38 +00:00
gdImagePtr im ;
2001-07-30 17:29:57 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 4 | | zend_get_parameters_ex ( 4 , & IM , & x , & y , & col ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
1999-04-16 12:15:38 +00:00
}
2000-11-29 15:25:42 +00:00
ZEND_FETCH_RESOURCE ( im , gdImagePtr , IM , - 1 , " Image " , le_gd ) ;
1999-04-16 12:15:38 +00:00
2000-11-23 14:56:09 +00:00
convert_to_long_ex ( x ) ;
convert_to_long_ex ( y ) ;
convert_to_long_ex ( col ) ;
1999-04-16 12:15:38 +00:00
2001-08-11 16:39:07 +00:00
gdImageSetPixel ( im , Z_LVAL_PP ( x ) , Z_LVAL_PP ( y ) , Z_LVAL_PP ( col ) ) ;
1999-04-16 12:15:38 +00:00
RETURN_TRUE ;
}
2003-02-26 23:22:09 +00:00
/* }}} */
1999-04-16 12:15:38 +00:00
2003-06-15 15:29:46 +00:00
/* {{{ proto bool imageline(resource im, int x1, int y1, int x2, int y2, int col)
1999-11-24 22:04:49 +00:00
Draw a line */
1999-07-23 16:03:18 +00:00
PHP_FUNCTION ( imageline )
{
2000-11-23 14:56:09 +00:00
zval * * IM , * * x1 , * * y1 , * * x2 , * * y2 , * * col ;
1999-04-16 12:15:38 +00:00
gdImagePtr im ;
2001-07-30 17:29:57 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 6 | | zend_get_parameters_ex ( 6 , & IM , & x1 , & y1 , & x2 , & y2 , & col ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
1999-04-16 12:15:38 +00:00
}
2000-11-29 15:25:42 +00:00
ZEND_FETCH_RESOURCE ( im , gdImagePtr , IM , - 1 , " Image " , le_gd ) ;
1999-04-16 12:15:38 +00:00
2000-11-23 14:56:09 +00:00
convert_to_long_ex ( x1 ) ;
convert_to_long_ex ( y1 ) ;
convert_to_long_ex ( x2 ) ;
convert_to_long_ex ( y2 ) ;
convert_to_long_ex ( col ) ;
1999-04-16 12:15:38 +00:00
2002-12-11 20:44:44 +00:00
# ifdef HAVE_GD_BUNDLED
2003-03-20 01:12:57 +00:00
if ( im - > antialias ) {
2002-12-11 20:44:44 +00:00
gdImageAALine ( im , Z_LVAL_PP ( x1 ) , Z_LVAL_PP ( y1 ) , Z_LVAL_PP ( x2 ) , Z_LVAL_PP ( y2 ) , Z_LVAL_PP ( col ) ) ;
2003-03-20 01:12:57 +00:00
} else
2003-02-26 23:22:09 +00:00
# endif
2003-03-20 01:12:57 +00:00
{
2002-12-11 20:44:44 +00:00
gdImageLine ( im , Z_LVAL_PP ( x1 ) , Z_LVAL_PP ( y1 ) , Z_LVAL_PP ( x2 ) , Z_LVAL_PP ( y2 ) , Z_LVAL_PP ( col ) ) ;
2003-03-20 01:12:57 +00:00
}
1999-04-16 12:15:38 +00:00
RETURN_TRUE ;
}
2003-02-26 23:22:09 +00:00
/* }}} */
1999-04-16 12:15:38 +00:00
2003-06-15 15:29:46 +00:00
/* {{{ proto bool imagedashedline(resource im, int x1, int y1, int x2, int y2, int col)
1999-11-24 22:04:49 +00:00
Draw a dashed line */
1999-07-23 16:03:18 +00:00
PHP_FUNCTION ( imagedashedline )
{
2000-11-23 14:56:09 +00:00
zval * * IM , * * x1 , * * y1 , * * x2 , * * y2 , * * col ;
1999-04-16 12:15:38 +00:00
gdImagePtr im ;
2001-07-30 17:29:57 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 6 | | zend_get_parameters_ex ( 6 , & IM , & x1 , & y1 , & x2 , & y2 , & col ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
1999-04-16 12:15:38 +00:00
}
2000-11-29 15:25:42 +00:00
ZEND_FETCH_RESOURCE ( im , gdImagePtr , IM , - 1 , " Image " , le_gd ) ;
1999-04-16 12:15:38 +00:00
2000-11-23 14:56:09 +00:00
convert_to_long_ex ( x1 ) ;
convert_to_long_ex ( y1 ) ;
convert_to_long_ex ( x2 ) ;
convert_to_long_ex ( y2 ) ;
convert_to_long_ex ( col ) ;
1999-04-16 12:15:38 +00:00
2001-08-11 16:39:07 +00:00
gdImageDashedLine ( im , Z_LVAL_PP ( x1 ) , Z_LVAL_PP ( y1 ) , Z_LVAL_PP ( x2 ) , Z_LVAL_PP ( y2 ) , Z_LVAL_PP ( col ) ) ;
1999-04-16 12:15:38 +00:00
RETURN_TRUE ;
}
/* }}} */
2003-06-15 15:29:46 +00:00
/* {{{ proto bool imagerectangle(resource im, int x1, int y1, int x2, int y2, int col)
1999-11-24 22:04:49 +00:00
Draw a rectangle */
1999-07-23 16:03:18 +00:00
PHP_FUNCTION ( imagerectangle )
{
2000-11-23 14:56:09 +00:00
zval * * IM , * * x1 , * * y1 , * * x2 , * * y2 , * * col ;
1999-04-16 12:15:38 +00:00
gdImagePtr im ;
2001-07-30 17:29:57 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 6 | | zend_get_parameters_ex ( 6 , & IM , & x1 , & y1 , & x2 , & y2 , & col ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
1999-04-16 12:15:38 +00:00
}
2000-11-29 15:25:42 +00:00
ZEND_FETCH_RESOURCE ( im , gdImagePtr , IM , - 1 , " Image " , le_gd ) ;
1999-04-16 12:15:38 +00:00
2000-11-23 14:56:09 +00:00
convert_to_long_ex ( x1 ) ;
convert_to_long_ex ( y1 ) ;
convert_to_long_ex ( x2 ) ;
convert_to_long_ex ( y2 ) ;
convert_to_long_ex ( col ) ;
1999-04-16 12:15:38 +00:00
2001-08-11 16:39:07 +00:00
gdImageRectangle ( im , Z_LVAL_PP ( x1 ) , Z_LVAL_PP ( y1 ) , Z_LVAL_PP ( x2 ) , Z_LVAL_PP ( y2 ) , Z_LVAL_PP ( col ) ) ;
1999-04-16 12:15:38 +00:00
RETURN_TRUE ;
}
2003-02-26 23:22:09 +00:00
/* }}} */
1999-04-16 12:15:38 +00:00
2003-06-15 15:29:46 +00:00
/* {{{ proto bool imagefilledrectangle(resource im, int x1, int y1, int x2, int y2, int col)
1999-11-24 22:04:49 +00:00
Draw a filled rectangle */
1999-07-23 16:03:18 +00:00
PHP_FUNCTION ( imagefilledrectangle )
{
2000-11-23 14:56:09 +00:00
zval * * IM , * * x1 , * * y1 , * * x2 , * * y2 , * * col ;
1999-04-16 12:15:38 +00:00
gdImagePtr im ;
2001-07-30 17:29:57 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 6 | | zend_get_parameters_ex ( 6 , & IM , & x1 , & y1 , & x2 , & y2 , & col ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
1999-04-16 12:15:38 +00:00
}
2000-11-29 15:25:42 +00:00
ZEND_FETCH_RESOURCE ( im , gdImagePtr , IM , - 1 , " Image " , le_gd ) ;
1999-04-16 12:15:38 +00:00
2000-11-23 14:56:09 +00:00
convert_to_long_ex ( x1 ) ;
convert_to_long_ex ( y1 ) ;
convert_to_long_ex ( x2 ) ;
convert_to_long_ex ( y2 ) ;
convert_to_long_ex ( col ) ;
1999-04-16 12:15:38 +00:00
2001-08-11 16:39:07 +00:00
gdImageFilledRectangle ( im , Z_LVAL_PP ( x1 ) , Z_LVAL_PP ( y1 ) , Z_LVAL_PP ( x2 ) , Z_LVAL_PP ( y2 ) , Z_LVAL_PP ( col ) ) ;
1999-04-16 12:15:38 +00:00
RETURN_TRUE ;
}
2003-02-26 23:22:09 +00:00
/* }}} */
1999-04-16 12:15:38 +00:00
2003-06-15 15:29:46 +00:00
/* {{{ proto bool imagearc(resource im, int cx, int cy, int w, int h, int s, int e, int col)
1999-11-24 22:04:49 +00:00
Draw a partial ellipse */
1999-07-23 16:03:18 +00:00
PHP_FUNCTION ( imagearc )
{
2000-11-23 14:56:09 +00:00
zval * * IM , * * cx , * * cy , * * w , * * h , * * ST , * * E , * * col ;
1999-04-16 12:15:38 +00:00
gdImagePtr im ;
2001-08-11 16:39:07 +00:00
int e , st ;
1999-04-16 12:15:38 +00:00
2001-07-30 17:29:57 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 8 | | zend_get_parameters_ex ( 8 , & IM , & cx , & cy , & w , & h , & ST , & E , & col ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
1999-04-16 12:15:38 +00:00
}
2000-11-29 15:25:42 +00:00
ZEND_FETCH_RESOURCE ( im , gdImagePtr , IM , - 1 , " Image " , le_gd ) ;
1999-04-16 12:15:38 +00:00
2000-11-23 14:56:09 +00:00
convert_to_long_ex ( cx ) ;
convert_to_long_ex ( cy ) ;
convert_to_long_ex ( w ) ;
convert_to_long_ex ( h ) ;
2000-02-28 16:52:03 +00:00
convert_to_long_ex ( ST ) ;
convert_to_long_ex ( E ) ;
2000-11-23 14:56:09 +00:00
convert_to_long_ex ( col ) ;
2000-02-28 16:52:03 +00:00
2000-11-23 14:56:09 +00:00
e = Z_LVAL_PP ( E ) ;
2003-03-20 01:12:57 +00:00
if ( e < 0 ) {
e % = 360 ;
}
2003-12-28 21:08:46 +00:00
2000-11-23 14:56:09 +00:00
st = Z_LVAL_PP ( ST ) ;
2003-03-20 01:12:57 +00:00
if ( st < 0 ) {
st % = 360 ;
}
2003-12-28 21:08:46 +00:00
2001-08-11 16:39:07 +00:00
gdImageArc ( im , Z_LVAL_PP ( cx ) , Z_LVAL_PP ( cy ) , Z_LVAL_PP ( w ) , Z_LVAL_PP ( h ) , st , e , Z_LVAL_PP ( col ) ) ;
1999-04-16 12:15:38 +00:00
RETURN_TRUE ;
}
2003-02-26 23:22:09 +00:00
/* }}} */
1999-04-16 12:15:38 +00:00
2003-06-15 15:29:46 +00:00
/* {{{ proto bool imageellipse(resource im, int cx, int cy, int w, int h, int color)
2002-07-28 10:00:37 +00:00
Draw an ellipse */
PHP_FUNCTION ( imageellipse )
{
zval * * IM , * * cx , * * cy , * * w , * * h , * * color ;
gdImagePtr im ;
if ( ZEND_NUM_ARGS ( ) ! = 6 | | zend_get_parameters_ex ( 6 , & IM , & cx , & cy , & w , & h , & color ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
}
2003-02-26 23:22:09 +00:00
2002-07-28 10:00:37 +00:00
ZEND_FETCH_RESOURCE ( im , gdImagePtr , IM , - 1 , " Image " , le_gd ) ;
convert_to_long_ex ( cx ) ;
convert_to_long_ex ( cy ) ;
convert_to_long_ex ( w ) ;
convert_to_long_ex ( h ) ;
convert_to_long_ex ( color ) ;
# ifdef HAVE_GD_IMAGEELLIPSE /* this function is missing from GD 2.0.1 */
gdImageEllipse ( im , Z_LVAL_PP ( cx ) , Z_LVAL_PP ( cy ) , Z_LVAL_PP ( w ) , Z_LVAL_PP ( h ) , Z_LVAL_PP ( color ) ) ;
# else
gdImageArc ( im , Z_LVAL_PP ( cx ) , Z_LVAL_PP ( cy ) , Z_LVAL_PP ( w ) , Z_LVAL_PP ( h ) , 0 , 360 , Z_LVAL_PP ( color ) ) ;
# endif
RETURN_TRUE ;
}
/* }}} */
2003-06-15 15:29:46 +00:00
/* {{{ proto bool imagefilltoborder(resource im, int x, int y, int border, int col)
1999-11-24 22:04:49 +00:00
Flood fill to specific color */
1999-07-23 16:03:18 +00:00
PHP_FUNCTION ( imagefilltoborder )
{
2000-11-23 14:56:09 +00:00
zval * * IM , * * x , * * y , * * border , * * col ;
1999-04-16 12:15:38 +00:00
gdImagePtr im ;
2001-07-30 17:29:57 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 5 | | zend_get_parameters_ex ( 5 , & IM , & x , & y , & border , & col ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
1999-04-16 12:15:38 +00:00
}
2000-11-29 15:25:42 +00:00
ZEND_FETCH_RESOURCE ( im , gdImagePtr , IM , - 1 , " Image " , le_gd ) ;
1999-04-16 12:15:38 +00:00
2000-11-23 14:56:09 +00:00
convert_to_long_ex ( x ) ;
convert_to_long_ex ( y ) ;
convert_to_long_ex ( border ) ;
convert_to_long_ex ( col ) ;
1999-04-16 12:15:38 +00:00
2001-08-11 16:39:07 +00:00
gdImageFillToBorder ( im , Z_LVAL_PP ( x ) , Z_LVAL_PP ( y ) , Z_LVAL_PP ( border ) , Z_LVAL_PP ( col ) ) ;
1999-04-16 12:15:38 +00:00
RETURN_TRUE ;
}
2003-02-26 23:22:09 +00:00
/* }}} */
1999-04-16 12:15:38 +00:00
2003-06-15 15:29:46 +00:00
/* {{{ proto bool imagefill(resource im, int x, int y, int col)
1999-11-24 22:04:49 +00:00
Flood fill */
1999-07-23 16:03:18 +00:00
PHP_FUNCTION ( imagefill )
{
2000-11-23 14:56:09 +00:00
zval * * IM , * * x , * * y , * * col ;
1999-04-16 12:15:38 +00:00
gdImagePtr im ;
2001-07-30 17:29:57 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 4 | | zend_get_parameters_ex ( 4 , & IM , & x , & y , & col ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
1999-04-16 12:15:38 +00:00
}
2000-11-29 15:25:42 +00:00
ZEND_FETCH_RESOURCE ( im , gdImagePtr , IM , - 1 , " Image " , le_gd ) ;
1999-04-16 12:15:38 +00:00
2000-11-23 14:56:09 +00:00
convert_to_long_ex ( x ) ;
convert_to_long_ex ( y ) ;
convert_to_long_ex ( col ) ;
1999-04-16 12:15:38 +00:00
2001-08-11 16:39:07 +00:00
gdImageFill ( im , Z_LVAL_PP ( x ) , Z_LVAL_PP ( y ) , Z_LVAL_PP ( col ) ) ;
1999-04-16 12:15:38 +00:00
RETURN_TRUE ;
}
2003-02-26 23:22:09 +00:00
/* }}} */
1999-04-16 12:15:38 +00:00
2003-06-15 15:29:46 +00:00
/* {{{ proto int imagecolorstotal(resource im)
1999-11-24 22:04:49 +00:00
Find out the number of colors in an image ' s palette */
1999-07-23 16:03:18 +00:00
PHP_FUNCTION ( imagecolorstotal )
{
2000-02-28 16:52:03 +00:00
zval * * IM ;
1999-04-16 12:15:38 +00:00
gdImagePtr im ;
2001-07-30 17:29:57 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 1 | | zend_get_parameters_ex ( 1 , & IM ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
1999-04-16 12:15:38 +00:00
}
2000-11-23 14:56:09 +00:00
2000-11-29 15:25:42 +00:00
ZEND_FETCH_RESOURCE ( im , gdImagePtr , IM , - 1 , " Image " , le_gd ) ;
1999-04-16 12:15:38 +00:00
RETURN_LONG ( gdImageColorsTotal ( im ) ) ;
}
2003-02-26 23:22:09 +00:00
/* }}} */
1999-04-16 12:15:38 +00:00
2003-06-15 15:29:46 +00:00
/* {{{ proto int imagecolortransparent(resource im [, int col])
1999-11-24 22:04:49 +00:00
Define a color as transparent */
1999-07-23 16:03:18 +00:00
PHP_FUNCTION ( imagecolortransparent )
{
2000-08-22 04:11:57 +00:00
zval * * IM , * * COL ;
1999-04-16 12:15:38 +00:00
gdImagePtr im ;
2003-03-20 01:12:57 +00:00
switch ( ZEND_NUM_ARGS ( ) ) {
case 1 :
if ( zend_get_parameters_ex ( 1 , & IM ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
}
break ;
case 2 :
if ( zend_get_parameters_ex ( 2 , & IM , & COL ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
}
convert_to_long_ex ( COL ) ;
break ;
default :
2001-07-30 17:29:57 +00:00
ZEND_WRONG_PARAM_COUNT ( ) ;
1999-04-16 12:15:38 +00:00
}
2000-11-29 15:25:42 +00:00
ZEND_FETCH_RESOURCE ( im , gdImagePtr , IM , - 1 , " Image " , le_gd ) ;
1999-04-16 12:15:38 +00:00
2000-08-22 04:11:57 +00:00
if ( ZEND_NUM_ARGS ( ) > 1 ) {
gdImageColorTransparent ( im , Z_LVAL_PP ( COL ) ) ;
1999-04-16 12:15:38 +00:00
}
2000-11-23 14:56:09 +00:00
RETURN_LONG ( gdImageGetTransparent ( im ) ) ;
1999-04-16 12:15:38 +00:00
}
2003-02-26 23:22:09 +00:00
/* }}} */
1999-04-16 12:15:38 +00:00
2003-06-15 15:29:46 +00:00
/* {{{ proto int imageinterlace(resource im [, int interlace])
1999-11-24 22:04:49 +00:00
Enable or disable interlace */
1999-07-23 16:03:18 +00:00
PHP_FUNCTION ( imageinterlace )
{
2000-11-23 14:56:09 +00:00
zval * * IM , * * INT ;
1999-04-16 12:15:38 +00:00
gdImagePtr im ;
2003-03-20 01:12:57 +00:00
switch ( ZEND_NUM_ARGS ( ) ) {
case 1 :
if ( zend_get_parameters_ex ( 1 , & IM ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
}
break ;
case 2 :
if ( zend_get_parameters_ex ( 2 , & IM , & INT ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
}
convert_to_long_ex ( INT ) ;
break ;
default :
2001-07-30 17:29:57 +00:00
ZEND_WRONG_PARAM_COUNT ( ) ;
1999-04-16 12:15:38 +00:00
}
2000-11-29 15:25:42 +00:00
ZEND_FETCH_RESOURCE ( im , gdImagePtr , IM , - 1 , " Image " , le_gd ) ;
1999-04-16 12:15:38 +00:00
2000-11-23 14:56:09 +00:00
if ( ZEND_NUM_ARGS ( ) > 1 ) {
2001-08-11 16:39:07 +00:00
gdImageInterlace ( im , Z_LVAL_PP ( INT ) ) ;
1999-04-16 12:15:38 +00:00
}
2000-11-23 14:56:09 +00:00
RETURN_LONG ( gdImageGetInterlaced ( im ) ) ;
1999-04-16 12:15:38 +00:00
}
2003-02-26 23:22:09 +00:00
/* }}} */
1999-04-16 12:15:38 +00:00
2001-06-05 13:12:10 +00:00
/* {{{ php_imagepolygon
arg = 0 normal polygon
1999-04-16 12:15:38 +00:00
arg = 1 filled polygon */
/* im, points, num_points, col */
2003-02-26 23:22:09 +00:00
static void php_imagepolygon ( INTERNAL_FUNCTION_PARAMETERS , int filled )
2001-06-07 13:17:02 +00:00
{
2000-02-28 16:52:03 +00:00
zval * * IM , * * POINTS , * * NPOINTS , * * COL ;
2005-12-06 01:26:39 +00:00
zval * * var = NULL ;
1999-04-16 12:15:38 +00:00
gdImagePtr im ;
2003-02-26 23:22:09 +00:00
gdPointPtr points ;
1999-04-16 12:15:38 +00:00
int npoints , col , nelem , i ;
2001-07-30 17:29:57 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 4 | | zend_get_parameters_ex ( 4 , & IM , & POINTS , & NPOINTS , & COL ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
1999-04-16 12:15:38 +00:00
}
2000-11-29 15:25:42 +00:00
ZEND_FETCH_RESOURCE ( im , gdImagePtr , IM , - 1 , " Image " , le_gd ) ;
1999-04-16 12:15:38 +00:00
2000-02-28 16:52:03 +00:00
convert_to_long_ex ( NPOINTS ) ;
convert_to_long_ex ( COL ) ;
1999-04-16 12:15:38 +00:00
2000-11-23 14:56:09 +00:00
npoints = Z_LVAL_PP ( NPOINTS ) ;
col = Z_LVAL_PP ( COL ) ;
1999-04-16 12:15:38 +00:00
2001-09-25 22:49:04 +00:00
if ( Z_TYPE_PP ( POINTS ) ! = IS_ARRAY ) {
2002-08-22 18:38:44 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " 2nd argument to imagepolygon not an array " ) ;
1999-04-16 12:15:38 +00:00
RETURN_FALSE ;
}
2001-09-25 22:49:04 +00:00
nelem = zend_hash_num_elements ( Z_ARRVAL_PP ( POINTS ) ) ;
1999-04-16 12:15:38 +00:00
if ( nelem < 6 ) {
2002-08-22 18:38:44 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " You must have at least 3 points in your array " ) ;
1999-04-16 12:15:38 +00:00
RETURN_FALSE ;
}
if ( nelem < npoints * 2 ) {
2002-08-22 18:38:44 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Trying to use %d points in array with only %d points " , npoints , nelem / 2 ) ;
1999-04-16 12:15:38 +00:00
RETURN_FALSE ;
}
2003-08-12 00:58:52 +00:00
points = ( gdPointPtr ) safe_emalloc ( npoints , sizeof ( gdPoint ) , 0 ) ;
1999-04-16 12:15:38 +00:00
for ( i = 0 ; i < npoints ; i + + ) {
2001-09-25 22:49:04 +00:00
if ( zend_hash_index_find ( Z_ARRVAL_PP ( POINTS ) , ( i * 2 ) , ( void * * ) & var ) = = SUCCESS ) {
2000-02-28 16:52:03 +00:00
SEPARATE_ZVAL ( ( var ) ) ;
1999-07-23 16:03:18 +00:00
convert_to_long ( * var ) ;
2000-11-23 14:56:09 +00:00
points [ i ] . x = Z_LVAL_PP ( var ) ;
1999-04-16 12:15:38 +00:00
}
2001-09-25 22:49:04 +00:00
if ( zend_hash_index_find ( Z_ARRVAL_PP ( POINTS ) , ( i * 2 ) + 1 , ( void * * ) & var ) = = SUCCESS ) {
1999-07-23 16:03:18 +00:00
SEPARATE_ZVAL ( var ) ;
convert_to_long ( * var ) ;
2000-11-23 14:56:09 +00:00
points [ i ] . y = Z_LVAL_PP ( var ) ;
1999-04-16 12:15:38 +00:00
}
}
if ( filled ) {
gdImageFilledPolygon ( im , points , npoints , col ) ;
2000-11-23 14:56:09 +00:00
} else {
1999-04-16 12:15:38 +00:00
gdImagePolygon ( im , points , npoints , col ) ;
}
2000-05-01 18:56:58 +00:00
efree ( points ) ;
1999-04-16 12:15:38 +00:00
RETURN_TRUE ;
}
2001-06-05 13:12:10 +00:00
/* }}} */
1999-04-16 12:15:38 +00:00
2003-06-15 15:29:46 +00:00
/* {{{ proto bool imagepolygon(resource im, array point, int num_points, int col)
1999-11-24 22:04:49 +00:00
Draw a polygon */
1999-05-21 10:06:25 +00:00
PHP_FUNCTION ( imagepolygon )
1999-04-16 12:15:38 +00:00
{
1999-12-17 21:50:07 +00:00
php_imagepolygon ( INTERNAL_FUNCTION_PARAM_PASSTHRU , 0 ) ;
1999-04-16 12:15:38 +00:00
}
/* }}} */
2003-06-15 15:29:46 +00:00
/* {{{ proto bool imagefilledpolygon(resource im, array point, int num_points, int col)
1999-11-24 22:04:49 +00:00
Draw a filled polygon */
1999-05-21 10:06:25 +00:00
PHP_FUNCTION ( imagefilledpolygon )
1999-04-16 12:15:38 +00:00
{
1999-12-17 21:50:07 +00:00
php_imagepolygon ( INTERNAL_FUNCTION_PARAM_PASSTHRU , 1 ) ;
1999-04-16 12:15:38 +00:00
}
/* }}} */
2001-06-05 13:12:10 +00:00
/* {{{ php_find_gd_font
*/
2003-03-26 06:30:45 +00:00
static gdFontPtr php_find_gd_font ( int size TSRMLS_DC )
1999-04-16 12:15:38 +00:00
{
gdFontPtr font ;
int ind_type ;
2003-02-26 23:22:09 +00:00
1999-04-16 12:15:38 +00:00
switch ( size ) {
2002-09-12 21:42:33 +00:00
case 1 :
1999-04-16 12:15:38 +00:00
font = gdFontTiny ;
break ;
2002-09-12 21:42:33 +00:00
case 2 :
1999-04-16 12:15:38 +00:00
font = gdFontSmall ;
break ;
2002-09-12 21:42:33 +00:00
case 3 :
1999-04-16 12:15:38 +00:00
font = gdFontMediumBold ;
break ;
2002-09-12 21:42:33 +00:00
case 4 :
1999-04-16 12:15:38 +00:00
font = gdFontLarge ;
break ;
2002-09-12 21:42:33 +00:00
case 5 :
1999-04-16 12:15:38 +00:00
font = gdFontGiant ;
break ;
2002-09-12 21:42:33 +00:00
default :
1999-12-17 19:51:39 +00:00
font = zend_list_find ( size - 5 , & ind_type ) ;
2000-11-29 15:25:42 +00:00
if ( ! font | | ind_type ! = le_gd_font ) {
1999-04-16 12:15:38 +00:00
if ( size < 1 ) {
font = gdFontTiny ;
} else {
font = gdFontGiant ;
}
}
break ;
}
return font ;
}
2001-06-05 13:12:10 +00:00
/* }}} */
1999-04-16 12:15:38 +00:00
2001-06-05 13:12:10 +00:00
/* {{{ php_imagefontsize
1999-04-16 12:15:38 +00:00
* arg = 0 ImageFontWidth
* arg = 1 ImageFontHeight
*/
1999-12-17 21:50:07 +00:00
static void php_imagefontsize ( INTERNAL_FUNCTION_PARAMETERS , int arg )
1999-04-16 12:15:38 +00:00
{
2000-11-23 14:56:09 +00:00
zval * * SIZE ;
1999-04-16 12:15:38 +00:00
gdFontPtr font ;
2001-07-30 17:29:57 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 1 | | zend_get_parameters_ex ( 1 , & SIZE ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
1999-04-16 12:15:38 +00:00
}
2003-02-26 23:22:09 +00:00
2000-11-23 14:56:09 +00:00
convert_to_long_ex ( SIZE ) ;
2003-03-26 06:30:45 +00:00
font = php_find_gd_font ( Z_LVAL_PP ( SIZE ) TSRMLS_CC ) ;
1999-04-16 12:15:38 +00:00
RETURN_LONG ( arg ? font - > h : font - > w ) ;
}
2001-06-05 13:12:10 +00:00
/* }}} */
1999-04-16 12:15:38 +00:00
/* {{{ proto int imagefontwidth(int font)
1999-11-24 22:04:49 +00:00
Get font width */
1999-05-21 10:06:25 +00:00
PHP_FUNCTION ( imagefontwidth )
1999-04-16 12:15:38 +00:00
{
1999-12-17 21:50:07 +00:00
php_imagefontsize ( INTERNAL_FUNCTION_PARAM_PASSTHRU , 0 ) ;
1999-04-16 12:15:38 +00:00
}
/* }}} */
/* {{{ proto int imagefontheight(int font)
2000-01-24 20:25:57 +00:00
Get font height */
1999-05-21 10:06:25 +00:00
PHP_FUNCTION ( imagefontheight )
1999-04-16 12:15:38 +00:00
{
1999-12-17 21:50:07 +00:00
php_imagefontsize ( INTERNAL_FUNCTION_PARAM_PASSTHRU , 1 ) ;
1999-04-16 12:15:38 +00:00
}
/* }}} */
2001-06-05 13:12:10 +00:00
/* {{{ php_gdimagecharup
* workaround for a bug in gd 1.2 */
2001-08-22 08:34:04 +00:00
static void php_gdimagecharup ( gdImagePtr im , gdFontPtr f , int x , int y , int c , int color )
1999-04-16 12:15:38 +00:00
{
int cx , cy , px , py , fline ;
cx = 0 ;
cy = 0 ;
2003-03-20 01:12:57 +00:00
1999-04-16 12:15:38 +00:00
if ( ( c < f - > offset ) | | ( c > = ( f - > offset + f - > nchars ) ) ) {
return ;
}
2003-03-20 01:12:57 +00:00
1999-04-16 12:15:38 +00:00
fline = ( c - f - > offset ) * f - > h * f - > w ;
for ( py = y ; ( py > ( y - f - > w ) ) ; py - - ) {
for ( px = x ; ( px < ( x + f - > h ) ) ; px + + ) {
if ( f - > data [ fline + cy * f - > w + cx ] ) {
2003-02-26 23:22:09 +00:00
gdImageSetPixel ( im , px , py , color ) ;
1999-04-16 12:15:38 +00:00
}
cy + + ;
}
cy = 0 ;
cx + + ;
}
}
2001-06-05 13:12:10 +00:00
/* }}} */
1999-04-16 12:15:38 +00:00
2001-06-05 13:12:10 +00:00
/* {{{ php_imagechar
1999-04-16 12:15:38 +00:00
* arg = 0 ImageChar
* arg = 1 ImageCharUp
* arg = 2 ImageString
* arg = 3 ImageStringUp
*/
2003-02-26 23:22:09 +00:00
static void php_imagechar ( INTERNAL_FUNCTION_PARAMETERS , int mode )
2000-11-23 14:56:09 +00:00
{
2000-02-28 16:52:03 +00:00
zval * * IM , * * SIZE , * * X , * * Y , * * C , * * COL ;
1999-04-16 12:15:38 +00:00
gdImagePtr im ;
int ch = 0 , col , x , y , size , i , l = 0 ;
2000-02-08 22:21:43 +00:00
unsigned char * str = NULL ;
1999-04-16 12:15:38 +00:00
gdFontPtr font ;
2001-07-30 17:29:57 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 6 | | zend_get_parameters_ex ( 6 , & IM , & SIZE , & X , & Y , & C , & COL ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
1999-04-16 12:15:38 +00:00
}
2000-11-29 15:25:42 +00:00
ZEND_FETCH_RESOURCE ( im , gdImagePtr , IM , - 1 , " Image " , le_gd ) ;
2000-02-28 16:52:03 +00:00
convert_to_long_ex ( SIZE ) ;
convert_to_long_ex ( X ) ;
convert_to_long_ex ( Y ) ;
convert_to_string_ex ( C ) ;
convert_to_long_ex ( COL ) ;
1999-04-16 12:15:38 +00:00
2000-11-23 14:56:09 +00:00
col = Z_LVAL_PP ( COL ) ;
1999-04-16 12:15:38 +00:00
if ( mode < 2 ) {
2000-11-23 14:56:09 +00:00
ch = ( int ) ( ( unsigned char ) * ( Z_STRVAL_PP ( C ) ) ) ;
1999-04-16 12:15:38 +00:00
} else {
2000-11-23 14:56:09 +00:00
str = ( unsigned char * ) estrndup ( Z_STRVAL_PP ( C ) , Z_STRLEN_PP ( C ) ) ;
2000-02-08 22:21:43 +00:00
l = strlen ( str ) ;
1999-04-16 12:15:38 +00:00
}
2000-11-23 14:56:09 +00:00
y = Z_LVAL_PP ( Y ) ;
x = Z_LVAL_PP ( X ) ;
size = Z_LVAL_PP ( SIZE ) ;
1999-04-16 12:15:38 +00:00
2003-03-26 06:30:45 +00:00
font = php_find_gd_font ( size TSRMLS_CC ) ;
1999-04-16 12:15:38 +00:00
2003-03-20 01:17:05 +00:00
switch ( mode ) {
2002-09-12 21:42:33 +00:00
case 0 :
1999-04-16 12:15:38 +00:00
gdImageChar ( im , font , x , y , ch , col ) ;
break ;
2002-09-12 21:42:33 +00:00
case 1 :
1999-12-17 21:50:07 +00:00
php_gdimagecharup ( im , font , x , y , ch , col ) ;
1999-04-16 12:15:38 +00:00
break ;
2002-09-12 21:42:33 +00:00
case 2 :
1999-04-16 12:15:38 +00:00
for ( i = 0 ; ( i < l ) ; i + + ) {
2003-03-20 01:12:57 +00:00
gdImageChar ( im , font , x , y , ( int ) ( ( unsigned char ) str [ i ] ) , col ) ;
1999-04-16 12:15:38 +00:00
x + = font - > w ;
}
break ;
2002-09-12 21:42:33 +00:00
case 3 : {
1999-04-16 12:15:38 +00:00
for ( i = 0 ; ( i < l ) ; i + + ) {
2003-03-20 01:12:57 +00:00
/* php_gdimagecharup(im, font, x, y, (int) str[i], col); */
gdImageCharUp ( im , font , x , y , ( int ) str [ i ] , col ) ;
1999-04-16 12:15:38 +00:00
y - = font - > w ;
}
break ;
}
}
2000-02-08 22:21:43 +00:00
if ( str ) {
efree ( str ) ;
1999-04-16 12:15:38 +00:00
}
RETURN_TRUE ;
2001-06-05 13:12:10 +00:00
}
/* }}} */
1999-04-16 12:15:38 +00:00
2003-06-15 15:29:46 +00:00
/* {{{ proto bool imagechar(resource im, int font, int x, int y, string c, int col)
2003-02-26 23:22:09 +00:00
Draw a character */
PHP_FUNCTION ( imagechar )
2000-11-23 14:56:09 +00:00
{
1999-12-17 21:50:07 +00:00
php_imagechar ( INTERNAL_FUNCTION_PARAM_PASSTHRU , 0 ) ;
1999-04-16 12:15:38 +00:00
}
/* }}} */
2003-06-15 15:29:46 +00:00
/* {{{ proto bool imagecharup(resource im, int font, int x, int y, string c, int col)
1999-11-24 22:04:49 +00:00
Draw a character rotated 90 degrees counter - clockwise */
2003-02-26 23:22:09 +00:00
PHP_FUNCTION ( imagecharup )
2000-11-23 14:56:09 +00:00
{
1999-12-17 21:50:07 +00:00
php_imagechar ( INTERNAL_FUNCTION_PARAM_PASSTHRU , 1 ) ;
1999-04-16 12:15:38 +00:00
}
/* }}} */
2003-06-15 15:29:46 +00:00
/* {{{ proto bool imagestring(resource im, int font, int x, int y, string str, int col)
1999-11-24 22:04:49 +00:00
Draw a string horizontally */
2003-02-26 23:22:09 +00:00
PHP_FUNCTION ( imagestring )
2000-11-23 14:56:09 +00:00
{
1999-12-17 21:50:07 +00:00
php_imagechar ( INTERNAL_FUNCTION_PARAM_PASSTHRU , 2 ) ;
1999-04-16 12:15:38 +00:00
}
/* }}} */
2003-06-15 15:29:46 +00:00
/* {{{ proto bool imagestringup(resource im, int font, int x, int y, string str, int col)
1999-11-24 22:04:49 +00:00
Draw a string vertically - rotated 90 degrees counter - clockwise */
2003-02-26 23:22:09 +00:00
PHP_FUNCTION ( imagestringup )
2000-11-23 14:56:09 +00:00
{
1999-12-17 21:50:07 +00:00
php_imagechar ( INTERNAL_FUNCTION_PARAM_PASSTHRU , 3 ) ;
1999-04-16 12:15:38 +00:00
}
/* }}} */
2003-06-15 15:29:46 +00:00
/* {{{ proto bool imagecopy(resource dst_im, resource src_im, int dst_x, int dst_y, int src_x, int src_y, int src_w, int src_h)
2003-02-26 23:22:09 +00:00
Copy part of an image */
1999-05-21 10:06:25 +00:00
PHP_FUNCTION ( imagecopy )
1999-04-16 12:15:38 +00:00
{
2000-02-28 16:52:03 +00:00
zval * * SIM , * * DIM , * * SX , * * SY , * * SW , * * SH , * * DX , * * DY ;
2000-11-23 14:56:09 +00:00
gdImagePtr im_dst , im_src ;
1999-04-16 12:15:38 +00:00
int srcH , srcW , srcY , srcX , dstY , dstX ;
2003-03-20 01:12:57 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 8 | | zend_get_parameters_ex ( 8 , & DIM , & SIM , & DX , & DY , & SX , & SY , & SW , & SH ) = = FAILURE ) {
2001-07-30 17:29:57 +00:00
ZEND_WRONG_PARAM_COUNT ( ) ;
1999-04-16 12:15:38 +00:00
}
2000-11-29 15:25:42 +00:00
ZEND_FETCH_RESOURCE ( im_src , gdImagePtr , SIM , - 1 , " Image " , le_gd ) ;
ZEND_FETCH_RESOURCE ( im_dst , gdImagePtr , DIM , - 1 , " Image " , le_gd ) ;
1999-04-16 12:15:38 +00:00
2000-02-28 16:52:03 +00:00
convert_to_long_ex ( SX ) ;
convert_to_long_ex ( SY ) ;
convert_to_long_ex ( SW ) ;
convert_to_long_ex ( SH ) ;
convert_to_long_ex ( DX ) ;
convert_to_long_ex ( DY ) ;
2000-11-23 14:56:09 +00:00
srcX = Z_LVAL_PP ( SX ) ;
srcY = Z_LVAL_PP ( SY ) ;
srcH = Z_LVAL_PP ( SH ) ;
srcW = Z_LVAL_PP ( SW ) ;
dstX = Z_LVAL_PP ( DX ) ;
dstY = Z_LVAL_PP ( DY ) ;
1999-04-16 12:15:38 +00:00
gdImageCopy ( im_dst , im_src , dstX , dstY , srcX , srcY , srcW , srcH ) ;
RETURN_TRUE ;
}
/* }}} */
2003-06-15 15:29:46 +00:00
/* {{{ proto bool imagecopymerge(resource src_im, resource dst_im, int dst_x, int dst_y, int src_x, int src_y, int src_w, int src_h, int pct)
2000-06-25 10:59:42 +00:00
Merge one part of an image with another */
2000-06-25 02:55:31 +00:00
PHP_FUNCTION ( imagecopymerge )
{
zval * * SIM , * * DIM , * * SX , * * SY , * * SW , * * SH , * * DX , * * DY , * * PCT ;
2000-11-23 14:56:09 +00:00
gdImagePtr im_dst , im_src ;
2000-06-25 02:55:31 +00:00
int srcH , srcW , srcY , srcX , dstY , dstX , pct ;
2003-03-20 01:12:57 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 9 | | zend_get_parameters_ex ( 9 , & DIM , & SIM , & DX , & DY , & SX , & SY , & SW , & SH , & PCT ) = = FAILURE ) {
2001-07-30 17:29:57 +00:00
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-06-25 02:55:31 +00:00
}
2000-11-29 15:25:42 +00:00
ZEND_FETCH_RESOURCE ( im_src , gdImagePtr , SIM , - 1 , " Image " , le_gd ) ;
ZEND_FETCH_RESOURCE ( im_dst , gdImagePtr , DIM , - 1 , " Image " , le_gd ) ;
2000-06-25 02:55:31 +00:00
convert_to_long_ex ( SX ) ;
convert_to_long_ex ( SY ) ;
convert_to_long_ex ( SW ) ;
convert_to_long_ex ( SH ) ;
convert_to_long_ex ( DX ) ;
convert_to_long_ex ( DY ) ;
convert_to_long_ex ( PCT ) ;
srcX = Z_LVAL_PP ( SX ) ;
srcY = Z_LVAL_PP ( SY ) ;
srcH = Z_LVAL_PP ( SH ) ;
srcW = Z_LVAL_PP ( SW ) ;
2000-06-25 03:12:38 +00:00
dstX = Z_LVAL_PP ( DX ) ;
2000-06-25 02:55:31 +00:00
dstY = Z_LVAL_PP ( DY ) ;
pct = Z_LVAL_PP ( PCT ) ;
gdImageCopyMerge ( im_dst , im_src , dstX , dstY , srcX , srcY , srcW , srcH , pct ) ;
RETURN_TRUE ;
}
2000-06-25 03:06:38 +00:00
/* }}} */
2000-06-25 02:55:31 +00:00
2003-06-15 15:29:46 +00:00
/* {{{ proto bool imagecopymergegray(resource src_im, resource dst_im, int dst_x, int dst_y, int src_x, int src_y, int src_w, int src_h, int pct)
2001-04-13 12:00:12 +00:00
Merge one part of an image with another */
PHP_FUNCTION ( imagecopymergegray )
{
zval * * SIM , * * DIM , * * SX , * * SY , * * SW , * * SH , * * DX , * * DY , * * PCT ;
gdImagePtr im_dst , im_src ;
int srcH , srcW , srcY , srcX , dstY , dstX , pct ;
2003-03-20 01:12:57 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 9 | | zend_get_parameters_ex ( 9 , & DIM , & SIM , & DX , & DY , & SX , & SY , & SW , & SH , & PCT ) = = FAILURE ) {
2001-07-30 17:29:57 +00:00
ZEND_WRONG_PARAM_COUNT ( ) ;
2001-04-13 12:00:12 +00:00
}
ZEND_FETCH_RESOURCE ( im_src , gdImagePtr , SIM , - 1 , " Image " , le_gd ) ;
ZEND_FETCH_RESOURCE ( im_dst , gdImagePtr , DIM , - 1 , " Image " , le_gd ) ;
convert_to_long_ex ( SX ) ;
convert_to_long_ex ( SY ) ;
convert_to_long_ex ( SW ) ;
convert_to_long_ex ( SH ) ;
convert_to_long_ex ( DX ) ;
convert_to_long_ex ( DY ) ;
convert_to_long_ex ( PCT ) ;
srcX = Z_LVAL_PP ( SX ) ;
srcY = Z_LVAL_PP ( SY ) ;
srcH = Z_LVAL_PP ( SH ) ;
srcW = Z_LVAL_PP ( SW ) ;
dstX = Z_LVAL_PP ( DX ) ;
dstY = Z_LVAL_PP ( DY ) ;
pct = Z_LVAL_PP ( PCT ) ;
gdImageCopyMergeGray ( im_dst , im_src , dstX , dstY , srcX , srcY , srcW , srcH , pct ) ;
RETURN_TRUE ;
}
/* }}} */
2003-06-15 15:29:46 +00:00
/* {{{ proto bool imagecopyresized(resource dst_im, resource src_im, int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h)
1999-11-24 22:04:49 +00:00
Copy and resize part of an image */
1999-05-21 10:06:25 +00:00
PHP_FUNCTION ( imagecopyresized )
1999-04-16 12:15:38 +00:00
{
2000-02-28 16:52:03 +00:00
zval * * SIM , * * DIM , * * SX , * * SY , * * SW , * * SH , * * DX , * * DY , * * DW , * * DH ;
2000-11-23 14:56:09 +00:00
gdImagePtr im_dst , im_src ;
1999-04-16 12:15:38 +00:00
int srcH , srcW , dstH , dstW , srcY , srcX , dstY , dstX ;
2003-03-20 01:12:57 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 10 | | zend_get_parameters_ex ( 10 , & DIM , & SIM , & DX , & DY , & SX , & SY , & DW , & DH , & SW , & SH ) = = FAILURE ) {
2001-07-30 17:29:57 +00:00
ZEND_WRONG_PARAM_COUNT ( ) ;
1999-04-16 12:15:38 +00:00
}
2000-11-29 15:25:42 +00:00
ZEND_FETCH_RESOURCE ( im_dst , gdImagePtr , DIM , - 1 , " Image " , le_gd ) ;
ZEND_FETCH_RESOURCE ( im_src , gdImagePtr , SIM , - 1 , " Image " , le_gd ) ;
1999-04-16 12:15:38 +00:00
2000-02-28 16:52:03 +00:00
convert_to_long_ex ( SX ) ;
convert_to_long_ex ( SY ) ;
convert_to_long_ex ( SW ) ;
convert_to_long_ex ( SH ) ;
convert_to_long_ex ( DX ) ;
convert_to_long_ex ( DY ) ;
convert_to_long_ex ( DW ) ;
convert_to_long_ex ( DH ) ;
2000-11-23 14:56:09 +00:00
srcX = Z_LVAL_PP ( SX ) ;
srcY = Z_LVAL_PP ( SY ) ;
srcH = Z_LVAL_PP ( SH ) ;
srcW = Z_LVAL_PP ( SW ) ;
dstX = Z_LVAL_PP ( DX ) ;
dstY = Z_LVAL_PP ( DY ) ;
dstH = Z_LVAL_PP ( DH ) ;
dstW = Z_LVAL_PP ( DW ) ;
2003-12-28 21:08:46 +00:00
2003-04-04 01:33:57 +00:00
if ( dstW < = 0 | | dstH < = 0 | | srcW < = 0 | | srcH < = 0 ) {
2003-04-04 00:16:47 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Invalid image dimensions " ) ;
RETURN_FALSE ;
}
2000-11-23 14:56:09 +00:00
gdImageCopyResized ( im_dst , im_src , dstX , dstY , srcX , srcY , dstW , dstH , srcW , srcH ) ;
1999-04-16 12:15:38 +00:00
RETURN_TRUE ;
}
2003-02-26 23:22:09 +00:00
/* }}} */
1999-04-16 12:15:38 +00:00
2003-06-15 15:29:46 +00:00
/* {{{ proto int imagesx(resource im)
1999-11-24 22:04:49 +00:00
Get image width */
1999-07-27 19:44:46 +00:00
PHP_FUNCTION ( imagesx )
1999-04-16 12:15:38 +00:00
{
2000-02-28 16:52:03 +00:00
zval * * IM ;
1999-04-16 12:15:38 +00:00
gdImagePtr im ;
2000-06-05 19:47:54 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 1 | | zend_get_parameters_ex ( 1 , & IM ) = = FAILURE ) {
2001-07-30 17:29:57 +00:00
ZEND_WRONG_PARAM_COUNT ( ) ;
1999-04-16 12:15:38 +00:00
}
2000-11-29 15:25:42 +00:00
ZEND_FETCH_RESOURCE ( im , gdImagePtr , IM , - 1 , " Image " , le_gd ) ;
1999-04-16 12:15:38 +00:00
RETURN_LONG ( gdImageSX ( im ) ) ;
}
/* }}} */
2003-06-15 15:29:46 +00:00
/* {{{ proto int imagesy(resource im)
2000-01-24 20:25:57 +00:00
Get image height */
1999-07-27 19:44:46 +00:00
PHP_FUNCTION ( imagesy )
1999-04-16 12:15:38 +00:00
{
2000-02-28 16:52:03 +00:00
zval * * IM ;
1999-04-16 12:15:38 +00:00
gdImagePtr im ;
2000-06-05 19:47:54 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 1 | | zend_get_parameters_ex ( 1 , & IM ) = = FAILURE ) {
2001-07-30 17:29:57 +00:00
ZEND_WRONG_PARAM_COUNT ( ) ;
1999-04-16 12:15:38 +00:00
}
2000-11-29 15:25:42 +00:00
ZEND_FETCH_RESOURCE ( im , gdImagePtr , IM , - 1 , " Image " , le_gd ) ;
1999-04-16 12:15:38 +00:00
RETURN_LONG ( gdImageSY ( im ) ) ;
}
/* }}} */
1999-07-23 15:18:37 +00:00
# ifdef ENABLE_GD_TTF
1999-04-16 12:15:38 +00:00
# define TTFTEXT_DRAW 0
# define TTFTEXT_BBOX 1
2000-05-02 14:10:51 +00:00
# endif
1999-04-16 12:15:38 +00:00
2002-06-24 19:31:44 +00:00
# ifdef ENABLE_GD_TTF
2001-07-05 21:23:28 +00:00
2005-12-27 00:11:16 +00:00
# if HAVE_LIBFREETYPE && HAVE_GD_STRINGFTEX
2005-01-15 04:34:30 +00:00
/* {{{ proto array imageftbbox(float size, float angle, string font_file, string text [, array extrainfo])
2001-07-05 21:23:28 +00:00
Give the bounding box of a text using fonts via freetype2 */
PHP_FUNCTION ( imageftbbox )
{
php_imagettftext_common ( INTERNAL_FUNCTION_PARAM_PASSTHRU , TTFTEXT_BBOX , 1 ) ;
}
/* }}} */
2005-01-15 04:34:30 +00:00
/* {{{ proto array imagefttext(resource im, float size, float angle, int x, int y, int col, string font_file, string text [, array extrainfo])
2001-12-06 17:51:48 +00:00
Write text to the image using fonts via freetype2 */
2001-07-05 21:23:28 +00:00
PHP_FUNCTION ( imagefttext )
{
php_imagettftext_common ( INTERNAL_FUNCTION_PARAM_PASSTHRU , TTFTEXT_DRAW , 1 ) ;
}
/* }}} */
2003-02-26 23:22:09 +00:00
# endif
2001-07-05 21:23:28 +00:00
2005-01-15 04:34:30 +00:00
/* {{{ proto array imagettfbbox(float size, float angle, string font_file, string text)
1999-11-24 22:04:49 +00:00
Give the bounding box of a text using TrueType fonts */
1999-05-21 10:06:25 +00:00
PHP_FUNCTION ( imagettfbbox )
1999-04-16 12:15:38 +00:00
{
2001-07-05 21:23:28 +00:00
php_imagettftext_common ( INTERNAL_FUNCTION_PARAM_PASSTHRU , TTFTEXT_BBOX , 0 ) ;
1999-04-16 12:15:38 +00:00
}
/* }}} */
2005-01-15 04:34:30 +00:00
/* {{{ proto array imagettftext(resource im, float size, float angle, int x, int y, int col, string font_file, string text)
1999-11-24 22:04:49 +00:00
Write text to the image using a TrueType font */
1999-05-21 10:06:25 +00:00
PHP_FUNCTION ( imagettftext )
1999-04-16 12:15:38 +00:00
{
2001-07-05 21:23:28 +00:00
php_imagettftext_common ( INTERNAL_FUNCTION_PARAM_PASSTHRU , TTFTEXT_DRAW , 0 ) ;
1999-04-16 12:15:38 +00:00
}
/* }}} */
2001-06-05 13:12:10 +00:00
/* {{{ php_imagettftext_common
*/
2001-09-06 23:10:37 +00:00
static void php_imagettftext_common ( INTERNAL_FUNCTION_PARAMETERS , int mode , int extended )
1999-04-16 12:15:38 +00:00
{
2005-01-17 17:07:28 +00:00
zval * IM , * EXT = NULL ;
2000-05-24 08:58:40 +00:00
gdImagePtr im = NULL ;
2005-04-10 21:37:17 +00:00
long col = - 1 , x = - 1 , y = - 1 ;
int str_len , fontname_len , i , brect [ 8 ] ;
1999-04-16 12:15:38 +00:00
double ptsize , angle ;
2000-02-08 22:21:43 +00:00
unsigned char * str = NULL , * fontname = NULL ;
2003-01-24 19:23:53 +00:00
char * error = NULL ;
2005-01-17 17:07:28 +00:00
int argc = ZEND_NUM_ARGS ( ) ;
2001-07-05 21:23:28 +00:00
# if HAVE_GD_STRINGFTEX
2003-12-25 22:12:12 +00:00
gdFTStringExtra strex = { 0 } ;
2001-07-05 21:23:28 +00:00
# endif
# if !HAVE_GD_STRINGFTEX
2002-08-27 20:10:46 +00:00
assert ( ! extended ) ;
2001-07-05 21:23:28 +00:00
# endif
2003-02-26 23:22:09 +00:00
1999-04-16 12:15:38 +00:00
if ( mode = = TTFTEXT_BBOX ) {
2005-01-17 17:07:28 +00:00
if ( argc < 4 | | argc > ( ( extended ) ? 5 : 4 ) ) {
2001-07-30 17:29:57 +00:00
ZEND_WRONG_PARAM_COUNT ( ) ;
2005-01-17 17:07:28 +00:00
} else if ( zend_parse_parameters ( argc TSRMLS_CC , " ddss|a " , & ptsize , & angle , & fontname , & fontname_len , & str , & str_len , & EXT ) = = FAILURE ) {
RETURN_FALSE ;
1999-04-16 12:15:38 +00:00
}
} else {
2005-01-17 17:07:28 +00:00
if ( argc < 8 | | argc > ( ( extended ) ? 9 : 8 ) ) {
2001-07-30 17:29:57 +00:00
ZEND_WRONG_PARAM_COUNT ( ) ;
2005-01-17 17:07:28 +00:00
} else if ( zend_parse_parameters ( argc TSRMLS_CC , " rddlllss|a " , & IM , & ptsize , & angle , & x , & y , & col , & fontname , & fontname_len , & str , & str_len , & EXT ) = = FAILURE ) {
RETURN_FALSE ;
1999-04-16 12:15:38 +00:00
}
2005-01-17 17:07:28 +00:00
ZEND_FETCH_RESOURCE ( im , gdImagePtr , & IM , - 1 , " Image " , le_gd ) ;
1999-04-16 12:15:38 +00:00
}
2005-01-17 17:07:28 +00:00
/* convert angle to radians */
angle = angle * ( M_PI / 180 ) ;
2001-07-05 21:23:28 +00:00
# if HAVE_GD_STRINGFTEX
2005-01-17 17:07:28 +00:00
if ( extended & & EXT ) { /* parse extended info */
2005-01-15 04:34:30 +00:00
HashPosition pos ;
2003-02-26 23:22:09 +00:00
2005-01-15 04:34:30 +00:00
/* walk the assoc array */
2005-01-17 17:07:28 +00:00
zend_hash_internal_pointer_reset_ex ( HASH_OF ( EXT ) , & pos ) ;
2005-01-15 04:34:30 +00:00
do {
zval * * item ;
char * key ;
ulong num_key ;
2001-07-05 21:23:28 +00:00
2005-01-17 17:07:28 +00:00
if ( zend_hash_get_current_key_ex ( HASH_OF ( EXT ) , & key , NULL , & num_key , 0 , & pos ) ! = HASH_KEY_IS_STRING ) {
2005-01-15 04:34:30 +00:00
continue ;
}
2001-07-05 21:23:28 +00:00
2005-01-17 17:07:28 +00:00
if ( zend_hash_get_current_data_ex ( HASH_OF ( EXT ) , ( void * * ) & item , & pos ) = = FAILURE ) {
2005-01-15 04:34:30 +00:00
continue ;
}
2005-01-17 17:07:28 +00:00
if ( strcmp ( " linespacing " , key ) = = 0 ) {
2005-01-15 04:34:30 +00:00
convert_to_double_ex ( item ) ;
strex . flags | = gdFTEX_LINESPACE ;
strex . linespacing = Z_DVAL_PP ( item ) ;
}
2003-02-26 23:22:09 +00:00
2005-01-17 17:07:28 +00:00
} while ( zend_hash_move_forward_ex ( HASH_OF ( EXT ) , & pos ) = = SUCCESS ) ;
2005-01-15 04:34:30 +00:00
}
2001-07-05 21:23:28 +00:00
# endif
2003-02-26 23:22:09 +00:00
2001-07-20 11:25:13 +00:00
# ifdef VIRTUAL_DIR
2003-12-25 22:12:12 +00:00
{
char tmp_font_path [ MAXPATHLEN ] ;
2005-01-17 17:07:28 +00:00
if ( VCWD_REALPATH ( fontname , tmp_font_path ) ) {
fontname = ( unsigned char * ) fontname ;
} else {
fontname = NULL ;
2003-12-25 22:12:12 +00:00
}
2001-07-20 11:25:13 +00:00
}
# else
2005-01-17 17:07:28 +00:00
fontname = ( unsigned char * ) fontname ;
2001-07-20 11:25:13 +00:00
# endif
2006-01-17 23:49:14 +00:00
PHP_GD_CHECK_OPEN_BASEDIR ( fontname , " Invalid font filename " ) ;
2001-09-06 23:10:37 +00:00
# ifdef USE_GD_IMGSTRTTF
# if HAVE_GD_STRINGFTEX
2003-03-20 01:12:57 +00:00
if ( extended ) {
2001-07-05 21:23:28 +00:00
error = gdImageStringFTEx ( im , brect , col , fontname , ptsize , angle , x , y , str , & strex ) ;
}
else
2001-09-06 23:10:37 +00:00
# endif
2001-10-24 10:42:31 +00:00
2001-09-06 23:10:37 +00:00
# if HAVE_GD_STRINGFT
2001-04-13 12:00:12 +00:00
error = gdImageStringFT ( im , brect , col , fontname , ptsize , angle , x , y , str ) ;
2001-10-24 10:42:31 +00:00
# elif HAVE_GD_STRINGTTF
2000-10-16 13:50:30 +00:00
error = gdImageStringTTF ( im , brect , col , fontname , ptsize , angle , x , y , str ) ;
2001-04-13 12:00:12 +00:00
# endif
2000-10-16 13:50:30 +00:00
# endif
1999-04-16 12:15:38 +00:00
if ( error ) {
2002-08-22 18:38:44 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " %s " , error ) ;
1999-04-16 12:15:38 +00:00
RETURN_FALSE ;
}
2003-02-26 23:22:09 +00:00
2003-01-17 21:37:56 +00:00
array_init ( return_value ) ;
1999-04-16 12:15:38 +00:00
/* return array with the text's bounding box */
for ( i = 0 ; i < 8 ; i + + ) {
add_next_index_long ( return_value , brect [ i ] ) ;
}
}
2001-06-05 13:12:10 +00:00
/* }}} */
2000-02-25 06:43:51 +00:00
# endif /* ENABLE_GD_TTF */
# if HAVE_LIBT1
2001-06-05 13:12:10 +00:00
/* {{{ php_free_ps_font
*/
2002-06-28 12:35:30 +00:00
static void php_free_ps_font ( zend_rsrc_list_entry * rsrc TSRMLS_DC )
2000-02-25 06:43:51 +00:00
{
2003-03-20 01:12:57 +00:00
int * font = ( int * ) rsrc - > ptr ;
2001-07-31 05:44:11 +00:00
2000-02-25 06:43:51 +00:00
T1_DeleteFont ( * font ) ;
efree ( font ) ;
}
2001-06-05 13:12:10 +00:00
/* }}} */
2000-02-25 06:43:51 +00:00
2001-06-05 13:12:10 +00:00
/* {{{ php_free_ps_enc
*/
2002-06-28 12:35:30 +00:00
static void php_free_ps_enc ( zend_rsrc_list_entry * rsrc TSRMLS_DC )
2000-02-25 06:43:51 +00:00
{
2003-03-20 01:12:57 +00:00
char * * enc = ( char * * ) rsrc - > ptr ;
2001-07-31 05:44:11 +00:00
2000-02-25 06:43:51 +00:00
T1_DeleteEncoding ( enc ) ;
}
2001-06-05 13:12:10 +00:00
/* }}} */
2000-02-25 06:43:51 +00:00
2003-06-15 15:29:46 +00:00
/* {{{ proto resource imagepsloadfont(string pathname)
2000-02-25 06:43:51 +00:00
Load a new font from specified file */
PHP_FUNCTION ( imagepsloadfont )
{
zval * * file ;
2000-11-23 14:56:09 +00:00
int f_ind , * font ;
2000-02-25 06:43:51 +00:00
2001-07-30 17:29:57 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 1 | | zend_get_parameters_ex ( 1 , & file ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-02-25 06:43:51 +00:00
}
convert_to_string_ex ( file ) ;
2000-11-23 14:56:09 +00:00
f_ind = T1_AddFont ( Z_STRVAL_PP ( file ) ) ;
2000-02-25 06:43:51 +00:00
if ( f_ind < 0 ) {
2003-04-04 00:09:23 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " T1Lib Error: %s " , T1_StrError ( f_ind ) ) ;
2000-02-25 06:43:51 +00:00
}
2000-06-16 10:09:12 +00:00
if ( T1_LoadFont ( f_ind ) ) {
2002-08-22 18:38:44 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Couldn't load the font " ) ;
2000-06-16 10:09:12 +00:00
RETURN_FALSE ;
}
2000-02-25 06:43:51 +00:00
font = ( int * ) emalloc ( sizeof ( int ) ) ;
* font = f_ind ;
2000-11-29 15:25:42 +00:00
ZEND_REGISTER_RESOURCE ( return_value , font , le_ps_font ) ;
2000-02-25 06:43:51 +00:00
}
/* }}} */
2001-12-06 18:37:05 +00:00
/* {{{ proto int imagepscopyfont(int font_index)
Make a copy of a font for purposes like extending or reenconding */
/* The function in t1lib which this function uses seem to be buggy...
2000-02-25 06:43:51 +00:00
PHP_FUNCTION ( imagepscopyfont )
{
2000-11-23 14:56:09 +00:00
zval * * fnt ;
2000-02-25 06:43:51 +00:00
int l_ind , type ;
gd_ps_font * nf_ind , * of_ind ;
2000-11-23 14:56:09 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 1 | | zend_get_parameters_ex ( 1 , & fnt ) = = FAILURE ) {
2001-07-30 17:29:57 +00:00
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-02-25 06:43:51 +00:00
}
2000-11-23 14:56:09 +00:00
convert_to_long_ex ( fnt ) ;
2000-02-25 06:43:51 +00:00
2000-11-23 14:56:09 +00:00
of_ind = zend_list_find ( Z_LVAL_PP ( fnt ) , & type ) ;
2000-02-25 06:43:51 +00:00
2000-11-29 15:25:42 +00:00
if ( type ! = le_ps_font ) {
2003-08-28 21:00:24 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " %ld is not a Type 1 font index " , Z_LVAL_PP ( fnt ) ) ;
2000-02-25 06:43:51 +00:00
RETURN_FALSE ;
}
nf_ind = emalloc ( sizeof ( gd_ps_font ) ) ;
nf_ind - > font_id = T1_CopyFont ( of_ind - > font_id ) ;
if ( nf_ind - > font_id < 0 ) {
l_ind = nf_ind - > font_id ;
efree ( nf_ind ) ;
switch ( l_ind ) {
2003-03-20 01:12:57 +00:00
case - 1 :
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " FontID %d is not loaded in memory " , l_ind ) ;
RETURN_FALSE ;
break ;
case - 2 :
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Tried to copy a logical font " ) ;
RETURN_FALSE ;
break ;
case - 3 :
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Memory allocation fault in t1lib " ) ;
RETURN_FALSE ;
break ;
default :
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " An unknown error occurred in t1lib " ) ;
RETURN_FALSE ;
break ;
2000-02-25 06:43:51 +00:00
}
}
nf_ind - > extend = 1 ;
2000-11-29 15:25:42 +00:00
l_ind = zend_list_insert ( nf_ind , le_ps_font ) ;
2000-02-25 06:43:51 +00:00
RETURN_LONG ( l_ind ) ;
}
*/
/* }}} */
2003-06-15 15:29:46 +00:00
/* {{{ proto bool imagepsfreefont(resource font_index)
2000-02-25 06:43:51 +00:00
Free memory used by a font */
PHP_FUNCTION ( imagepsfreefont )
{
zval * * fnt ;
int * f_ind ;
2000-06-05 19:47:54 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 1 | | zend_get_parameters_ex ( 1 , & fnt ) = = FAILURE ) {
2001-07-30 17:29:57 +00:00
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-02-25 06:43:51 +00:00
}
2000-11-29 15:25:42 +00:00
ZEND_FETCH_RESOURCE ( f_ind , int * , fnt , - 1 , " Type 1 font " , le_ps_font ) ;
2000-02-25 06:43:51 +00:00
2000-11-23 14:56:09 +00:00
zend_list_delete ( Z_LVAL_PP ( fnt ) ) ;
2000-02-25 06:43:51 +00:00
RETURN_TRUE ;
}
/* }}} */
2003-06-15 15:29:46 +00:00
/* {{{ proto bool imagepsencodefont(resource font_index, string filename)
2000-02-25 06:43:51 +00:00
To change a fonts character encoding vector */
PHP_FUNCTION ( imagepsencodefont )
{
zval * * fnt , * * enc ;
char * * enc_vector ;
int * f_ind ;
2000-06-05 19:47:54 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 2 | | zend_get_parameters_ex ( 2 , & fnt , & enc ) = = FAILURE ) {
2001-07-30 17:29:57 +00:00
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-02-25 06:43:51 +00:00
}
convert_to_string_ex ( enc ) ;
2000-11-29 15:25:42 +00:00
ZEND_FETCH_RESOURCE ( f_ind , int * , fnt , - 1 , " Type 1 font " , le_ps_font ) ;
2000-02-25 06:43:51 +00:00
2000-11-23 14:56:09 +00:00
if ( ( enc_vector = T1_LoadEncoding ( Z_STRVAL_PP ( enc ) ) ) = = NULL ) {
2002-08-22 18:38:44 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Couldn't load encoding vector from %s " , Z_STRVAL_PP ( enc ) ) ;
2000-02-25 06:43:51 +00:00
RETURN_FALSE ;
}
T1_DeleteAllSizes ( * f_ind ) ;
if ( T1_ReencodeFont ( * f_ind , enc_vector ) ) {
T1_DeleteEncoding ( enc_vector ) ;
2002-08-22 18:38:44 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Couldn't reencode font " ) ;
2000-02-25 06:43:51 +00:00
RETURN_FALSE ;
}
2003-03-20 01:12:57 +00:00
2000-11-29 15:25:42 +00:00
zend_list_insert ( enc_vector , le_ps_enc ) ;
2003-03-20 01:12:57 +00:00
2000-02-25 06:43:51 +00:00
RETURN_TRUE ;
}
/* }}} */
2003-06-15 15:29:46 +00:00
/* {{{ proto bool imagepsextendfont(resource font_index, float extend)
2000-02-25 06:43:51 +00:00
Extend or or condense ( if extend < 1 ) a font */
PHP_FUNCTION ( imagepsextendfont )
{
zval * * fnt , * * ext ;
int * f_ind ;
2000-06-05 19:47:54 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 2 | | zend_get_parameters_ex ( 2 , & fnt , & ext ) = = FAILURE ) {
2001-07-30 17:29:57 +00:00
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-02-25 06:43:51 +00:00
}
convert_to_double_ex ( ext ) ;
2000-11-29 15:25:42 +00:00
ZEND_FETCH_RESOURCE ( f_ind , int * , fnt , - 1 , " Type 1 font " , le_ps_font ) ;
2000-02-25 06:43:51 +00:00
2002-06-28 09:53:25 +00:00
T1_DeleteAllSizes ( * f_ind ) ;
2003-04-04 00:09:23 +00:00
if ( Z_DVAL_PP ( ext ) < = 0 ) {
2005-12-29 22:00:09 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Second parameter %f out of range (must be > 0) " , Z_DVAL_PP ( ext ) ) ;
2003-04-04 00:09:23 +00:00
RETURN_FALSE ;
}
2003-03-20 01:12:57 +00:00
if ( T1_ExtendFont ( * f_ind , Z_DVAL_PP ( ext ) ) ! = 0 ) {
RETURN_FALSE ;
}
2000-02-25 06:43:51 +00:00
RETURN_TRUE ;
}
/* }}} */
2003-06-15 15:29:46 +00:00
/* {{{ proto bool imagepsslantfont(resource font_index, float slant)
2000-02-25 06:43:51 +00:00
Slant a font */
PHP_FUNCTION ( imagepsslantfont )
{
zval * * fnt , * * slt ;
int * f_ind ;
2000-06-05 19:47:54 +00:00
if ( ZEND_NUM_ARGS ( ) ! = 2 | | zend_get_parameters_ex ( 2 , & fnt , & slt ) = = FAILURE ) {
2001-07-30 17:29:57 +00:00
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-02-25 06:43:51 +00:00
}
convert_to_double_ex ( slt ) ;
2000-11-29 15:25:42 +00:00
ZEND_FETCH_RESOURCE ( f_ind , int * , fnt , - 1 , " Type 1 font " , le_ps_font ) ;
2000-02-25 06:43:51 +00:00
2003-03-20 01:12:57 +00:00
if ( T1_SlantFont ( * f_ind , Z_DVAL_PP ( slt ) ) ! = 0 ) {
RETURN_FALSE ;
}
2000-02-25 06:43:51 +00:00
RETURN_TRUE ;
}
/* }}} */
2003-06-15 15:29:46 +00:00
/* {{{ proto array imagepstext(resource image, string text, resource font, int size, int xcoord, int ycoord [, int space, int tightness, float angle, int antialias])
2000-02-25 06:43:51 +00:00
Rasterize a string over an image */
PHP_FUNCTION ( imagepstext )
{
2003-01-22 19:53:29 +00:00
zval * img , * fnt ;
int i , j ;
2004-01-28 01:36:53 +00:00
long _fg , _bg , x , y , size , space = 0 , aa_steps = 4 , width = 0 ;
2000-02-25 06:43:51 +00:00
int * f_ind ;
int h_lines , v_lines , c_ind ;
2003-01-22 19:53:29 +00:00
int rd , gr , bl , fg_rd , fg_gr , fg_bl , bg_rd , bg_gr , bg_bl ;
2002-09-05 00:22:40 +00:00
int fg_al , bg_al , al ;
2003-01-22 19:53:29 +00:00
int aa [ 16 ] ;
int amount_kern , add_width ;
double angle = 0.0 , extend ;
2000-02-25 06:43:51 +00:00
unsigned long aa_greys [ ] = { 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 } ;
gdImagePtr bg_img ;
GLYPH * str_img ;
T1_OUTLINE * char_path , * str_path ;
T1_TMATRIX * transform = NULL ;
2003-01-24 16:23:11 +00:00
char * str ;
int str_len ;
2003-01-22 19:53:29 +00:00
int argc = ZEND_NUM_ARGS ( ) ;
2003-02-26 23:22:09 +00:00
2003-01-22 19:53:29 +00:00
if ( argc ! = 8 & & argc ! = 12 ) {
2001-07-30 17:29:57 +00:00
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-02-25 06:43:51 +00:00
}
2003-02-26 23:22:09 +00:00
2003-01-24 16:23:11 +00:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " rsrlllll|lldl " , & img , & str , & str_len , & fnt , & size , & _fg , & _bg , & x , & y , & space , & width , & angle , & aa_steps ) = = FAILURE ) {
2003-01-22 19:53:29 +00:00
return ;
}
2000-02-25 06:43:51 +00:00
2003-01-22 19:53:29 +00:00
ZEND_FETCH_RESOURCE ( bg_img , gdImagePtr , & img , - 1 , " Image " , le_gd ) ;
ZEND_FETCH_RESOURCE ( f_ind , int * , & fnt , - 1 , " Type 1 font " , le_ps_font ) ;
2002-09-20 00:47:00 +00:00
2003-01-22 19:53:29 +00:00
/* Ensure that the provided colors are valid */
if ( _fg < 0 | | ( ! gdImageTrueColor ( bg_img ) & & _fg > gdImageColorsTotal ( bg_img ) ) ) {
2004-12-29 21:40:34 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Foreground color index %ld out of range " , _fg ) ;
2003-01-22 19:53:29 +00:00
RETURN_FALSE ;
}
2000-02-25 06:43:51 +00:00
2003-01-22 19:53:29 +00:00
if ( _bg < 0 | | ( ! gdImageTrueColor ( bg_img ) & & _fg > gdImageColorsTotal ( bg_img ) ) ) {
2004-12-29 21:40:34 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Background color index %ld out of range " , _bg ) ;
2003-01-22 19:53:29 +00:00
RETURN_FALSE ;
}
2003-02-26 23:22:09 +00:00
2000-11-23 14:56:09 +00:00
fg_rd = gdImageRed ( bg_img , _fg ) ;
fg_gr = gdImageGreen ( bg_img , _fg ) ;
fg_bl = gdImageBlue ( bg_img , _fg ) ;
2002-08-22 07:28:26 +00:00
fg_al = gdImageAlpha ( bg_img , _fg ) ;
2000-11-23 14:56:09 +00:00
bg_rd = gdImageRed ( bg_img , _bg ) ;
bg_gr = gdImageGreen ( bg_img , _bg ) ;
bg_bl = gdImageBlue ( bg_img , _bg ) ;
2002-08-22 07:28:26 +00:00
bg_al = gdImageAlpha ( bg_img , _bg ) ;
2000-02-25 06:43:51 +00:00
for ( i = 0 ; i < aa_steps ; i + + ) {
2003-03-20 01:12:57 +00:00
rd = bg_rd + ( double ) ( fg_rd - bg_rd ) / aa_steps * ( i + 1 ) ;
gr = bg_gr + ( double ) ( fg_gr - bg_gr ) / aa_steps * ( i + 1 ) ;
bl = bg_bl + ( double ) ( fg_bl - bg_bl ) / aa_steps * ( i + 1 ) ;
al = bg_al + ( double ) ( fg_al - bg_al ) / aa_steps * ( i + 1 ) ;
2002-08-22 07:28:26 +00:00
aa [ i ] = gdImageColorResolveAlpha ( bg_img , rd , gr , bl , al ) ;
2000-02-25 06:43:51 +00:00
}
T1_AASetBitsPerPixel ( 8 ) ;
switch ( aa_steps ) {
2003-01-22 19:53:29 +00:00
case 4 :
T1_AASetGrayValues ( 0 , 1 , 2 , 3 , 4 ) ;
T1_AASetLevel ( T1_AA_LOW ) ;
break ;
case 16 :
T1_AAHSetGrayValues ( aa_greys ) ;
T1_AASetLevel ( T1_AA_HIGH ) ;
break ;
default :
2004-12-29 21:40:34 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Invalid value %ld as number of steps for antialiasing " , aa_steps ) ;
2003-01-22 19:53:29 +00:00
RETURN_FALSE ;
2000-02-25 06:43:51 +00:00
}
if ( angle ) {
transform = T1_RotateMatrix ( NULL , angle ) ;
}
2003-05-15 02:25:50 +00:00
if ( width ) {
extend = T1_GetExtend ( * f_ind ) ;
str_path = T1_GetCharOutline ( * f_ind , str [ 0 ] , size , transform ) ;
2000-02-25 06:43:51 +00:00
2003-05-15 02:25:50 +00:00
if ( ! str_path ) {
if ( T1_errno ) {
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " T1Lib Error: %s " , T1_StrError ( T1_errno ) ) ;
}
RETURN_FALSE ;
2003-02-26 23:22:09 +00:00
}
2002-12-12 21:17:36 +00:00
2003-05-15 02:25:50 +00:00
for ( i = 1 ; i < str_len ; i + + ) {
amount_kern = ( int ) T1_GetKerning ( * f_ind , str [ i - 1 ] , str [ i ] ) ;
amount_kern + = str [ i - 1 ] = = ' ' ? space : 0 ;
add_width = ( int ) ( amount_kern + width ) / extend ;
2000-02-25 06:43:51 +00:00
2003-05-15 02:25:50 +00:00
char_path = T1_GetMoveOutline ( * f_ind , add_width , 0 , 0 , size , transform ) ;
str_path = T1_ConcatOutlines ( str_path , char_path ) ;
2000-02-25 06:43:51 +00:00
2003-05-15 02:25:50 +00:00
char_path = T1_GetCharOutline ( * f_ind , str [ i ] , size , transform ) ;
str_path = T1_ConcatOutlines ( str_path , char_path ) ;
}
str_img = T1_AAFillOutline ( str_path , 0 ) ;
} else {
str_img = T1_AASetString ( * f_ind , str , str_len , space , T1_KERNING , size , transform ) ;
2000-02-25 06:43:51 +00:00
}
2000-06-16 10:09:12 +00:00
if ( T1_errno ) {
2003-04-04 00:09:23 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " T1Lib Error: %s " , T1_StrError ( T1_errno ) ) ;
2000-06-16 10:09:12 +00:00
RETURN_FALSE ;
}
2000-02-25 06:43:51 +00:00
h_lines = str_img - > metrics . ascent - str_img - > metrics . descent ;
v_lines = str_img - > metrics . rightSideBearing - str_img - > metrics . leftSideBearing ;
for ( i = 0 ; i < v_lines ; i + + ) {
for ( j = 0 ; j < h_lines ; j + + ) {
2003-03-20 01:12:57 +00:00
switch ( str_img - > bits [ j * v_lines + i ] ) {
2003-01-22 19:53:29 +00:00
case 0 :
break ;
default :
2003-03-20 01:12:57 +00:00
c_ind = aa [ str_img - > bits [ j * v_lines + i ] - 1 ] ;
gdImageSetPixel ( bg_img , x + str_img - > metrics . leftSideBearing + i , y - str_img - > metrics . ascent + j , c_ind ) ;
2003-01-22 19:53:29 +00:00
break ;
2000-02-25 06:43:51 +00:00
}
}
}
2003-01-17 21:37:56 +00:00
array_init ( return_value ) ;
2000-02-25 06:43:51 +00:00
add_next_index_long ( return_value , str_img - > metrics . leftSideBearing ) ;
add_next_index_long ( return_value , str_img - > metrics . descent ) ;
add_next_index_long ( return_value , str_img - > metrics . rightSideBearing ) ;
add_next_index_long ( return_value , str_img - > metrics . ascent ) ;
}
/* }}} */
2003-06-15 15:29:46 +00:00
/* {{{ proto array imagepsbbox(string text, resource font, int size [, int space, int tightness, int angle])
2000-02-25 06:43:51 +00:00
Return the bounding box needed by a string if rasterized */
PHP_FUNCTION ( imagepsbbox )
{
zval * * str , * * fnt , * * sz , * * sp , * * wd , * * ang ;
2001-07-30 20:27:11 +00:00
int i , space , add_width = 0 , char_width , amount_kern ;
2000-02-25 06:43:51 +00:00
int cur_x , cur_y , dx , dy ;
int x1 , y1 , x2 , y2 , x3 , y3 , x4 , y4 ;
int * f_ind ;
int per_char = 0 ;
2000-02-28 16:52:03 +00:00
double angle , sin_a = 0 , cos_a = 0 ;
2000-02-25 06:43:51 +00:00
BBox char_bbox , str_bbox = { 0 , 0 , 0 , 0 } ;
2003-03-20 01:12:57 +00:00
switch ( ZEND_NUM_ARGS ( ) ) {
case 3 :
if ( zend_get_parameters_ex ( 3 , & str , & fnt , & sz ) = = FAILURE ) {
RETURN_FALSE ;
}
space = 0 ;
break ;
case 6 :
if ( zend_get_parameters_ex ( 6 , & str , & fnt , & sz , & sp , & wd , & ang ) = = FAILURE ) {
RETURN_FALSE ;
}
convert_to_long_ex ( sp ) ;
convert_to_long_ex ( wd ) ;
convert_to_double_ex ( ang ) ;
space = Z_LVAL_PP ( sp ) ;
add_width = Z_LVAL_PP ( wd ) ;
angle = Z_DVAL_PP ( ang ) * M_PI / 180 ;
sin_a = sin ( angle ) ;
cos_a = cos ( angle ) ;
per_char = add_width | | angle ? 1 : 0 ;
break ;
default :
ZEND_WRONG_PARAM_COUNT ( ) ;
2000-02-25 06:43:51 +00:00
}
2000-11-29 15:25:42 +00:00
ZEND_FETCH_RESOURCE ( f_ind , int * , fnt , - 1 , " Type 1 font " , le_ps_font ) ;
2000-02-25 06:43:51 +00:00
2000-11-23 14:56:09 +00:00
convert_to_string_ex ( str ) ;
convert_to_long_ex ( sz ) ;
2000-02-25 06:43:51 +00:00
# define max(a, b) (a > b ? a : b)
# define min(a, b) (a < b ? a : b)
# define new_x(a, b) (int) ((a) * cos_a - (b) * sin_a)
# define new_y(a, b) (int) ((a) * sin_a + (b) * cos_a)
if ( per_char ) {
space + = T1_GetCharWidth ( * f_ind , ' ' ) ;
cur_x = cur_y = 0 ;
2001-09-25 21:58:48 +00:00
for ( i = 0 ; i < Z_STRLEN_PP ( str ) ; i + + ) {
if ( Z_STRVAL_PP ( str ) [ i ] = = ' ' ) {
2000-02-25 06:43:51 +00:00
char_bbox . llx = char_bbox . lly = char_bbox . ury = 0 ;
char_bbox . urx = char_width = space ;
} else {
2001-09-25 21:58:48 +00:00
char_bbox = T1_GetCharBBox ( * f_ind , Z_STRVAL_PP ( str ) [ i ] ) ;
char_width = T1_GetCharWidth ( * f_ind , Z_STRVAL_PP ( str ) [ i ] ) ;
2000-02-25 06:43:51 +00:00
}
2003-03-20 01:12:57 +00:00
amount_kern = i ? T1_GetKerning ( * f_ind , Z_STRVAL_PP ( str ) [ i - 1 ] , Z_STRVAL_PP ( str ) [ i ] ) : 0 ;
2000-02-25 06:43:51 +00:00
/* Transfer character bounding box to right place */
x1 = new_x ( char_bbox . llx , char_bbox . lly ) + cur_x ;
y1 = new_y ( char_bbox . llx , char_bbox . lly ) + cur_y ;
x2 = new_x ( char_bbox . llx , char_bbox . ury ) + cur_x ;
y2 = new_y ( char_bbox . llx , char_bbox . ury ) + cur_y ;
x3 = new_x ( char_bbox . urx , char_bbox . ury ) + cur_x ;
y3 = new_y ( char_bbox . urx , char_bbox . ury ) + cur_y ;
x4 = new_x ( char_bbox . urx , char_bbox . lly ) + cur_x ;
y4 = new_y ( char_bbox . urx , char_bbox . lly ) + cur_y ;
/* Find min & max values and compare them with current bounding box */
str_bbox . llx = min ( str_bbox . llx , min ( x1 , min ( x2 , min ( x3 , x4 ) ) ) ) ;
str_bbox . lly = min ( str_bbox . lly , min ( y1 , min ( y2 , min ( y3 , y4 ) ) ) ) ;
str_bbox . urx = max ( str_bbox . urx , max ( x1 , max ( x2 , max ( x3 , x4 ) ) ) ) ;
str_bbox . ury = max ( str_bbox . ury , max ( y1 , max ( y2 , max ( y3 , y4 ) ) ) ) ;
/* Move to the next base point */
dx = new_x ( char_width + add_width + amount_kern , 0 ) ;
dy = new_y ( char_width + add_width + amount_kern , 0 ) ;
cur_x + = dx ;
cur_y + = dy ;
/*
printf ( " %d \t %d \t %d \t %d \t %d \t %d \t %d \t %d \t %d \t %d \t %d \t %d \t %d \t %d \t %d \t %d \t %d \t %d \n " , x1 , y1 , x2 , y2 , x3 , y3 , x4 , y4 , char_bbox . llx , char_bbox . lly , char_bbox . urx , char_bbox . ury , char_width , amount_kern , cur_x , cur_y , dx , dy ) ;
*/
}
} else {
2001-09-25 21:58:48 +00:00
str_bbox = T1_GetStringBBox ( * f_ind , Z_STRVAL_PP ( str ) , Z_STRLEN_PP ( str ) , space , T1_KERNING ) ;
2000-02-25 06:43:51 +00:00
}
2003-03-20 01:12:57 +00:00
if ( T1_errno ) {
RETURN_FALSE ;
}
2003-02-26 23:22:09 +00:00
2003-01-17 21:37:56 +00:00
array_init ( return_value ) ;
2000-02-25 06:43:51 +00:00
/*
printf ( " %d %d %d %d \n " , str_bbox . llx , str_bbox . lly , str_bbox . urx , str_bbox . ury ) ;
*/
2001-09-25 21:58:48 +00:00
add_next_index_long ( return_value , ( int ) ceil ( ( ( double ) str_bbox . llx ) * Z_LVAL_PP ( sz ) / 1000 ) ) ;
add_next_index_long ( return_value , ( int ) ceil ( ( ( double ) str_bbox . lly ) * Z_LVAL_PP ( sz ) / 1000 ) ) ;
add_next_index_long ( return_value , ( int ) ceil ( ( ( double ) str_bbox . urx ) * Z_LVAL_PP ( sz ) / 1000 ) ) ;
add_next_index_long ( return_value , ( int ) ceil ( ( ( double ) str_bbox . ury ) * Z_LVAL_PP ( sz ) / 1000 ) ) ;
2000-02-25 06:43:51 +00:00
}
/* }}} */
2003-02-26 23:22:09 +00:00
# endif
2000-02-25 06:43:51 +00:00
2003-06-15 15:29:46 +00:00
/* {{{ proto bool image2wbmp(resource im [, string filename [, int threshold]])
2001-01-24 09:24:26 +00:00
Output WBMP image to browser or file */
PHP_FUNCTION ( image2wbmp )
{
2003-03-20 01:12:57 +00:00
_php_image_output ( INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GDIMG_CONVERT_WBM , " WBMP " , _php_image_bw_convert ) ;
2001-01-24 09:24:26 +00:00
}
2001-06-05 13:12:10 +00:00
/* }}} */
2001-01-24 09:24:26 +00:00
2005-12-14 22:33:34 +00:00
# if defined(HAVE_GD_JPG)
2003-06-15 15:29:46 +00:00
/* {{{ proto bool jpeg2wbmp (string f_org, string f_dest, int d_height, int d_width, int threshold)
2001-01-27 14:20:06 +00:00
Convert JPEG image to WBMP image */
2001-01-24 09:24:26 +00:00
PHP_FUNCTION ( jpeg2wbmp )
{
2003-03-20 01:12:57 +00:00
_php_image_convert ( INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GDIMG_TYPE_JPG ) ;
2001-01-24 09:24:26 +00:00
}
/* }}} */
2002-06-24 19:31:44 +00:00
# endif
2001-01-24 09:24:26 +00:00
2005-12-14 22:33:34 +00:00
# if defined(HAVE_GD_PNG)
2003-06-15 15:29:46 +00:00
/* {{{ proto bool png2wbmp (string f_org, string f_dest, int d_height, int d_width, int threshold)
2001-01-27 14:20:06 +00:00
Convert PNG image to WBMP image */
2001-01-24 09:24:26 +00:00
PHP_FUNCTION ( png2wbmp )
{
2003-03-20 01:12:57 +00:00
_php_image_convert ( INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GDIMG_TYPE_PNG ) ;
2001-01-24 09:24:26 +00:00
}
/* }}} */
2002-06-24 19:31:44 +00:00
# endif
2001-01-24 09:24:26 +00:00
2001-06-05 13:12:10 +00:00
/* {{{ _php_image_bw_convert
* It converts a gd Image to bw using a threshold value */
2003-03-20 01:12:57 +00:00
static void _php_image_bw_convert ( gdImagePtr im_org , gdIOCtx * out , int threshold )
2001-04-01 05:42:07 +00:00
{
2001-01-24 09:24:26 +00:00
gdImagePtr im_dest ;
int white , black ;
int color , color_org , median ;
2003-03-20 01:12:57 +00:00
int dest_height = gdImageSY ( im_org ) ;
int dest_width = gdImageSX ( im_org ) ;
2001-08-11 16:39:07 +00:00
int x , y ;
2001-07-30 20:27:11 +00:00
TSRMLS_FETCH ( ) ;
2003-02-26 23:22:09 +00:00
2003-03-20 01:12:57 +00:00
im_dest = gdImageCreate ( dest_width , dest_height ) ;
2001-01-24 09:24:26 +00:00
if ( im_dest = = NULL ) {
2002-08-22 19:14:27 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Unable to allocate temporary buffer " ) ;
2001-01-24 09:24:26 +00:00
return ;
}
2003-03-20 01:12:57 +00:00
white = gdImageColorAllocate ( im_dest , 255 , 255 , 255 ) ;
if ( white = = - 1 ) {
2002-08-22 19:14:27 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Unable to allocate the colors for the destination buffer " ) ;
2001-01-24 09:24:26 +00:00
return ;
}
2003-03-20 01:12:57 +00:00
black = gdImageColorAllocate ( im_dest , 0 , 0 , 0 ) ;
2001-01-24 09:24:26 +00:00
if ( black = = - 1 ) {
2002-08-22 19:14:27 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Unable to allocate the colors for the destination buffer " ) ;
2001-01-24 09:24:26 +00:00
return ;
}
2004-02-17 21:30:00 +00:00
if ( im_org - > trueColor ) {
gdImageTrueColorToPalette ( im_org , 1 , 256 ) ;
}
2001-01-24 09:24:26 +00:00
for ( y = 0 ; y < dest_height ; y + + ) {
for ( x = 0 ; x < dest_width ; x + + ) {
2003-03-20 01:12:57 +00:00
color_org = gdImageGetPixel ( im_org , x , y ) ;
2001-01-24 09:24:26 +00:00
median = ( im_org - > red [ color_org ] + im_org - > green [ color_org ] + im_org - > blue [ color_org ] ) / 3 ;
if ( median < threshold ) {
color = black ;
2003-03-20 01:12:57 +00:00
} else {
2001-01-24 09:24:26 +00:00
color = white ;
}
gdImageSetPixel ( im_dest , x , y , color ) ;
}
}
2001-04-01 05:42:07 +00:00
gdImageWBMPCtx ( im_dest , black , out ) ;
}
2001-06-05 13:12:10 +00:00
/* }}} */
2001-01-24 09:24:26 +00:00
2001-06-05 13:12:10 +00:00
/* {{{ _php_image_convert
* _php_image_convert converts jpeg / png images to wbmp and resizes them as needed */
2003-02-26 23:22:09 +00:00
static void _php_image_convert ( INTERNAL_FUNCTION_PARAMETERS , int image_type )
2001-06-07 13:17:02 +00:00
{
2001-01-24 09:24:26 +00:00
zval * * f_org , * * f_dest , * * height , * * width , * * threshold ;
gdImagePtr im_org , im_dest , im_tmp ;
char * fn_org = NULL ;
char * fn_dest = NULL ;
2001-08-11 16:39:07 +00:00
FILE * org , * dest ;
2003-03-20 01:12:57 +00:00
int argc = ZEND_NUM_ARGS ( ) ;
2001-01-24 09:24:26 +00:00
int dest_height = - 1 ;
int dest_width = - 1 ;
int org_height , org_width ;
int white , black ;
int color , color_org , median ;
int int_threshold ;
int x , y ;
float x_ratio , y_ratio ;
2006-02-02 20:30:54 +00:00
long ignore_warning ;
2001-01-24 09:24:26 +00:00
2002-01-02 01:25:48 +00:00
if ( argc ! = 5 | | zend_get_parameters_ex ( argc , & f_org , & f_dest , & height , & width , & threshold ) = = FAILURE ) {
2001-07-30 17:29:57 +00:00
ZEND_WRONG_PARAM_COUNT ( ) ;
2001-01-24 09:24:26 +00:00
}
2003-03-20 01:12:57 +00:00
convert_to_string_ex ( f_org ) ;
convert_to_string_ex ( f_dest ) ;
convert_to_long_ex ( height ) ;
convert_to_long_ex ( width ) ;
convert_to_long_ex ( threshold ) ;
2002-01-02 01:25:48 +00:00
fn_org = Z_STRVAL_PP ( f_org ) ;
fn_dest = Z_STRVAL_PP ( f_dest ) ;
dest_height = Z_LVAL_PP ( height ) ;
dest_width = Z_LVAL_PP ( width ) ;
int_threshold = Z_LVAL_PP ( threshold ) ;
/* Check threshold value */
2003-03-20 01:12:57 +00:00
if ( int_threshold < 0 | | int_threshold > 8 ) {
2002-08-22 19:14:27 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Invalid threshold value '%d' " , int_threshold ) ;
2002-01-02 01:25:48 +00:00
RETURN_FALSE ;
}
2001-01-24 09:24:26 +00:00
2002-01-02 01:25:48 +00:00
/* Check origin file */
2005-11-01 17:04:29 +00:00
PHP_GD_CHECK_OPEN_BASEDIR ( fn_org , " Invalid origin filename " ) ;
2001-01-24 09:24:26 +00:00
2002-01-02 01:25:48 +00:00
/* Check destination file */
2005-11-01 17:04:29 +00:00
PHP_GD_CHECK_OPEN_BASEDIR ( fn_dest , " Invalid destination filename " ) ;
2001-01-24 09:24:26 +00:00
2002-01-02 01:25:48 +00:00
/* Open origin file */
org = VCWD_FOPEN ( fn_org , " rb " ) ;
if ( ! org ) {
2002-08-22 19:14:27 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Unable to open '%s' for reading " , fn_org ) ;
2002-01-02 01:25:48 +00:00
RETURN_FALSE ;
}
2001-01-24 09:24:26 +00:00
2002-01-02 01:25:48 +00:00
/* Open destination file */
dest = VCWD_FOPEN ( fn_dest , " wb " ) ;
if ( ! dest ) {
2002-08-22 19:14:27 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Unable to open '%s' for writing " , fn_dest ) ;
2002-01-02 01:25:48 +00:00
RETURN_FALSE ;
}
2001-01-24 09:24:26 +00:00
2002-01-02 01:25:48 +00:00
switch ( image_type ) {
2001-08-24 20:05:58 +00:00
# ifdef HAVE_GD_GIF_READ
2002-01-02 01:25:48 +00:00
case PHP_GDIMG_TYPE_GIF :
2003-03-20 01:12:57 +00:00
im_org = gdImageCreateFromGif ( org ) ;
2002-01-02 01:25:48 +00:00
if ( im_org = = NULL ) {
2002-08-27 19:40:55 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Unable to open '%s' Not a valid GIF file " , fn_dest ) ;
2002-01-02 01:25:48 +00:00
RETURN_FALSE ;
}
break ;
2001-08-24 20:05:58 +00:00
# endif /* HAVE_GD_GIF_READ */
2001-02-09 21:14:30 +00:00
# ifdef HAVE_GD_JPG
2002-01-02 01:25:48 +00:00
case PHP_GDIMG_TYPE_JPG :
2006-02-02 20:30:54 +00:00
ignore_warning = INI_INT ( " gd.jpeg_ignore_warning " ) ;
2006-03-10 18:15:21 +00:00
# ifdef HAVE_GD_BUNDLED
2006-02-02 20:30:54 +00:00
im_org = gdImageCreateFromJpeg ( org , ignore_warning ) ;
2006-03-10 18:15:21 +00:00
# else
im_org = gdImageCreateFromJpeg ( org ) ;
# endif
2002-01-02 01:25:48 +00:00
if ( im_org = = NULL ) {
2002-08-22 19:14:27 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Unable to open '%s' Not a valid JPEG file " , fn_dest ) ;
2002-01-02 01:25:48 +00:00
RETURN_FALSE ;
}
break ;
2001-02-09 21:14:30 +00:00
# endif /* HAVE_GD_JPG */
# ifdef HAVE_GD_PNG
2002-01-02 01:25:48 +00:00
case PHP_GDIMG_TYPE_PNG :
im_org = gdImageCreateFromPng ( org ) ;
if ( im_org = = NULL ) {
2002-08-22 19:14:27 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Unable to open '%s' Not a valid PNG file " , fn_dest ) ;
2002-01-02 01:25:48 +00:00
RETURN_FALSE ;
}
break ;
2001-02-09 21:14:30 +00:00
# endif /* HAVE_GD_PNG */
2002-01-02 01:25:48 +00:00
default :
2002-08-22 18:38:44 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Format not supported " ) ;
2002-01-02 01:25:48 +00:00
RETURN_FALSE ;
break ;
}
2001-01-24 09:24:26 +00:00
2002-01-02 01:25:48 +00:00
org_width = gdImageSX ( im_org ) ;
org_height = gdImageSY ( im_org ) ;
2001-01-24 09:24:26 +00:00
2002-01-02 01:25:48 +00:00
x_ratio = ( float ) org_width / ( float ) dest_width ;
y_ratio = ( float ) org_height / ( float ) dest_height ;
2001-01-24 09:24:26 +00:00
2002-01-02 01:25:48 +00:00
if ( x_ratio > 1 & & y_ratio > 1 ) {
if ( y_ratio > x_ratio ) {
x_ratio = y_ratio ;
2003-03-20 01:12:57 +00:00
} else {
2002-01-02 01:25:48 +00:00
y_ratio = x_ratio ;
2001-01-24 09:24:26 +00:00
}
2003-03-20 01:12:57 +00:00
dest_width = ( int ) ( org_width / x_ratio ) ;
dest_height = ( int ) ( org_height / y_ratio ) ;
} else {
2002-01-02 01:25:48 +00:00
x_ratio = ( float ) dest_width / ( float ) org_width ;
y_ratio = ( float ) dest_height / ( float ) org_height ;
2001-01-24 09:24:26 +00:00
2002-01-02 01:25:48 +00:00
if ( y_ratio < x_ratio ) {
x_ratio = y_ratio ;
2003-03-20 01:12:57 +00:00
} else {
2002-01-02 01:25:48 +00:00
y_ratio = x_ratio ;
}
2003-03-20 01:12:57 +00:00
dest_width = ( int ) ( org_width * x_ratio ) ;
dest_height = ( int ) ( org_height * y_ratio ) ;
2002-01-02 01:25:48 +00:00
}
2001-01-24 09:24:26 +00:00
2002-01-02 01:25:48 +00:00
im_tmp = gdImageCreate ( dest_width , dest_height ) ;
if ( im_tmp = = NULL ) {
2002-08-22 18:38:44 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Unable to allocate temporary buffer " ) ;
2002-01-02 01:25:48 +00:00
RETURN_FALSE ;
}
2001-01-24 09:24:26 +00:00
2002-01-02 01:25:48 +00:00
gdImageCopyResized ( im_tmp , im_org , 0 , 0 , 0 , 0 , dest_width , dest_height , org_width , org_height ) ;
2001-01-24 09:24:26 +00:00
2002-01-02 01:25:48 +00:00
gdImageDestroy ( im_org ) ;
2001-01-24 09:24:26 +00:00
2002-01-02 01:25:48 +00:00
fclose ( org ) ;
2001-01-24 09:24:26 +00:00
2002-01-02 01:25:48 +00:00
im_dest = gdImageCreate ( dest_width , dest_height ) ;
if ( im_dest = = NULL ) {
2002-08-22 18:38:44 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Unable to allocate destination buffer " ) ;
2002-01-02 01:25:48 +00:00
RETURN_FALSE ;
}
2003-03-20 01:12:57 +00:00
2002-01-02 01:25:48 +00:00
white = gdImageColorAllocate ( im_dest , 255 , 255 , 255 ) ;
if ( white = = - 1 ) {
2002-08-22 18:38:44 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Unable to allocate the colors for the destination buffer " ) ;
2002-01-02 01:25:48 +00:00
RETURN_FALSE ;
}
2001-01-24 09:24:26 +00:00
2002-01-02 01:25:48 +00:00
black = gdImageColorAllocate ( im_dest , 0 , 0 , 0 ) ;
if ( black = = - 1 ) {
2002-08-22 18:38:44 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Unable to allocate the colors for the destination buffer " ) ;
2002-01-02 01:25:48 +00:00
RETURN_FALSE ;
}
2001-01-24 09:24:26 +00:00
2002-01-02 01:25:48 +00:00
int_threshold = int_threshold * 32 ;
for ( y = 0 ; y < dest_height ; y + + ) {
2003-03-20 01:12:57 +00:00
for ( x = 0 ; x < dest_width ; x + + ) {
2002-01-02 01:25:48 +00:00
color_org = gdImageGetPixel ( im_tmp , x , y ) ;
median = ( im_tmp - > red [ color_org ] + im_tmp - > green [ color_org ] + im_tmp - > blue [ color_org ] ) / 3 ;
if ( median < int_threshold ) {
color = black ;
2003-03-20 01:12:57 +00:00
} else {
2002-01-02 01:25:48 +00:00
color = white ;
2001-01-24 09:24:26 +00:00
}
2002-01-02 01:25:48 +00:00
gdImageSetPixel ( im_dest , x , y , color ) ;
2001-01-24 09:24:26 +00:00
}
2002-01-02 01:25:48 +00:00
}
2001-01-24 09:24:26 +00:00
2002-01-02 01:25:48 +00:00
gdImageDestroy ( im_tmp ) ;
2001-01-24 09:24:26 +00:00
2003-03-20 01:12:57 +00:00
gdImageWBMP ( im_dest , black , dest ) ;
2001-01-24 09:24:26 +00:00
2002-01-02 01:25:48 +00:00
fflush ( dest ) ;
fclose ( dest ) ;
2001-01-24 09:24:26 +00:00
2003-03-20 01:12:57 +00:00
gdImageDestroy ( im_dest ) ;
2003-02-26 23:22:09 +00:00
2002-01-02 01:25:48 +00:00
RETURN_TRUE ;
2001-01-24 09:24:26 +00:00
}
2001-06-05 13:12:10 +00:00
/* }}} */
2001-01-25 20:52:52 +00:00
2001-01-24 09:24:26 +00:00
# endif /* HAVE_LIBGD */
1999-04-16 12:15:38 +00:00
2002-11-13 20:02:58 +00:00
/* Section Filters */
# ifdef HAVE_GD_BUNDLED
2004-05-09 17:39:20 +00:00
# define PHP_GD_SINGLE_RES \
zval * * SIM ; \
gdImagePtr im_src ; \
if ( zend_get_parameters_ex ( 1 , & SIM ) = = FAILURE ) { \
RETURN_FALSE ; \
} \
ZEND_FETCH_RESOURCE ( im_src , gdImagePtr , SIM , - 1 , " Image " , le_gd ) ; \
if ( im_src = = NULL ) { \
RETURN_FALSE ; \
2003-02-26 23:22:09 +00:00
}
2002-11-13 20:02:58 +00:00
2004-05-09 17:39:20 +00:00
static void php_image_filter_negate ( INTERNAL_FUNCTION_PARAMETERS )
{
PHP_GD_SINGLE_RES
2003-03-20 01:12:57 +00:00
if ( gdImageNegate ( im_src ) = = 1 ) {
2002-11-13 20:02:58 +00:00
RETURN_TRUE ;
}
2003-03-20 01:12:57 +00:00
2002-11-13 20:02:58 +00:00
RETURN_FALSE ;
}
static void php_image_filter_grayscale ( INTERNAL_FUNCTION_PARAMETERS )
{
2004-05-09 17:39:20 +00:00
PHP_GD_SINGLE_RES
2003-03-20 01:12:57 +00:00
if ( gdImageGrayScale ( im_src ) = = 1 ) {
2002-11-13 20:02:58 +00:00
RETURN_TRUE ;
}
2003-03-20 01:12:57 +00:00
2002-11-13 20:02:58 +00:00
RETURN_FALSE ;
}
static void php_image_filter_brightness ( INTERNAL_FUNCTION_PARAMETERS )
{
zval * SIM ;
gdImagePtr im_src ;
long brightness , tmp ;
2004-05-09 17:39:20 +00:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " zll " , & SIM , & tmp , & brightness ) = = FAILURE ) {
RETURN_FALSE ;
2003-02-26 23:22:09 +00:00
}
2002-11-13 20:02:58 +00:00
ZEND_FETCH_RESOURCE ( im_src , gdImagePtr , & SIM , - 1 , " Image " , le_gd ) ;
2003-03-20 01:12:57 +00:00
if ( im_src = = NULL ) {
2002-11-13 20:02:58 +00:00
RETURN_FALSE ;
}
2003-03-20 01:12:57 +00:00
if ( gdImageBrightness ( im_src , ( int ) brightness ) = = 1 ) {
2002-11-13 20:02:58 +00:00
RETURN_TRUE ;
}
2003-03-20 01:12:57 +00:00
2002-11-13 20:02:58 +00:00
RETURN_FALSE ;
}
static void php_image_filter_contrast ( INTERNAL_FUNCTION_PARAMETERS )
{
zval * SIM ;
gdImagePtr im_src ;
long contrast , tmp ;
2003-02-26 23:22:09 +00:00
2004-05-09 17:39:20 +00:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " rll " , & SIM , & tmp , & contrast ) = = FAILURE ) {
RETURN_FALSE ;
2003-02-26 23:22:09 +00:00
}
2002-11-13 20:02:58 +00:00
ZEND_FETCH_RESOURCE ( im_src , gdImagePtr , & SIM , - 1 , " Image " , le_gd ) ;
2003-03-20 01:12:57 +00:00
if ( im_src = = NULL ) {
2002-11-13 20:02:58 +00:00
RETURN_FALSE ;
}
2003-03-20 01:12:57 +00:00
2004-05-09 17:39:20 +00:00
if ( gdImageContrast ( im_src , ( int ) contrast ) = = 1 ) {
2002-11-13 20:02:58 +00:00
RETURN_TRUE ;
}
2003-03-20 01:12:57 +00:00
2002-11-13 20:02:58 +00:00
RETURN_FALSE ;
}
static void php_image_filter_colorize ( INTERNAL_FUNCTION_PARAMETERS )
{
zval * SIM ;
gdImagePtr im_src ;
long r , g , b , tmp ;
2004-05-09 17:39:20 +00:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " rllll " , & SIM , & tmp , & r , & g , & b ) = = FAILURE ) {
RETURN_FALSE ;
2003-02-26 23:22:09 +00:00
}
2002-11-13 20:02:58 +00:00
ZEND_FETCH_RESOURCE ( im_src , gdImagePtr , & SIM , - 1 , " Image " , le_gd ) ;
2003-03-20 01:12:57 +00:00
if ( im_src = = NULL ) {
2002-11-13 20:02:58 +00:00
RETURN_FALSE ;
}
2003-03-20 01:12:57 +00:00
if ( gdImageColor ( im_src , ( int ) r , ( int ) g , ( int ) b ) = = 1 ) {
2002-11-13 20:02:58 +00:00
RETURN_TRUE ;
}
2003-03-20 01:12:57 +00:00
2002-11-13 20:02:58 +00:00
RETURN_FALSE ;
}
static void php_image_filter_edgedetect ( INTERNAL_FUNCTION_PARAMETERS )
{
2004-05-09 17:39:20 +00:00
PHP_GD_SINGLE_RES
2003-03-20 01:12:57 +00:00
if ( gdImageEdgeDetectQuick ( im_src ) = = 1 ) {
2002-11-13 20:02:58 +00:00
RETURN_TRUE ;
}
2003-03-20 01:12:57 +00:00
2002-11-13 20:02:58 +00:00
RETURN_FALSE ;
}
static void php_image_filter_emboss ( INTERNAL_FUNCTION_PARAMETERS )
{
2004-05-09 17:39:20 +00:00
PHP_GD_SINGLE_RES
2003-03-20 01:12:57 +00:00
if ( gdImageEmboss ( im_src ) = = 1 ) {
2002-11-13 20:02:58 +00:00
RETURN_TRUE ;
}
2003-03-20 01:12:57 +00:00
2002-11-13 20:02:58 +00:00
RETURN_FALSE ;
}
static void php_image_filter_gaussian_blur ( INTERNAL_FUNCTION_PARAMETERS )
{
2004-05-09 17:39:20 +00:00
PHP_GD_SINGLE_RES
2003-03-20 01:12:57 +00:00
if ( gdImageGaussianBlur ( im_src ) = = 1 ) {
2002-11-13 20:02:58 +00:00
RETURN_TRUE ;
}
2003-03-20 01:12:57 +00:00
2002-11-13 20:02:58 +00:00
RETURN_FALSE ;
}
static void php_image_filter_selective_blur ( INTERNAL_FUNCTION_PARAMETERS )
{
2004-05-09 17:39:20 +00:00
PHP_GD_SINGLE_RES
2003-03-20 01:12:57 +00:00
if ( gdImageSelectiveBlur ( im_src ) = = 1 ) {
2002-11-13 20:02:58 +00:00
RETURN_TRUE ;
}
2003-03-20 01:12:57 +00:00
2002-11-13 20:02:58 +00:00
RETURN_FALSE ;
}
static void php_image_filter_mean_removal ( INTERNAL_FUNCTION_PARAMETERS )
{
2004-05-09 17:39:20 +00:00
PHP_GD_SINGLE_RES
2003-03-20 01:12:57 +00:00
if ( gdImageMeanRemoval ( im_src ) = = 1 ) {
2002-11-13 20:02:58 +00:00
RETURN_TRUE ;
}
2003-03-20 01:12:57 +00:00
2002-11-13 20:02:58 +00:00
RETURN_FALSE ;
}
static void php_image_filter_smooth ( INTERNAL_FUNCTION_PARAMETERS )
{
zval * SIM ;
long tmp ;
gdImagePtr im_src ;
double weight ;
2004-05-09 17:39:20 +00:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " rld " , & SIM , & tmp , & weight ) = = FAILURE ) {
RETURN_FALSE ;
2003-02-26 23:22:09 +00:00
}
2002-11-13 20:02:58 +00:00
ZEND_FETCH_RESOURCE ( im_src , gdImagePtr , & SIM , - 1 , " Image " , le_gd ) ;
2003-03-20 01:12:57 +00:00
if ( im_src = = NULL ) {
2002-11-13 20:02:58 +00:00
RETURN_FALSE ;
}
2003-03-20 01:12:57 +00:00
2002-11-28 22:48:20 +00:00
if ( gdImageSmooth ( im_src , ( float ) weight ) = = 1 ) {
2002-11-13 20:02:58 +00:00
RETURN_TRUE ;
}
2003-03-20 01:12:57 +00:00
2002-11-13 20:02:58 +00:00
RETURN_FALSE ;
}
2003-06-15 15:29:46 +00:00
/* {{{ proto bool imagefilter(resource src_im, int filtertype, [args] )
2002-11-13 20:02:58 +00:00
Applies Filter an image using a custom angle */
PHP_FUNCTION ( imagefilter )
{
zval * tmp ;
typedef void ( * image_filter ) ( INTERNAL_FUNCTION_PARAMETERS ) ;
long filtertype ;
2003-02-26 23:22:09 +00:00
image_filter filters [ ] =
2002-11-13 20:02:58 +00:00
{
php_image_filter_negate ,
php_image_filter_grayscale ,
php_image_filter_brightness ,
php_image_filter_contrast ,
php_image_filter_colorize ,
php_image_filter_edgedetect ,
php_image_filter_emboss ,
php_image_filter_gaussian_blur ,
php_image_filter_selective_blur ,
php_image_filter_mean_removal ,
php_image_filter_smooth
} ;
2003-03-20 01:12:57 +00:00
if ( ZEND_NUM_ARGS ( ) < 2 | | ZEND_NUM_ARGS ( ) > 5 | | zend_parse_parameters ( 2 TSRMLS_CC , " rl " , & tmp , & filtertype ) = = FAILURE ) {
2002-11-13 20:02:58 +00:00
ZEND_WRONG_PARAM_COUNT ( ) ;
2003-02-26 23:22:09 +00:00
}
2002-11-13 20:02:58 +00:00
2003-03-20 01:12:57 +00:00
if ( filtertype > = 0 & & filtertype < = IMAGE_FILTER_MAX ) {
2002-11-13 20:02:58 +00:00
filters [ filtertype ] ( INTERNAL_FUNCTION_PARAM_PASSTHRU ) ;
}
}
/* }}} */
2005-04-16 12:12:24 +00:00
/* {{{ proto resource imageconvolution(resource src_im, array matrix3x3, double div, double offset)
Apply a 3 x3 convolution matrix , using coefficient div and offset */
PHP_FUNCTION ( imageconvolution )
{
zval * SIM , * hash_matrix ;
2005-12-06 01:26:39 +00:00
zval * * var = NULL , * * var2 = NULL ;
2005-04-16 12:12:24 +00:00
gdImagePtr im_src = NULL ;
2005-10-27 11:07:39 +00:00
double div , offset ;
2005-04-16 12:12:24 +00:00
int nelem , i , j , res ;
2005-04-17 10:17:03 +00:00
float matrix [ 3 ] [ 3 ] = { { 0 , 0 , 0 } , { 0 , 0 , 0 } , { 0 , 0 , 0 } } ;
2005-04-16 12:12:24 +00:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " radd " , & SIM , & hash_matrix , & div , & offset ) = = FAILURE ) {
RETURN_FALSE ;
}
ZEND_FETCH_RESOURCE ( im_src , gdImagePtr , & SIM , - 1 , " Image " , le_gd ) ;
nelem = zend_hash_num_elements ( Z_ARRVAL_P ( hash_matrix ) ) ;
if ( nelem ! = 3 ) {
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " You must have 3x3 array " ) ;
RETURN_FALSE ;
}
for ( i = 0 ; i < 3 ; i + + ) {
if ( zend_hash_index_find ( Z_ARRVAL_P ( hash_matrix ) , ( i ) , ( void * * ) & var ) = = SUCCESS ) {
if ( Z_TYPE_PP ( var ) ! = IS_ARRAY | | zend_hash_num_elements ( Z_ARRVAL_PP ( var ) ) ! = 3 ) {
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " You must have 3x3 array " ) ;
RETURN_FALSE ;
}
for ( j = 0 ; j < 3 ; j + + ) {
if ( zend_hash_index_find ( Z_ARRVAL_PP ( var ) , ( j ) , ( void * * ) & var2 ) = = SUCCESS ) {
SEPARATE_ZVAL ( var2 ) ;
convert_to_double ( * var2 ) ;
matrix [ i ] [ j ] = Z_DVAL_PP ( var2 ) ;
} else {
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " You must have a 3x3 matrix " ) ;
RETURN_FALSE ;
}
}
}
}
res = gdImageConvolution ( im_src , matrix , div , offset ) ;
if ( res ) {
RETURN_TRUE ;
} else {
RETURN_FALSE ;
}
}
/* }}} */
2002-12-11 22:25:23 +00:00
/* End section: Filters */
2002-12-11 20:44:44 +00:00
2003-06-15 15:29:46 +00:00
/* {{{ proto bool imageantialias(resource im, bool on)
2003-03-20 01:12:57 +00:00
Should antialiased functions used or not */
2002-12-11 20:44:44 +00:00
PHP_FUNCTION ( imageantialias )
{
zval * * IM , * * alias ;
gdImagePtr im ;
if ( ZEND_NUM_ARGS ( ) ! = 2 | | zend_get_parameters_ex ( 2 , & IM , & alias ) = = FAILURE ) {
ZEND_WRONG_PARAM_COUNT ( ) ;
}
2003-03-20 01:12:57 +00:00
2002-12-11 20:44:44 +00:00
ZEND_FETCH_RESOURCE ( im , gdImagePtr , IM , - 1 , " Image " , le_gd ) ;
2003-03-20 01:12:57 +00:00
2002-12-11 20:44:44 +00:00
convert_to_boolean_ex ( alias ) ;
gdImageAntialias ( im , Z_LVAL_PP ( alias ) ) ;
2003-03-20 01:12:57 +00:00
2002-12-11 20:44:44 +00:00
RETURN_TRUE ;
}
/* }}} */
2002-12-11 22:25:23 +00:00
# endif
2002-11-13 20:02:58 +00:00
1999-04-16 12:15:38 +00:00
/*
* Local variables :
* tab - width : 4
* c - basic - offset : 4
* End :
2001-09-09 13:29:31 +00:00
* vim600 : sw = 4 ts = 4 fdm = marker
* vim < 600 : sw = 4 ts = 4
1999-04-16 12:15:38 +00:00
*/