1999-04-16 20:15:38 +08:00
/*
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2014-09-20 00:33:14 +08:00
| PHP Version 7 |
1999-04-16 20:15:38 +08:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2015-01-15 23:27:30 +08:00
| Copyright ( c ) 1997 - 2015 The PHP Group |
1999-04-16 20:15:38 +08:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2006-01-01 20:51:34 +08:00
| This source file is subject to version 3.01 of the PHP license , |
1999-07-16 21:13:16 +08:00
| that is bundled with this package in the file LICENSE , and is |
2003-06-11 04:04:29 +08:00
| available through the world - wide - web at the following url : |
2006-01-01 20:51:34 +08:00
| http : //www.php.net/license/3_01.txt |
1999-07-16 21:13:16 +08: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 20:15:38 +08:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2002-02-28 16:29:35 +08:00
| Authors : Rasmus Lerdorf < rasmus @ php . net > |
2003-03-18 20:06:09 +08:00
| Stig Bakken < ssb @ php . net > |
1999-04-16 20:15:38 +08:00
| Jim Winstead < jimw @ php . net > |
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
*/
/* $Id$ */
2003-02-27 07:22:09 +08:00
/* gd 1.2 is copyright 1994, 1995, Quest Protein Database Center,
1999-04-16 20:15:38 +08:00
Cold Spring Harbor Labs . */
/* Note that there is no code from the gd package in this file */
1999-04-24 04:06:01 +08:00
2001-05-24 18:07:29 +08:00
# ifdef HAVE_CONFIG_H
# include "config.h"
# endif
1999-04-16 20:15:38 +08:00
# include "php.h"
2006-02-05 23:53:58 +08:00
# include "php_ini.h"
1999-04-22 08:25:57 +08:00
# include "ext/standard/head.h"
1999-04-16 20:15:38 +08:00
# include <math.h>
1999-04-27 01:26:37 +08:00
# include "SAPI.h"
1999-12-05 03:19:57 +08:00
# include "php_gd.h"
2000-11-29 23:25:42 +08:00
# include "ext/standard/info.h"
2004-08-17 07:07:42 +08:00
# include "php_open_temporary_file.h"
1999-04-16 20:15:38 +08:00
2008-08-29 19:09:28 +08:00
1999-04-16 20:15:38 +08:00
# if HAVE_SYS_WAIT_H
# include <sys / wait.h>
# endif
# if HAVE_UNISTD_H
# include <unistd.h>
# endif
2000-06-16 07:45:05 +08:00
# ifdef PHP_WIN32
1999-04-16 20:15:38 +08:00
# include <io.h>
# include <fcntl.h>
2009-04-07 20:45:26 +08:00
# include <windows.h>
# include <Winuser.h>
# include <Wingdi.h>
1999-04-16 20:15:38 +08:00
# endif
2013-05-04 22:51:56 +08:00
# ifdef HAVE_GD_XPM
# include <X11 / xpm.h>
2009-04-07 17:26:22 +08:00
# endif
2013-05-05 15:54:27 +08:00
# include "gd_compat.h"
2013-05-06 16:00:45 +08:00
2013-05-03 21:37:39 +08:00
2000-11-29 23:25:42 +08:00
static int le_gd , le_gd_font ;
2000-04-06 06:30:19 +08:00
1999-04-16 20:15:38 +08: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 */
2008-08-29 19:09:28 +08:00
1999-07-23 23:18:37 +08:00
# ifdef ENABLE_GD_TTF
2003-09-10 03:08:30 +08:00
# ifdef HAVE_LIBFREETYPE
2003-12-18 16:17:45 +08:00
# include <ft2build.h>
# include FT_FREETYPE_H
2003-09-10 03:08:30 +08:00
# endif
1999-04-16 20:15:38 +08:00
# endif
2013-03-22 15:28:11 +08:00
# if defined(HAVE_GD_XPM) && defined(HAVE_GD_BUNDLED)
# include "X11 / xpm.h"
# endif
1999-04-16 20:15:38 +08:00
# ifndef M_PI
# define M_PI 3.14159265358979323846
# endif
1999-07-23 23:18:37 +08:00
# ifdef ENABLE_GD_TTF
2001-07-06 05:23:28 +08:00
static void php_imagettftext_common ( INTERNAL_FUNCTION_PARAMETERS , int , int ) ;
1999-04-16 20:15:38 +08:00
# endif
2001-02-01 23:40:35 +08:00
# include "gd_ctx.c"
2004-07-27 08:27:06 +08:00
2015-01-03 17:22:58 +08:00
/* as it is not really public, duplicate declaration here to avoid
2013-03-22 15:28:11 +08:00
pointless warnings */
int overflow2 ( int a , int b ) ;
2002-11-14 04:02:58 +08:00
/* Section Filters Declarations */
/* IMPORTANT NOTE FOR NEW FILTER
* Do not forget to update :
* IMAGE_FILTER_MAX : define the last filter index
2013-07-13 20:37:04 +08:00
* IMAGE_FILTER_MAX_ARGS : define the biggest amount of arguments
2002-11-14 04:02:58 +08:00
* image_filter array in PHP_FUNCTION ( imagefilter )
* */
# 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
2009-01-15 03:06:12 +08:00
# define IMAGE_FILTER_PIXELATE 11
# define IMAGE_FILTER_MAX 11
2009-01-20 00:35:58 +08:00
# define IMAGE_FILTER_MAX_ARGS 6
2002-11-14 04:02:58 +08:00
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 ) ;
2009-01-15 03:06:12 +08:00
static void php_image_filter_pixelate ( INTERNAL_FUNCTION_PARAMETERS ) ;
2009-05-26 20:50:40 +08:00
2002-11-14 04:02:58 +08:00
/* End Section filters declarations */
2014-12-14 06:06:14 +08:00
static gdImagePtr _php_image_create_from_string ( zval * Data , char * tn , gdImagePtr ( * ioctx_func_p ) ( ) ) ;
2001-04-07 02:01:52 +08: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 09:12:57 +08:00
static int _php_image_type ( char data [ 8 ] ) ;
2001-04-07 02:01:52 +08:00
static void _php_image_convert ( INTERNAL_FUNCTION_PARAMETERS , int image_type ) ;
2001-04-01 13:42:07 +08:00
static void _php_image_bw_convert ( gdImagePtr im_org , gdIOCtx * out , int threshold ) ;
2001-02-01 23:40:35 +08:00
2006-06-12 04:03:05 +08:00
/* {{{ arginfo */
ZEND_BEGIN_ARG_INFO ( arginfo_gd_info , 0 )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imageloadfont , 0 )
ZEND_ARG_INFO ( 0 , filename )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagesetstyle , 0 )
ZEND_ARG_INFO ( 0 , im )
2006-06-15 23:31:54 +08:00
ZEND_ARG_INFO ( 0 , styles ) /* ARRAY_INFO(0, styles, 0) */
2006-06-12 04:03:05 +08:00
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagecreatetruecolor , 0 )
ZEND_ARG_INFO ( 0 , x_size )
ZEND_ARG_INFO ( 0 , y_size )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imageistruecolor , 0 )
ZEND_ARG_INFO ( 0 , im )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagetruecolortopalette , 0 )
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , ditherFlag )
ZEND_ARG_INFO ( 0 , colorsWanted )
ZEND_END_ARG_INFO ( )
2013-03-20 14:46:59 +08:00
ZEND_BEGIN_ARG_INFO ( arginfo_imagepalettetotruecolor , 0 )
ZEND_ARG_INFO ( 0 , im )
ZEND_END_ARG_INFO ( )
2006-06-12 04:03:05 +08:00
ZEND_BEGIN_ARG_INFO ( arginfo_imagecolormatch , 0 )
ZEND_ARG_INFO ( 0 , im1 )
ZEND_ARG_INFO ( 0 , im2 )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagesetthickness , 0 )
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , thickness )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagefilledellipse , 0 )
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , cx )
ZEND_ARG_INFO ( 0 , cy )
ZEND_ARG_INFO ( 0 , w )
ZEND_ARG_INFO ( 0 , h )
ZEND_ARG_INFO ( 0 , color )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagefilledarc , 0 )
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , cx )
ZEND_ARG_INFO ( 0 , cy )
ZEND_ARG_INFO ( 0 , w )
ZEND_ARG_INFO ( 0 , h )
ZEND_ARG_INFO ( 0 , s )
ZEND_ARG_INFO ( 0 , e )
ZEND_ARG_INFO ( 0 , col )
ZEND_ARG_INFO ( 0 , style )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagealphablending , 0 )
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , blend )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagesavealpha , 0 )
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , save )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagelayereffect , 0 )
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , effect )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagecolorallocatealpha , 0 )
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , red )
ZEND_ARG_INFO ( 0 , green )
ZEND_ARG_INFO ( 0 , blue )
ZEND_ARG_INFO ( 0 , alpha )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagecolorresolvealpha , 0 )
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , red )
ZEND_ARG_INFO ( 0 , green )
ZEND_ARG_INFO ( 0 , blue )
ZEND_ARG_INFO ( 0 , alpha )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagecolorclosestalpha , 0 )
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , red )
ZEND_ARG_INFO ( 0 , green )
ZEND_ARG_INFO ( 0 , blue )
ZEND_ARG_INFO ( 0 , alpha )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagecolorexactalpha , 0 )
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , red )
ZEND_ARG_INFO ( 0 , green )
ZEND_ARG_INFO ( 0 , blue )
ZEND_ARG_INFO ( 0 , alpha )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagecopyresampled , 0 )
ZEND_ARG_INFO ( 0 , dst_im )
ZEND_ARG_INFO ( 0 , src_im )
ZEND_ARG_INFO ( 0 , dst_x )
ZEND_ARG_INFO ( 0 , dst_y )
ZEND_ARG_INFO ( 0 , src_x )
ZEND_ARG_INFO ( 0 , src_y )
ZEND_ARG_INFO ( 0 , dst_w )
ZEND_ARG_INFO ( 0 , dst_h )
ZEND_ARG_INFO ( 0 , src_w )
ZEND_ARG_INFO ( 0 , src_h )
ZEND_END_ARG_INFO ( )
2007-04-17 23:31:45 +08:00
# ifdef PHP_WIN32
2007-04-17 23:39:19 +08:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_imagegrabwindow , 0 , 0 , 1 )
2007-04-17 23:31:45 +08:00
ZEND_ARG_INFO ( 0 , handle )
ZEND_ARG_INFO ( 0 , client_area )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagegrabscreen , 0 )
ZEND_END_ARG_INFO ( )
# endif
2006-06-12 04:03:05 +08:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_imagerotate , 0 , 0 , 3 )
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , angle )
ZEND_ARG_INFO ( 0 , bgdcolor )
ZEND_ARG_INFO ( 0 , ignoretransparent )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagesettile , 0 )
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , tile )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagesetbrush , 0 )
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , brush )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagecreate , 0 )
ZEND_ARG_INFO ( 0 , x_size )
ZEND_ARG_INFO ( 0 , y_size )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagetypes , 0 )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagecreatefromstring , 0 )
ZEND_ARG_INFO ( 0 , image )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagecreatefromgif , 0 )
ZEND_ARG_INFO ( 0 , filename )
ZEND_END_ARG_INFO ( )
# ifdef HAVE_GD_JPG
ZEND_BEGIN_ARG_INFO ( arginfo_imagecreatefromjpeg , 0 )
ZEND_ARG_INFO ( 0 , filename )
ZEND_END_ARG_INFO ( )
# endif
# ifdef HAVE_GD_PNG
ZEND_BEGIN_ARG_INFO ( arginfo_imagecreatefrompng , 0 )
ZEND_ARG_INFO ( 0 , filename )
ZEND_END_ARG_INFO ( )
# endif
2010-10-05 06:30:35 +08:00
# ifdef HAVE_GD_WEBP
ZEND_BEGIN_ARG_INFO ( arginfo_imagecreatefromwebp , 0 )
ZEND_ARG_INFO ( 0 , filename )
ZEND_END_ARG_INFO ( )
# endif
2006-06-12 04:03:05 +08:00
ZEND_BEGIN_ARG_INFO ( arginfo_imagecreatefromxbm , 0 )
ZEND_ARG_INFO ( 0 , filename )
ZEND_END_ARG_INFO ( )
2013-05-03 19:53:55 +08:00
# if defined(HAVE_GD_XPM)
2006-06-12 04:03:05 +08:00
ZEND_BEGIN_ARG_INFO ( arginfo_imagecreatefromxpm , 0 )
ZEND_ARG_INFO ( 0 , filename )
ZEND_END_ARG_INFO ( )
# endif
ZEND_BEGIN_ARG_INFO ( arginfo_imagecreatefromwbmp , 0 )
ZEND_ARG_INFO ( 0 , filename )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagecreatefromgd , 0 )
ZEND_ARG_INFO ( 0 , filename )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagecreatefromgd2 , 0 )
ZEND_ARG_INFO ( 0 , filename )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagecreatefromgd2part , 0 )
ZEND_ARG_INFO ( 0 , filename )
ZEND_ARG_INFO ( 0 , srcX )
ZEND_ARG_INFO ( 0 , srcY )
ZEND_ARG_INFO ( 0 , width )
ZEND_ARG_INFO ( 0 , height )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO_EX ( arginfo_imagexbm , 0 , 0 , 2 )
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , filename )
ZEND_ARG_INFO ( 0 , foreground )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO_EX ( arginfo_imagegif , 0 , 0 , 1 )
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , filename )
ZEND_END_ARG_INFO ( )
# ifdef HAVE_GD_PNG
2006-10-19 00:04:37 +08:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_imagepng , 0 , 0 , 1 )
2006-06-12 04:03:05 +08:00
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , filename )
ZEND_END_ARG_INFO ( )
# endif
2010-10-05 06:30:35 +08:00
# ifdef HAVE_GD_WEBP
ZEND_BEGIN_ARG_INFO_EX ( arginfo_imagewebp , 0 , 0 , 1 )
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , filename )
ZEND_END_ARG_INFO ( )
# endif
2006-06-12 04:03:05 +08:00
# ifdef HAVE_GD_JPG
2006-10-19 00:04:37 +08:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_imagejpeg , 0 , 0 , 1 )
2006-06-12 04:03:05 +08:00
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , filename )
ZEND_ARG_INFO ( 0 , quality )
ZEND_END_ARG_INFO ( )
# endif
ZEND_BEGIN_ARG_INFO_EX ( arginfo_imagewbmp , 0 , 0 , 1 )
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , filename )
ZEND_ARG_INFO ( 0 , foreground )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO_EX ( arginfo_imagegd , 0 , 0 , 1 )
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , filename )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO_EX ( arginfo_imagegd2 , 0 , 0 , 1 )
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , filename )
ZEND_ARG_INFO ( 0 , chunk_size )
ZEND_ARG_INFO ( 0 , type )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagedestroy , 0 )
ZEND_ARG_INFO ( 0 , im )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagecolorallocate , 0 )
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , red )
ZEND_ARG_INFO ( 0 , green )
ZEND_ARG_INFO ( 0 , blue )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagepalettecopy , 0 )
ZEND_ARG_INFO ( 0 , dst )
ZEND_ARG_INFO ( 0 , src )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagecolorat , 0 )
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , x )
ZEND_ARG_INFO ( 0 , y )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagecolorclosest , 0 )
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , red )
ZEND_ARG_INFO ( 0 , green )
ZEND_ARG_INFO ( 0 , blue )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagecolorclosesthwb , 0 )
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , red )
ZEND_ARG_INFO ( 0 , green )
ZEND_ARG_INFO ( 0 , blue )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagecolordeallocate , 0 )
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , index )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagecolorresolve , 0 )
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , red )
ZEND_ARG_INFO ( 0 , green )
ZEND_ARG_INFO ( 0 , blue )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagecolorexact , 0 )
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , red )
ZEND_ARG_INFO ( 0 , green )
ZEND_ARG_INFO ( 0 , blue )
ZEND_END_ARG_INFO ( )
2010-05-18 20:38:57 +08:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_imagecolorset , 0 , 0 , 5 )
2006-06-12 04:03:05 +08:00
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , color )
ZEND_ARG_INFO ( 0 , red )
ZEND_ARG_INFO ( 0 , green )
ZEND_ARG_INFO ( 0 , blue )
2010-05-18 20:38:57 +08:00
ZEND_ARG_INFO ( 0 , alpha )
2006-06-12 04:03:05 +08:00
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagecolorsforindex , 0 )
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , index )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagegammacorrect , 0 )
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , inputgamma )
ZEND_ARG_INFO ( 0 , outputgamma )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagesetpixel , 0 )
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , x )
ZEND_ARG_INFO ( 0 , y )
ZEND_ARG_INFO ( 0 , col )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imageline , 0 )
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , x1 )
ZEND_ARG_INFO ( 0 , y1 )
ZEND_ARG_INFO ( 0 , x2 )
ZEND_ARG_INFO ( 0 , y2 )
ZEND_ARG_INFO ( 0 , col )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagedashedline , 0 )
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , x1 )
ZEND_ARG_INFO ( 0 , y1 )
ZEND_ARG_INFO ( 0 , x2 )
ZEND_ARG_INFO ( 0 , y2 )
ZEND_ARG_INFO ( 0 , col )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagerectangle , 0 )
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , x1 )
ZEND_ARG_INFO ( 0 , y1 )
ZEND_ARG_INFO ( 0 , x2 )
ZEND_ARG_INFO ( 0 , y2 )
ZEND_ARG_INFO ( 0 , col )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagefilledrectangle , 0 )
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , x1 )
ZEND_ARG_INFO ( 0 , y1 )
ZEND_ARG_INFO ( 0 , x2 )
ZEND_ARG_INFO ( 0 , y2 )
ZEND_ARG_INFO ( 0 , col )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagearc , 0 )
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , cx )
ZEND_ARG_INFO ( 0 , cy )
ZEND_ARG_INFO ( 0 , w )
ZEND_ARG_INFO ( 0 , h )
ZEND_ARG_INFO ( 0 , s )
ZEND_ARG_INFO ( 0 , e )
ZEND_ARG_INFO ( 0 , col )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imageellipse , 0 )
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , cx )
ZEND_ARG_INFO ( 0 , cy )
ZEND_ARG_INFO ( 0 , w )
ZEND_ARG_INFO ( 0 , h )
ZEND_ARG_INFO ( 0 , color )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagefilltoborder , 0 )
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , x )
ZEND_ARG_INFO ( 0 , y )
ZEND_ARG_INFO ( 0 , border )
ZEND_ARG_INFO ( 0 , col )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagefill , 0 )
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , x )
ZEND_ARG_INFO ( 0 , y )
ZEND_ARG_INFO ( 0 , col )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagecolorstotal , 0 )
ZEND_ARG_INFO ( 0 , im )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO_EX ( arginfo_imagecolortransparent , 0 , 0 , 1 )
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , col )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO_EX ( arginfo_imageinterlace , 0 , 0 , 1 )
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , interlace )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagepolygon , 0 )
ZEND_ARG_INFO ( 0 , im )
2006-06-15 23:31:54 +08:00
ZEND_ARG_INFO ( 0 , points ) /* ARRAY_INFO(0, points, 0) */
2006-06-12 04:03:05 +08:00
ZEND_ARG_INFO ( 0 , num_pos )
ZEND_ARG_INFO ( 0 , col )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagefilledpolygon , 0 )
ZEND_ARG_INFO ( 0 , im )
2006-06-15 23:31:54 +08:00
ZEND_ARG_INFO ( 0 , points ) /* ARRAY_INFO(0, points, 0) */
2006-06-12 04:03:05 +08:00
ZEND_ARG_INFO ( 0 , num_pos )
ZEND_ARG_INFO ( 0 , col )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagefontwidth , 0 )
ZEND_ARG_INFO ( 0 , font )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagefontheight , 0 )
ZEND_ARG_INFO ( 0 , font )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagechar , 0 )
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , font )
ZEND_ARG_INFO ( 0 , x )
ZEND_ARG_INFO ( 0 , y )
ZEND_ARG_INFO ( 0 , c )
ZEND_ARG_INFO ( 0 , col )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagecharup , 0 )
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , font )
ZEND_ARG_INFO ( 0 , x )
ZEND_ARG_INFO ( 0 , y )
ZEND_ARG_INFO ( 0 , c )
ZEND_ARG_INFO ( 0 , col )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagestring , 0 )
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , font )
ZEND_ARG_INFO ( 0 , x )
ZEND_ARG_INFO ( 0 , y )
ZEND_ARG_INFO ( 0 , str )
ZEND_ARG_INFO ( 0 , col )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagestringup , 0 )
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , font )
ZEND_ARG_INFO ( 0 , x )
ZEND_ARG_INFO ( 0 , y )
ZEND_ARG_INFO ( 0 , str )
ZEND_ARG_INFO ( 0 , col )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagecopy , 0 )
ZEND_ARG_INFO ( 0 , dst_im )
ZEND_ARG_INFO ( 0 , src_im )
ZEND_ARG_INFO ( 0 , dst_x )
ZEND_ARG_INFO ( 0 , dst_y )
ZEND_ARG_INFO ( 0 , src_x )
ZEND_ARG_INFO ( 0 , src_y )
ZEND_ARG_INFO ( 0 , src_w )
ZEND_ARG_INFO ( 0 , src_h )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagecopymerge , 0 )
ZEND_ARG_INFO ( 0 , src_im )
ZEND_ARG_INFO ( 0 , dst_im )
ZEND_ARG_INFO ( 0 , dst_x )
ZEND_ARG_INFO ( 0 , dst_y )
ZEND_ARG_INFO ( 0 , src_x )
ZEND_ARG_INFO ( 0 , src_y )
ZEND_ARG_INFO ( 0 , src_w )
ZEND_ARG_INFO ( 0 , src_h )
ZEND_ARG_INFO ( 0 , pct )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagecopymergegray , 0 )
ZEND_ARG_INFO ( 0 , src_im )
ZEND_ARG_INFO ( 0 , dst_im )
ZEND_ARG_INFO ( 0 , dst_x )
ZEND_ARG_INFO ( 0 , dst_y )
ZEND_ARG_INFO ( 0 , src_x )
ZEND_ARG_INFO ( 0 , src_y )
ZEND_ARG_INFO ( 0 , src_w )
ZEND_ARG_INFO ( 0 , src_h )
ZEND_ARG_INFO ( 0 , pct )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagecopyresized , 0 )
ZEND_ARG_INFO ( 0 , dst_im )
ZEND_ARG_INFO ( 0 , src_im )
ZEND_ARG_INFO ( 0 , dst_x )
ZEND_ARG_INFO ( 0 , dst_y )
ZEND_ARG_INFO ( 0 , src_x )
ZEND_ARG_INFO ( 0 , src_y )
ZEND_ARG_INFO ( 0 , dst_w )
ZEND_ARG_INFO ( 0 , dst_h )
ZEND_ARG_INFO ( 0 , src_w )
ZEND_ARG_INFO ( 0 , src_h )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagesx , 0 )
ZEND_ARG_INFO ( 0 , im )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagesy , 0 )
ZEND_ARG_INFO ( 0 , im )
ZEND_END_ARG_INFO ( )
# ifdef ENABLE_GD_TTF
2013-05-03 19:53:55 +08:00
# if HAVE_LIBFREETYPE
2006-06-12 04:03:05 +08:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_imageftbbox , 0 , 0 , 4 )
2006-07-02 08:11:06 +08:00
ZEND_ARG_INFO ( 0 , size )
ZEND_ARG_INFO ( 0 , angle )
2006-06-12 04:03:05 +08:00
ZEND_ARG_INFO ( 0 , font_file )
ZEND_ARG_INFO ( 0 , text )
2006-06-15 23:31:54 +08:00
ZEND_ARG_INFO ( 0 , extrainfo ) /* ARRAY_INFO(0, extrainfo, 0) */
2006-06-12 04:03:05 +08:00
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO_EX ( arginfo_imagefttext , 0 , 0 , 8 )
ZEND_ARG_INFO ( 0 , im )
2006-07-02 08:11:06 +08:00
ZEND_ARG_INFO ( 0 , size )
ZEND_ARG_INFO ( 0 , angle )
2006-06-12 04:03:05 +08:00
ZEND_ARG_INFO ( 0 , x )
ZEND_ARG_INFO ( 0 , y )
ZEND_ARG_INFO ( 0 , col )
ZEND_ARG_INFO ( 0 , font_file )
ZEND_ARG_INFO ( 0 , text )
2006-06-15 23:31:54 +08:00
ZEND_ARG_INFO ( 0 , extrainfo ) /* ARRAY_INFO(0, extrainfo, 0) */
2006-06-12 04:03:05 +08:00
ZEND_END_ARG_INFO ( )
# endif
ZEND_BEGIN_ARG_INFO ( arginfo_imagettfbbox , 0 )
ZEND_ARG_INFO ( 0 , size )
ZEND_ARG_INFO ( 0 , angle )
ZEND_ARG_INFO ( 0 , font_file )
ZEND_ARG_INFO ( 0 , text )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imagettftext , 0 )
ZEND_ARG_INFO ( 0 , im )
2006-07-02 08:11:06 +08:00
ZEND_ARG_INFO ( 0 , size )
ZEND_ARG_INFO ( 0 , angle )
2006-06-12 04:03:05 +08:00
ZEND_ARG_INFO ( 0 , x )
ZEND_ARG_INFO ( 0 , y )
ZEND_ARG_INFO ( 0 , col )
ZEND_ARG_INFO ( 0 , font_file )
ZEND_ARG_INFO ( 0 , text )
ZEND_END_ARG_INFO ( )
# endif
ZEND_BEGIN_ARG_INFO_EX ( arginfo_image2wbmp , 0 , 0 , 1 )
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , filename )
ZEND_ARG_INFO ( 0 , threshold )
ZEND_END_ARG_INFO ( )
2013-05-03 19:53:55 +08:00
# if defined(HAVE_GD_JPG)
2006-06-12 04:03:05 +08:00
ZEND_BEGIN_ARG_INFO ( arginfo_jpeg2wbmp , 0 )
ZEND_ARG_INFO ( 0 , f_org )
ZEND_ARG_INFO ( 0 , f_dest )
ZEND_ARG_INFO ( 0 , d_height )
ZEND_ARG_INFO ( 0 , d_width )
ZEND_ARG_INFO ( 0 , d_threshold )
ZEND_END_ARG_INFO ( )
# endif
2013-05-03 19:53:55 +08:00
# if defined(HAVE_GD_PNG)
2006-06-12 04:03:05 +08:00
ZEND_BEGIN_ARG_INFO ( arginfo_png2wbmp , 0 )
ZEND_ARG_INFO ( 0 , f_org )
ZEND_ARG_INFO ( 0 , f_dest )
ZEND_ARG_INFO ( 0 , d_height )
ZEND_ARG_INFO ( 0 , d_width )
ZEND_ARG_INFO ( 0 , d_threshold )
ZEND_END_ARG_INFO ( )
# endif
ZEND_BEGIN_ARG_INFO_EX ( arginfo_imagefilter , 0 , 0 , 2 )
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , filtertype )
ZEND_ARG_INFO ( 0 , arg1 )
ZEND_ARG_INFO ( 0 , arg2 )
ZEND_ARG_INFO ( 0 , arg3 )
2009-01-31 23:27:52 +08:00
ZEND_ARG_INFO ( 0 , arg4 )
2006-06-12 04:03:05 +08:00
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo_imageconvolution , 0 )
ZEND_ARG_INFO ( 0 , im )
2006-06-15 23:31:54 +08:00
ZEND_ARG_INFO ( 0 , matrix3x3 ) /* ARRAY_INFO(0, matrix3x3, 0) */
2006-06-12 04:03:05 +08:00
ZEND_ARG_INFO ( 0 , div )
ZEND_ARG_INFO ( 0 , offset )
ZEND_END_ARG_INFO ( )
2013-04-24 20:32:03 +08:00
ZEND_BEGIN_ARG_INFO ( arginfo_imageflip , 0 )
2006-06-12 04:03:05 +08:00
ZEND_ARG_INFO ( 0 , im )
2013-04-24 20:32:03 +08:00
ZEND_ARG_INFO ( 0 , mode )
2006-06-12 04:03:05 +08:00
ZEND_END_ARG_INFO ( )
2013-02-27 17:39:25 +08:00
2013-04-24 20:32:03 +08:00
# ifdef HAVE_GD_BUNDLED
ZEND_BEGIN_ARG_INFO ( arginfo_imageantialias , 0 )
2013-02-27 17:39:25 +08:00
ZEND_ARG_INFO ( 0 , im )
2013-04-24 20:32:03 +08:00
ZEND_ARG_INFO ( 0 , on )
2013-02-27 17:39:25 +08:00
ZEND_END_ARG_INFO ( )
2013-04-25 19:39:35 +08:00
# endif
2013-03-01 00:24:23 +08:00
2013-03-01 15:10:49 +08:00
ZEND_BEGIN_ARG_INFO ( arginfo_imagecrop , 0 )
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , rect )
ZEND_END_ARG_INFO ( )
2013-05-16 03:59:43 +08:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_imagecropauto , 0 , 0 , 1 )
2013-03-01 00:24:23 +08:00
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , mode )
2013-03-01 02:22:06 +08:00
ZEND_ARG_INFO ( 0 , threshold )
ZEND_ARG_INFO ( 0 , color )
2013-03-01 00:24:23 +08:00
ZEND_END_ARG_INFO ( )
2013-03-20 14:46:59 +08:00
2013-05-16 03:59:43 +08:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_imagescale , 0 , 0 , 2 )
2013-03-20 14:46:59 +08:00
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , new_width )
ZEND_ARG_INFO ( 0 , new_height )
ZEND_ARG_INFO ( 0 , mode )
ZEND_END_ARG_INFO ( )
2013-05-16 03:59:43 +08:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_imageaffine , 0 , 0 , 2 )
2013-03-20 14:46:59 +08:00
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , affine )
2013-05-16 03:59:43 +08:00
ZEND_ARG_INFO ( 0 , clip )
2013-03-20 14:46:59 +08:00
ZEND_END_ARG_INFO ( )
2013-05-16 03:59:43 +08:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_imageaffinematrixget , 0 , 0 , 1 )
ZEND_ARG_INFO ( 0 , type )
2013-03-20 18:01:37 +08:00
ZEND_ARG_INFO ( 0 , options )
ZEND_END_ARG_INFO ( )
2013-03-20 19:19:03 +08:00
ZEND_BEGIN_ARG_INFO ( arginfo_imageaffinematrixconcat , 0 )
ZEND_ARG_INFO ( 0 , m1 )
ZEND_ARG_INFO ( 0 , m2 )
ZEND_END_ARG_INFO ( )
2013-03-20 14:46:59 +08:00
ZEND_BEGIN_ARG_INFO ( arginfo_imagesetinterpolation , 0 )
ZEND_ARG_INFO ( 0 , im )
ZEND_ARG_INFO ( 0 , method )
ZEND_END_ARG_INFO ( )
2006-06-12 04:03:05 +08:00
/* }}} */
2001-06-05 21:12:10 +08:00
/* {{{ gd_functions[]
*/
2007-09-28 02:00:48 +08:00
const zend_function_entry gd_functions [ ] = {
2006-06-12 04:03:05 +08:00
PHP_FE ( gd_info , arginfo_gd_info )
PHP_FE ( imagearc , arginfo_imagearc )
PHP_FE ( imageellipse , arginfo_imageellipse )
PHP_FE ( imagechar , arginfo_imagechar )
PHP_FE ( imagecharup , arginfo_imagecharup )
PHP_FE ( imagecolorat , arginfo_imagecolorat )
PHP_FE ( imagecolorallocate , arginfo_imagecolorallocate )
PHP_FE ( imagepalettecopy , arginfo_imagepalettecopy )
PHP_FE ( imagecreatefromstring , arginfo_imagecreatefromstring )
PHP_FE ( imagecolorclosest , arginfo_imagecolorclosest )
PHP_FE ( imagecolorclosesthwb , arginfo_imagecolorclosesthwb )
PHP_FE ( imagecolordeallocate , arginfo_imagecolordeallocate )
PHP_FE ( imagecolorresolve , arginfo_imagecolorresolve )
PHP_FE ( imagecolorexact , arginfo_imagecolorexact )
PHP_FE ( imagecolorset , arginfo_imagecolorset )
PHP_FE ( imagecolortransparent , arginfo_imagecolortransparent )
PHP_FE ( imagecolorstotal , arginfo_imagecolorstotal )
PHP_FE ( imagecolorsforindex , arginfo_imagecolorsforindex )
PHP_FE ( imagecopy , arginfo_imagecopy )
PHP_FE ( imagecopymerge , arginfo_imagecopymerge )
PHP_FE ( imagecopymergegray , arginfo_imagecopymergegray )
PHP_FE ( imagecopyresized , arginfo_imagecopyresized )
PHP_FE ( imagecreate , arginfo_imagecreate )
PHP_FE ( imagecreatetruecolor , arginfo_imagecreatetruecolor )
PHP_FE ( imageistruecolor , arginfo_imageistruecolor )
PHP_FE ( imagetruecolortopalette , arginfo_imagetruecolortopalette )
2013-03-20 14:46:59 +08:00
PHP_FE ( imagepalettetotruecolor , arginfo_imagepalettetotruecolor )
2006-06-12 04:03:05 +08:00
PHP_FE ( imagesetthickness , arginfo_imagesetthickness )
PHP_FE ( imagefilledarc , arginfo_imagefilledarc )
PHP_FE ( imagefilledellipse , arginfo_imagefilledellipse )
PHP_FE ( imagealphablending , arginfo_imagealphablending )
PHP_FE ( imagesavealpha , arginfo_imagesavealpha )
PHP_FE ( imagecolorallocatealpha , arginfo_imagecolorallocatealpha )
PHP_FE ( imagecolorresolvealpha , arginfo_imagecolorresolvealpha )
PHP_FE ( imagecolorclosestalpha , arginfo_imagecolorclosestalpha )
PHP_FE ( imagecolorexactalpha , arginfo_imagecolorexactalpha )
PHP_FE ( imagecopyresampled , arginfo_imagecopyresampled )
2002-06-25 03:31:44 +08:00
2007-04-17 23:31:45 +08:00
# ifdef PHP_WIN32
PHP_FE ( imagegrabwindow , arginfo_imagegrabwindow )
PHP_FE ( imagegrabscreen , arginfo_imagegrabscreen )
# endif
2006-06-12 04:03:05 +08:00
PHP_FE ( imagerotate , arginfo_imagerotate )
2013-04-24 20:32:03 +08:00
PHP_FE ( imageflip , arginfo_imageflip )
2009-05-27 15:18:05 +08:00
# ifdef HAVE_GD_BUNDLED
2006-06-12 04:03:05 +08:00
PHP_FE ( imageantialias , arginfo_imageantialias )
2013-04-25 19:39:35 +08:00
# endif
2013-03-01 15:10:49 +08:00
PHP_FE ( imagecrop , arginfo_imagecrop )
2013-03-01 00:24:23 +08:00
PHP_FE ( imagecropauto , arginfo_imagecropauto )
2013-03-20 14:46:59 +08:00
PHP_FE ( imagescale , arginfo_imagescale )
PHP_FE ( imageaffine , arginfo_imageaffine )
2013-03-20 19:19:03 +08:00
PHP_FE ( imageaffinematrixconcat , arginfo_imageaffinematrixconcat )
PHP_FE ( imageaffinematrixget , arginfo_imageaffinematrixget )
2013-03-20 14:46:59 +08:00
PHP_FE ( imagesetinterpolation , arginfo_imagesetinterpolation )
2006-06-12 04:03:05 +08:00
PHP_FE ( imagesettile , arginfo_imagesettile )
PHP_FE ( imagesetbrush , arginfo_imagesetbrush )
PHP_FE ( imagesetstyle , arginfo_imagesetstyle )
2001-04-13 20:00:12 +08:00
2002-03-02 20:32:31 +08:00
# ifdef HAVE_GD_PNG
2006-06-12 04:03:05 +08:00
PHP_FE ( imagecreatefrompng , arginfo_imagecreatefrompng )
2002-03-02 20:32:31 +08:00
# endif
2010-10-05 06:30:35 +08:00
# ifdef HAVE_GD_WEBP
PHP_FE ( imagecreatefromwebp , arginfo_imagecreatefromwebp )
# endif
2006-06-12 04:03:05 +08:00
PHP_FE ( imagecreatefromgif , arginfo_imagecreatefromgif )
2002-03-02 20:32:31 +08:00
# ifdef HAVE_GD_JPG
2006-06-12 04:03:05 +08:00
PHP_FE ( imagecreatefromjpeg , arginfo_imagecreatefromjpeg )
2002-03-02 20:32:31 +08:00
# endif
2006-06-12 04:03:05 +08:00
PHP_FE ( imagecreatefromwbmp , arginfo_imagecreatefromwbmp )
PHP_FE ( imagecreatefromxbm , arginfo_imagecreatefromxbm )
2013-05-03 19:53:55 +08:00
# if defined(HAVE_GD_XPM)
2006-06-12 04:03:05 +08:00
PHP_FE ( imagecreatefromxpm , arginfo_imagecreatefromxpm )
2002-03-02 20:32:31 +08:00
# endif
2006-06-12 04:03:05 +08:00
PHP_FE ( imagecreatefromgd , arginfo_imagecreatefromgd )
PHP_FE ( imagecreatefromgd2 , arginfo_imagecreatefromgd2 )
PHP_FE ( imagecreatefromgd2part , arginfo_imagecreatefromgd2part )
2002-03-02 20:32:31 +08:00
# ifdef HAVE_GD_PNG
2006-06-12 04:03:05 +08:00
PHP_FE ( imagepng , arginfo_imagepng )
2002-03-02 20:32:31 +08:00
# endif
2010-10-05 06:30:35 +08:00
# ifdef HAVE_GD_WEBP
PHP_FE ( imagewebp , arginfo_imagewebp )
# endif
2006-06-12 04:03:05 +08:00
PHP_FE ( imagegif , arginfo_imagegif )
2002-03-02 20:32:31 +08:00
# ifdef HAVE_GD_JPG
2006-06-12 04:03:05 +08:00
PHP_FE ( imagejpeg , arginfo_imagejpeg )
2002-03-02 20:32:31 +08:00
# endif
2006-06-12 04:03:05 +08:00
PHP_FE ( imagewbmp , arginfo_imagewbmp )
PHP_FE ( imagegd , arginfo_imagegd )
PHP_FE ( imagegd2 , arginfo_imagegd2 )
PHP_FE ( imagedestroy , arginfo_imagedestroy )
PHP_FE ( imagegammacorrect , arginfo_imagegammacorrect )
PHP_FE ( imagefill , arginfo_imagefill )
PHP_FE ( imagefilledpolygon , arginfo_imagefilledpolygon )
PHP_FE ( imagefilledrectangle , arginfo_imagefilledrectangle )
PHP_FE ( imagefilltoborder , arginfo_imagefilltoborder )
PHP_FE ( imagefontwidth , arginfo_imagefontwidth )
PHP_FE ( imagefontheight , arginfo_imagefontheight )
PHP_FE ( imageinterlace , arginfo_imageinterlace )
PHP_FE ( imageline , arginfo_imageline )
PHP_FE ( imageloadfont , arginfo_imageloadfont )
PHP_FE ( imagepolygon , arginfo_imagepolygon )
PHP_FE ( imagerectangle , arginfo_imagerectangle )
PHP_FE ( imagesetpixel , arginfo_imagesetpixel )
PHP_FE ( imagestring , arginfo_imagestring )
PHP_FE ( imagestringup , arginfo_imagestringup )
PHP_FE ( imagesx , arginfo_imagesx )
PHP_FE ( imagesy , arginfo_imagesy )
PHP_FE ( imagedashedline , arginfo_imagedashedline )
2002-06-25 03:31:44 +08:00
2002-03-02 20:32:31 +08:00
# ifdef ENABLE_GD_TTF
2006-06-12 04:03:05 +08:00
PHP_FE ( imagettfbbox , arginfo_imagettfbbox )
PHP_FE ( imagettftext , arginfo_imagettftext )
2013-05-03 19:53:55 +08:00
# if HAVE_GD_FREETYPE && HAVE_LIBFREETYPE
2006-06-12 04:03:05 +08:00
PHP_FE ( imageftbbox , arginfo_imageftbbox )
PHP_FE ( imagefttext , arginfo_imagefttext )
2002-03-02 20:32:31 +08:00
# endif
2002-06-25 03:31:44 +08:00
# endif
2006-06-12 04:03:05 +08:00
PHP_FE ( imagetypes , arginfo_imagetypes )
2003-02-27 07:22:09 +08:00
2013-05-03 19:53:55 +08:00
# if defined(HAVE_GD_JPG)
2006-06-12 04:03:05 +08:00
PHP_FE ( jpeg2wbmp , arginfo_jpeg2wbmp )
2002-03-02 20:32:31 +08:00
# endif
2013-05-03 19:53:55 +08:00
# if defined(HAVE_GD_PNG)
2006-06-12 04:03:05 +08:00
PHP_FE ( png2wbmp , arginfo_png2wbmp )
2002-03-02 20:32:31 +08:00
# endif
2006-06-12 04:03:05 +08:00
PHP_FE ( image2wbmp , arginfo_image2wbmp )
PHP_FE ( imagelayereffect , arginfo_imagelayereffect )
PHP_FE ( imagexbm , arginfo_imagexbm )
2009-05-27 16:18:24 +08:00
PHP_FE ( imagecolormatch , arginfo_imagecolormatch )
2002-11-14 04:02:58 +08:00
/* gd filters */
2006-06-12 04:03:05 +08:00
PHP_FE ( imagefilter , arginfo_imagefilter )
PHP_FE ( imageconvolution , arginfo_imageconvolution )
2002-11-14 04:02:58 +08:00
2011-07-25 19:35:02 +08:00
PHP_FE_END
1999-04-16 20:15:38 +08:00
} ;
2001-06-05 21:12:10 +08:00
/* }}} */
1999-04-16 20:15:38 +08:00
1999-12-18 04:55:31 +08:00
zend_module_entry gd_module_entry = {
2001-10-13 21:12:30 +08:00
STANDARD_MODULE_HEADER ,
2001-10-12 07:33:59 +08:00
" gd " ,
2001-10-13 21:12:30 +08:00
gd_functions ,
PHP_MINIT ( gd ) ,
2007-04-04 09:58:24 +08:00
NULL ,
2001-10-13 21:12:30 +08:00
NULL ,
2013-05-03 19:53:55 +08:00
# if HAVE_GD_FREETYPE && HAVE_LIBFREETYPE
2002-11-24 06:11:59 +08:00
PHP_RSHUTDOWN ( gd ) ,
2003-03-31 16:49:19 +08:00
# else
NULL ,
# endif
2001-10-13 21:12:30 +08:00
PHP_MINFO ( gd ) ,
2015-03-24 03:33:54 +08:00
PHP_GD_VERSION ,
2001-10-13 21:12:30 +08:00
STANDARD_MODULE_PROPERTIES
1999-04-16 20:15:38 +08:00
} ;
2000-05-23 17:33:51 +08:00
# ifdef COMPILE_DL_GD
2000-05-02 08:30:36 +08:00
ZEND_GET_MODULE ( gd )
1999-04-16 20:15:38 +08:00
# endif
2006-02-05 23:53:58 +08:00
/* {{{ PHP_INI_BEGIN */
PHP_INI_BEGIN ( )
PHP_INI_ENTRY ( " gd.jpeg_ignore_warning " , " 0 " , PHP_INI_ALL , NULL )
PHP_INI_END ( )
/* }}} */
2009-05-26 21:57:07 +08:00
2001-06-05 21:12:10 +08:00
/* {{{ php_free_gd_image
*/
2014-12-14 06:06:14 +08:00
static void php_free_gd_image ( zend_resource * rsrc )
2000-10-21 02:25:16 +08:00
{
2003-03-20 09:12:57 +08:00
gdImageDestroy ( ( gdImagePtr ) rsrc - > ptr ) ;
2000-10-21 02:25:16 +08:00
}
2001-06-05 21:12:10 +08:00
/* }}} */
1999-04-16 20:15:38 +08:00
2001-06-05 21:12:10 +08:00
/* {{{ php_free_gd_font
*/
2014-12-14 06:06:14 +08:00
static void php_free_gd_font ( zend_resource * rsrc )
1999-12-18 05:50:07 +08:00
{
2003-03-20 09:12:57 +08:00
gdFontPtr fp = ( gdFontPtr ) rsrc - > ptr ;
2001-07-31 13:44:11 +08:00
1999-12-18 05:50:07 +08:00
if ( fp - > data ) {
efree ( fp - > data ) ;
}
2003-03-20 09:12:57 +08:00
1999-12-18 05:50:07 +08:00
efree ( fp ) ;
}
2001-06-05 21:12:10 +08:00
/* }}} */
1999-12-18 05:50:07 +08:00
2013-05-03 19:53:55 +08:00
# ifndef HAVE_GD_BUNDLED
2013-04-25 19:39:35 +08:00
/* {{{ php_gd_error_method
*/
void php_gd_error_method ( int type , const char * format , va_list args )
{
2014-12-14 06:06:14 +08:00
php_verror ( NULL , " " , type , format , args ) ;
2013-04-25 19:39:35 +08:00
}
/* }}} */
# endif
2001-06-05 21:12:10 +08:00
/* {{{ PHP_MINIT_FUNCTION
*/
1999-07-28 03:44:46 +08:00
PHP_MINIT_FUNCTION ( gd )
1999-04-16 20:15:38 +08:00
{
2000-11-29 23:25:42 +08: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 ) ;
2007-04-06 23:38:35 +08:00
2013-05-03 19:53:55 +08:00
# if HAVE_GD_BUNDLED && HAVE_LIBFREETYPE
2007-04-04 08:47:55 +08:00
gdFontCacheMutexSetup ( ) ;
# endif
2013-05-03 19:53:55 +08:00
# ifndef HAVE_GD_BUNDLED
2013-04-25 19:39:35 +08:00
gdSetErrorMethod ( php_gd_error_method ) ;
# endif
2006-02-05 23:53:58 +08:00
REGISTER_INI_ENTRIES ( ) ;
2009-05-26 21:57:07 +08:00
2014-08-26 01:24:55 +08: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 ) ;
REGISTER_LONG_CONSTANT ( " IMG_XPM " , 16 , CONST_CS | CONST_PERSISTENT ) ;
2013-05-03 19:53:55 +08:00
2001-04-13 20:00:12 +08:00
/* special colours for gd */
2014-08-26 01:24:55 +08:00
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 ) ;
2013-05-03 19:53:55 +08:00
2001-04-13 20:00:12 +08:00
/* for imagefilledarc */
2014-08-26 01:24:55 +08:00
REGISTER_LONG_CONSTANT ( " IMG_ARC_ROUNDED " , gdArc , CONST_CS | CONST_PERSISTENT ) ;
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 ) ;
2009-05-26 21:57:07 +08:00
2013-05-03 19:53:55 +08:00
/* GD2 image format types */
2014-08-26 01:24:55 +08:00
REGISTER_LONG_CONSTANT ( " IMG_GD2_RAW " , GD2_FMT_RAW , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_GD2_COMPRESSED " , GD2_FMT_COMPRESSED , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_FLIP_HORIZONTAL " , GD_FLIP_HORINZONTAL , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_FLIP_VERTICAL " , GD_FLIP_VERTICAL , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_FLIP_BOTH " , GD_FLIP_BOTH , CONST_CS | CONST_PERSISTENT ) ;
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 ) ;
REGISTER_LONG_CONSTANT ( " IMG_CROP_DEFAULT " , GD_CROP_DEFAULT , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_CROP_TRANSPARENT " , GD_CROP_TRANSPARENT , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_CROP_BLACK " , GD_CROP_BLACK , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_CROP_WHITE " , GD_CROP_WHITE , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_CROP_SIDES " , GD_CROP_SIDES , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_CROP_THRESHOLD " , GD_CROP_THRESHOLD , CONST_CS | CONST_PERSISTENT ) ;
2013-03-20 14:46:59 +08:00
2015-01-03 17:22:58 +08:00
2014-08-26 01:24:55 +08:00
REGISTER_LONG_CONSTANT ( " IMG_BELL " , GD_BELL , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_BESSEL " , GD_BESSEL , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_BILINEAR_FIXED " , GD_BILINEAR_FIXED , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_BICUBIC " , GD_BICUBIC , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_BICUBIC_FIXED " , GD_BICUBIC_FIXED , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_BLACKMAN " , GD_BLACKMAN , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_BOX " , GD_BOX , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_BSPLINE " , GD_BSPLINE , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_CATMULLROM " , GD_CATMULLROM , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_GAUSSIAN " , GD_GAUSSIAN , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_GENERALIZED_CUBIC " , GD_GENERALIZED_CUBIC , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_HERMITE " , GD_HERMITE , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_HAMMING " , GD_HAMMING , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_HANNING " , GD_HANNING , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_MITCHELL " , GD_MITCHELL , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_POWER " , GD_POWER , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_QUADRATIC " , GD_QUADRATIC , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_SINC " , GD_SINC , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_NEAREST_NEIGHBOUR " , GD_NEAREST_NEIGHBOUR , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_WEIGHTED4 " , GD_WEIGHTED4 , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_TRIANGLE " , GD_TRIANGLE , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_AFFINE_TRANSLATE " , GD_AFFINE_TRANSLATE , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_AFFINE_SCALE " , GD_AFFINE_SCALE , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_AFFINE_ROTATE " , GD_AFFINE_ROTATE , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_AFFINE_SHEAR_HORIZONTAL " , GD_AFFINE_SHEAR_HORIZONTAL , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " IMG_AFFINE_SHEAR_VERTICAL " , GD_AFFINE_SHEAR_VERTICAL , CONST_CS | CONST_PERSISTENT ) ;
2013-03-20 19:19:03 +08:00
2013-05-03 19:53:55 +08:00
# if defined(HAVE_GD_BUNDLED)
2014-08-26 01:24:55 +08:00
REGISTER_LONG_CONSTANT ( " GD_BUNDLED " , 1 , CONST_CS | CONST_PERSISTENT ) ;
2009-05-26 21:35:59 +08:00
# else
2014-08-26 01:24:55 +08:00
REGISTER_LONG_CONSTANT ( " GD_BUNDLED " , 0 , CONST_CS | CONST_PERSISTENT ) ;
2009-05-26 21:35:59 +08:00
# endif
2007-06-04 01:46:18 +08:00
2003-03-20 09:12:57 +08:00
/* Section Filters */
2014-08-26 01:24:55 +08: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 ) ;
REGISTER_LONG_CONSTANT ( " IMG_FILTER_PIXELATE " , IMAGE_FILTER_PIXELATE , CONST_CS | CONST_PERSISTENT ) ;
2003-03-20 09:12:57 +08:00
/* End Section Filters */
2006-01-27 21:36:30 +08:00
2007-06-04 01:46:18 +08:00
# ifdef GD_VERSION_STRING
REGISTER_STRING_CONSTANT ( " GD_VERSION " , GD_VERSION_STRING , CONST_CS | CONST_PERSISTENT ) ;
# endif
# if defined(GD_MAJOR_VERSION) && defined(GD_MINOR_VERSION) && defined(GD_RELEASE_VERSION) && defined(GD_EXTRA_VERSION)
2014-08-26 01:24:55 +08:00
REGISTER_LONG_CONSTANT ( " GD_MAJOR_VERSION " , GD_MAJOR_VERSION , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " GD_MINOR_VERSION " , GD_MINOR_VERSION , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " GD_RELEASE_VERSION " , GD_RELEASE_VERSION , CONST_CS | CONST_PERSISTENT ) ;
2007-06-04 01:46:18 +08:00
REGISTER_STRING_CONSTANT ( " GD_EXTRA_VERSION " , GD_EXTRA_VERSION , CONST_CS | CONST_PERSISTENT ) ;
# endif
2006-01-27 21:36:30 +08:00
# ifdef HAVE_GD_PNG
2009-05-26 21:57:07 +08:00
/*
* 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 . . .
*/
2014-08-26 01:24:55 +08:00
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 ) ;
2006-01-27 21:36:30 +08:00
# endif
2009-05-26 21:57:07 +08:00
1999-04-16 20:15:38 +08:00
return SUCCESS ;
}
2001-06-05 21:12:10 +08:00
/* }}} */
1999-04-16 20:15:38 +08:00
2002-11-24 06:11:59 +08:00
/* {{{ PHP_RSHUTDOWN_FUNCTION
*/
2013-05-03 19:53:55 +08:00
# if HAVE_GD_FREETYPE && HAVE_LIBFREETYPE
2002-11-24 06:11:59 +08:00
PHP_RSHUTDOWN_FUNCTION ( gd )
{
2003-12-26 06:12:12 +08:00
gdFontCacheShutdown ( ) ;
2002-11-24 06:11:59 +08:00
return SUCCESS ;
}
2003-03-31 16:49:19 +08:00
# endif
2002-11-24 06:11:59 +08:00
/* }}} */
2013-04-25 19:39:35 +08:00
# if defined(HAVE_GD_BUNDLED)
2013-04-11 02:12:25 +08:00
# define PHP_GD_VERSION_STRING "bundled (2.1.0 compatible)"
2003-04-06 04:43:53 +08:00
# else
2013-05-03 19:53:55 +08:00
# define PHP_GD_VERSION_STRING GD_VERSION_STRING
2003-04-06 04:43:53 +08:00
# endif
2001-06-05 21:12:10 +08:00
/* {{{ PHP_MINFO_FUNCTION
*/
1999-07-28 03:44:46 +08:00
PHP_MINFO_FUNCTION ( gd )
1999-05-09 21:57:09 +08:00
{
2000-04-06 06:30:19 +08:00
php_info_print_table_start ( ) ;
php_info_print_table_row ( 2 , " GD Support " , " enabled " ) ;
1999-04-16 20:15:38 +08:00
/* need to use a PHPAPI function here because it is external module in windows */
2000-04-06 06:30:19 +08:00
2014-12-26 15:33:21 +08:00
# if defined(HAVE_GD_BUNDLED)
2003-04-06 04:43:53 +08:00
php_info_print_table_row ( 2 , " GD Version " , PHP_GD_VERSION_STRING ) ;
2014-12-26 15:33:21 +08:00
# else
php_info_print_table_row ( 2 , " GD headers Version " , PHP_GD_VERSION_STRING ) ;
# if defined(HAVE_GD_LIBVERSION)
php_info_print_table_row ( 2 , " GD library Version " , gdVersionString ( ) ) ;
# endif
# endif
1999-11-30 07:21:52 +08:00
1999-07-23 23:18:37 +08:00
# ifdef ENABLE_GD_TTF
2000-04-06 06:30:19 +08:00
php_info_print_table_row ( 2 , " FreeType Support " , " enabled " ) ;
1999-11-30 07:21:52 +08:00
# if HAVE_LIBFREETYPE
2000-04-06 06:30:19 +08:00
php_info_print_table_row ( 2 , " FreeType Linkage " , " with freetype " ) ;
2003-09-10 03:08:30 +08:00
{
char tmp [ 256 ] ;
2009-05-26 21:57:07 +08:00
2003-09-15 15:27:18 +08:00
# ifdef FREETYPE_PATCH
2003-09-10 03:08:30 +08:00
snprintf ( tmp , sizeof ( tmp ) , " %d.%d.%d " , FREETYPE_MAJOR , FREETYPE_MINOR , FREETYPE_PATCH ) ;
2007-05-07 22:54:36 +08:00
# elif defined(FREETYPE_MAJOR)
2003-09-15 15:27:18 +08:00
snprintf ( tmp , sizeof ( tmp ) , " %d.%d " , FREETYPE_MAJOR , FREETYPE_MINOR ) ;
2007-05-07 22:54:36 +08:00
# else
snprintf ( tmp , sizeof ( tmp ) , " 1.x " ) ;
2003-09-15 15:27:18 +08:00
# endif
2003-09-10 03:08:30 +08:00
php_info_print_table_row ( 2 , " FreeType Version " , tmp ) ;
}
1999-11-30 07:21:52 +08:00
# else
2000-04-06 06:30:19 +08:00
php_info_print_table_row ( 2 , " FreeType Linkage " , " with unknown library " ) ;
1999-11-30 07:21:52 +08:00
# endif
# endif
2001-08-25 04:05:58 +08:00
php_info_print_table_row ( 2 , " GIF Read Support " , " enabled " ) ;
php_info_print_table_row ( 2 , " GIF Create Support " , " enabled " ) ;
2013-05-03 19:53:55 +08:00
2000-04-08 02:50:08 +08:00
# ifdef HAVE_GD_JPG
2008-11-05 04:25:45 +08:00
{
2009-03-24 20:48:52 +08:00
php_info_print_table_row ( 2 , " JPEG Support " , " enabled " ) ;
2013-04-25 19:39:35 +08:00
php_info_print_table_row ( 2 , " libJPEG Version " , gdJpegGetVersionString ( ) ) ;
2008-11-05 04:25:45 +08:00
}
2000-07-15 05:51:31 +08:00
# endif
2008-11-06 18:14:37 +08:00
2000-11-01 12:38:28 +08:00
# ifdef HAVE_GD_PNG
php_info_print_table_row ( 2 , " PNG Support " , " enabled " ) ;
2008-11-06 18:14:37 +08:00
php_info_print_table_row ( 2 , " libPNG Version " , gdPngGetVersionString ( ) ) ;
2000-11-01 12:38:28 +08:00
# endif
2000-07-15 05:51:31 +08:00
php_info_print_table_row ( 2 , " WBMP Support " , " enabled " ) ;
2013-05-03 19:53:55 +08:00
# if defined(HAVE_GD_XPM)
2003-02-02 07:23:59 +08:00
php_info_print_table_row ( 2 , " XPM Support " , " enabled " ) ;
2012-10-05 00:20:02 +08:00
{
char tmp [ 12 ] ;
snprintf ( tmp , sizeof ( tmp ) , " %d " , XpmLibraryVersion ( ) ) ;
php_info_print_table_row ( 2 , " libXpm Version " , tmp ) ;
}
2003-02-02 07:23:59 +08:00
# endif
2000-11-01 12:38:28 +08:00
php_info_print_table_row ( 2 , " XBM Support " , " enabled " ) ;
2013-05-03 19:53:55 +08:00
# if defined(USE_GD_JISX0208)
2003-04-19 15:44:16 +08:00
php_info_print_table_row ( 2 , " JIS-mapped Japanese Font Support " , " enabled " ) ;
2013-03-28 00:38:57 +08:00
# endif
# ifdef HAVE_GD_WEBP
php_info_print_table_row ( 2 , " WebP Support " , " enabled " ) ;
1999-04-16 20:15:38 +08:00
# endif
2000-04-06 06:30:19 +08:00
php_info_print_table_end ( ) ;
2008-12-12 21:07:28 +08:00
DISPLAY_INI_ENTRIES ( ) ;
1999-04-16 20:15:38 +08:00
}
2001-06-05 21:12:10 +08:00
/* }}} */
1999-04-16 20:15:38 +08:00
2002-11-12 19:49:11 +08:00
/* {{{ proto array gd_info()
*/
PHP_FUNCTION ( gd_info )
{
2008-03-11 06:15:36 +08:00
if ( zend_parse_parameters_none ( ) = = FAILURE ) {
2002-11-12 19:49:11 +08:00
RETURN_FALSE ;
}
2003-01-18 05:37:56 +08:00
array_init ( return_value ) ;
2014-04-15 19:40:40 +08:00
add_assoc_string ( return_value , " GD Version " , PHP_GD_VERSION_STRING ) ;
2002-11-12 19:49:11 +08:00
# ifdef ENABLE_GD_TTF
add_assoc_bool ( return_value , " FreeType Support " , 1 ) ;
# if HAVE_LIBFREETYPE
2014-04-15 19:40:40 +08:00
add_assoc_string ( return_value , " FreeType Linkage " , " with freetype " ) ;
2002-11-12 19:49:11 +08:00
# else
2014-04-15 19:40:40 +08:00
add_assoc_string ( return_value , " FreeType Linkage " , " with unknown library " ) ;
2002-11-12 19:49:11 +08:00
# endif
# else
add_assoc_bool ( return_value , " FreeType Support " , 0 ) ;
# endif
add_assoc_bool ( return_value , " GIF Read Support " , 1 ) ;
add_assoc_bool ( return_value , " GIF Create Support " , 1 ) ;
# ifdef HAVE_GD_JPG
2009-03-26 08:43:45 +08:00
add_assoc_bool ( return_value , " JPEG Support " , 1 ) ;
2002-11-12 19:49:11 +08:00
# else
2009-03-26 08:43:45 +08:00
add_assoc_bool ( return_value , " JPEG Support " , 0 ) ;
2002-11-12 19:49:11 +08:00
# 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 ) ;
2013-05-03 19:53:55 +08:00
# if defined(HAVE_GD_XPM)
2003-02-02 07:23:59 +08:00
add_assoc_bool ( return_value , " XPM Support " , 1 ) ;
# else
add_assoc_bool ( return_value , " XPM Support " , 0 ) ;
# endif
2002-11-12 19:49:11 +08:00
add_assoc_bool ( return_value , " XBM Support " , 1 ) ;
2015-07-11 23:49:13 +08:00
# ifdef HAVE_GD_WEBP
add_assoc_bool ( return_value , " WebP Support " , 1 ) ;
# else
add_assoc_bool ( return_value , " WebP Support " , 0 ) ;
# endif
2013-05-03 19:53:55 +08:00
# if defined(USE_GD_JISX0208)
2003-04-19 15:44:16 +08:00
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 19:49:11 +08:00
}
/* }}} */
1999-08-06 00:25:10 +08:00
/* Need this for cpdf. See also comment in file.c php3i_get_le_fp() */
2001-02-21 02:00:44 +08:00
PHP_GD_API int phpi_get_le_gd ( void )
1999-12-18 05:50:07 +08:00
{
2000-11-29 23:25:42 +08:00
return le_gd ;
1999-08-06 00:25:10 +08:00
}
2006-06-12 04:03:05 +08:00
/* }}} */
1999-08-06 00:25:10 +08:00
2001-03-12 21:57:53 +08:00
# define FLIPWORD(a) (((a & 0xff000000) >> 24) | ((a & 0x00ff0000) >> 8) | ((a & 0x0000ff00) << 8) | ((a & 0x000000ff) << 24))
1999-04-16 20:15:38 +08:00
/* {{{ proto int imageloadfont(string filename)
1999-11-25 06:04:49 +08:00
Load a new font */
2003-02-27 07:22:09 +08:00
PHP_FUNCTION ( imageloadfont )
2000-11-23 22:56:09 +08:00
{
2014-05-12 15:53:35 +08:00
zval * ind ;
2015-01-21 15:40:33 +08:00
zend_string * file ;
2014-08-28 01:25:28 +08:00
int hdr_size = sizeof ( gdFont ) - sizeof ( char * ) ;
2014-05-12 15:53:35 +08:00
int body_size , n = 0 , b , i , body_size_check ;
1999-04-16 20:15:38 +08:00
gdFontPtr font ;
2002-03-16 09:28:57 +08:00
php_stream * stream ;
1999-04-16 20:15:38 +08:00
2015-01-21 15:40:33 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " P " , & file ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
1999-04-16 20:15:38 +08:00
}
2015-06-30 09:05:24 +08:00
stream = php_stream_open_wrapper ( ZSTR_VAL ( file ) , " rb " , IGNORE_PATH | IGNORE_URL_WIN | REPORT_ERRORS , NULL ) ;
2002-03-16 05:03:08 +08:00
if ( stream = = NULL ) {
1999-04-16 20:15:38 +08: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-27 07:22:09 +08:00
* in each character , for a total of
1999-04-16 20:15:38 +08:00
* ( nchars * width * height ) bytes .
*/
2003-03-20 09:12:57 +08:00
font = ( gdFontPtr ) emalloc ( sizeof ( gdFont ) ) ;
1999-04-16 20:15:38 +08:00
b = 0 ;
2003-03-20 09:12:57 +08:00
while ( b < hdr_size & & ( n = php_stream_read ( stream , ( char * ) & font [ b ] , hdr_size - b ) ) ) {
1999-04-16 20:15:38 +08:00
b + = n ;
2003-03-20 09:12:57 +08:00
}
1999-04-16 20:15:38 +08:00
if ( ! n ) {
efree ( font ) ;
2002-03-16 05:03:08 +08:00
if ( php_stream_eof ( stream ) ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " End of file while reading header " ) ;
1999-04-16 20:15:38 +08:00
} else {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Error while reading header " ) ;
1999-04-16 20:15:38 +08:00
}
2002-08-24 01:45:46 +08:00
php_stream_close ( stream ) ;
1999-04-16 20:15:38 +08:00
RETURN_FALSE ;
}
2002-03-16 05:03:08 +08: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 09:12:57 +08:00
1999-04-16 20:15:38 +08:00
body_size = font - > w * font - > h * font - > nchars ;
2001-03-12 21:57:53 +08: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 09:12:57 +08:00
2013-05-06 16:00:45 +08:00
if ( overflow2 ( font - > nchars , font - > h ) | | overflow2 ( font - > nchars * font - > h , font - > w ) ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Error reading font, invalid font header " ) ;
2008-07-18 07:13:09 +08:00
efree ( font ) ;
php_stream_close ( stream ) ;
RETURN_FALSE ;
}
2001-03-12 21:57:53 +08:00
if ( body_size ! = body_size_check ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Error reading font " ) ;
2001-03-12 21:57:53 +08:00
efree ( font ) ;
2004-05-21 07:37:59 +08:00
php_stream_close ( stream ) ;
2001-03-12 21:57:53 +08:00
RETURN_FALSE ;
}
1999-04-16 20:15:38 +08:00
font - > data = emalloc ( body_size ) ;
b = 0 ;
2003-03-20 09:12:57 +08:00
while ( b < body_size & & ( n = php_stream_read ( stream , & font - > data [ b ] , body_size - b ) ) ) {
1999-04-16 20:15:38 +08:00
b + = n ;
2003-03-20 09:12:57 +08:00
}
1999-04-16 20:15:38 +08:00
if ( ! n ) {
efree ( font - > data ) ;
efree ( font ) ;
2002-03-16 05:03:08 +08:00
if ( php_stream_eof ( stream ) ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " End of file while reading body " ) ;
1999-04-16 20:15:38 +08:00
} else {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Error while reading body " ) ;
1999-04-16 20:15:38 +08:00
}
2002-08-24 01:53:03 +08:00
php_stream_close ( stream ) ;
1999-04-16 20:15:38 +08:00
RETURN_FALSE ;
}
2002-03-16 05:03:08 +08:00
php_stream_close ( stream ) ;
1999-04-16 20:15:38 +08:00
2014-12-14 06:06:14 +08:00
ind = zend_list_insert ( font , le_gd_font ) ;
2014-05-12 15:53:35 +08:00
1999-04-16 20:15:38 +08: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.
*/
2014-08-26 01:24:55 +08:00
RETURN_LONG ( Z_RES_HANDLE_P ( ind ) + 5 ) ;
1999-04-16 20:15:38 +08:00
}
/* }}} */
2003-06-15 23:29:46 +08:00
/* {{{ proto bool imagesetstyle(resource im, array styles)
2001-06-11 22:39:13 +08:00
Set the line drawing styles for use with imageline and IMG_COLOR_STYLED . */
2001-04-13 20:00:12 +08:00
PHP_FUNCTION ( imagesetstyle )
{
2014-05-12 15:53:35 +08:00
zval * IM , * styles , * item ;
2001-04-13 20:00:12 +08:00
gdImagePtr im ;
2014-05-12 15:53:35 +08:00
int * stylearr ;
int index = 0 ;
2001-04-13 20:00:12 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " ra " , & IM , & styles ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
2001-04-13 20:00:12 +08:00
}
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2001-04-13 20:00:12 +08:00
/* copy the style values in the stylearr */
2015-09-25 03:39:59 +08:00
stylearr = safe_emalloc ( sizeof ( int ) , zend_hash_num_elements ( Z_ARRVAL_P ( styles ) ) , 0 ) ;
2001-04-13 20:00:12 +08:00
2015-09-25 03:39:59 +08:00
ZEND_HASH_FOREACH_VAL ( Z_ARRVAL_P ( styles ) , item ) {
2014-10-10 18:23:33 +08:00
stylearr [ index + + ] = zval_get_long ( item ) ;
2014-05-12 15:53:35 +08:00
} ZEND_HASH_FOREACH_END ( ) ;
2003-03-20 09:12:57 +08:00
2001-04-13 20:00:12 +08:00
gdImageSetStyle ( im , stylearr , index ) ;
efree ( stylearr ) ;
RETURN_TRUE ;
}
/* }}} */
2003-06-15 23:29:46 +08:00
/* {{{ proto resource imagecreatetruecolor(int x_size, int y_size)
2001-04-13 20:00:12 +08:00
Create a new true color image */
PHP_FUNCTION ( imagecreatetruecolor )
{
2014-08-26 01:24:55 +08:00
zend_long x_size , y_size ;
2001-04-13 20:00:12 +08:00
gdImagePtr im ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " ll " , & x_size , & y_size ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
2001-04-13 20:00:12 +08:00
}
2008-06-22 06:07:53 +08:00
if ( x_size < = 0 | | y_size < = 0 | | x_size > = INT_MAX | | y_size > = INT_MAX ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Invalid image dimensions " ) ;
2003-04-04 03:18:57 +08:00
RETURN_FALSE ;
}
2003-12-29 05:08:46 +08:00
2008-06-22 06:07:53 +08:00
im = gdImageCreateTrueColor ( x_size , y_size ) ;
2001-04-13 20:00:12 +08:00
2007-06-06 17:45:43 +08:00
if ( ! im ) {
RETURN_FALSE ;
}
2015-02-02 13:23:16 +08:00
RETURN_RES ( zend_register_resource ( im , le_gd ) ) ;
2001-04-13 20:00:12 +08:00
}
/* }}} */
2003-06-15 23:29:46 +08:00
/* {{{ proto bool imageistruecolor(resource im)
2002-12-11 03:45:58 +08:00
return true if the image uses truecolor */
PHP_FUNCTION ( imageistruecolor )
{
2008-06-22 06:07:53 +08:00
zval * IM ;
2002-12-11 03:45:58 +08:00
gdImagePtr im ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " r " , & IM ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
2002-12-11 03:45:58 +08:00
}
2003-02-27 07:22:09 +08:00
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2002-12-11 03:45:58 +08:00
RETURN_BOOL ( im - > trueColor ) ;
}
/* }}} */
2001-12-07 02:37:05 +08:00
/* {{{ proto void imagetruecolortopalette(resource im, bool ditherFlag, int colorsWanted)
2001-10-09 02:39:42 +08:00
Convert a true colour image to a palette based image with a number of colours , optionally using dithering . */
2001-04-13 20:00:12 +08:00
PHP_FUNCTION ( imagetruecolortopalette )
{
2008-06-22 06:07:53 +08:00
zval * IM ;
zend_bool dither ;
2014-08-26 01:24:55 +08:00
zend_long ncolors ;
2001-04-13 20:00:12 +08:00
gdImagePtr im ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rbl " , & IM , & dither , & ncolors ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
2001-04-13 20:00:12 +08:00
}
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2003-02-27 07:22:09 +08:00
2008-06-22 06:07:53 +08:00
if ( ncolors < = 0 ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Number of colors has to be greater than zero " ) ;
2005-10-27 05:38:20 +08:00
RETURN_FALSE ;
}
2008-06-22 06:07:53 +08:00
gdImageTrueColorToPalette ( im , dither , ncolors ) ;
2001-04-13 20:00:12 +08:00
RETURN_TRUE ;
}
/* }}} */
2013-03-20 14:46:59 +08:00
/* {{{ proto void imagetruecolortopalette(resource im, bool ditherFlag, int colorsWanted)
Convert a true colour image to a palette based image with a number of colours , optionally using dithering . */
PHP_FUNCTION ( imagepalettetotruecolor )
{
zval * IM ;
gdImagePtr im ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " r " , & IM ) = = FAILURE ) {
2013-03-20 14:46:59 +08:00
return ;
}
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2013-03-20 14:46:59 +08:00
if ( gdImagePaletteToTrueColor ( im ) = = 0 ) {
2013-03-27 12:13:30 +08:00
RETURN_FALSE ;
2013-03-20 14:46:59 +08:00
}
RETURN_TRUE ;
}
/* }}} */
2003-06-15 23:29:46 +08:00
/* {{{ proto bool imagecolormatch(resource im1, resource im2)
2002-09-13 05:42:33 +08:00
Makes the colors of the palette version of an image more closely match the true color version */
2002-08-22 15:28:26 +08:00
PHP_FUNCTION ( imagecolormatch )
{
2008-06-22 06:07:53 +08:00
zval * IM1 , * IM2 ;
2002-08-22 15:28:26 +08:00
gdImagePtr im1 , im2 ;
int result ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rr " , & IM1 , & IM2 ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
2002-08-22 15:28:26 +08:00
}
2015-02-02 13:23:16 +08:00
if ( ( im1 = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM1 ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
if ( ( im2 = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM2 ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2002-08-22 15:28:26 +08:00
result = gdImageColorMatch ( im1 , im2 ) ;
2003-03-20 09:12:57 +08:00
switch ( result ) {
case - 1 :
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Image1 must be TrueColor " ) ;
2003-03-20 09:12:57 +08:00
RETURN_FALSE ;
break ;
case - 2 :
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Image2 must be Palette " ) ;
2003-03-20 09:12:57 +08:00
RETURN_FALSE ;
break ;
case - 3 :
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Image1 and Image2 must be the same size " ) ;
2003-03-20 09:12:57 +08:00
RETURN_FALSE ;
break ;
2005-12-26 03:39:53 +08:00
case - 4 :
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Image2 must have at least one color " ) ;
2005-12-26 03:39:53 +08:00
RETURN_FALSE ;
break ;
2002-08-22 15:28:26 +08:00
}
RETURN_TRUE ;
}
/* }}} */
2003-06-15 23:29:46 +08:00
/* {{{ proto bool imagesetthickness(resource im, int thickness)
2001-10-09 02:39:42 +08:00
Set line thickness for drawing lines , ellipses , rectangles , polygons etc . */
2001-04-13 20:00:12 +08:00
PHP_FUNCTION ( imagesetthickness )
{
2008-06-22 06:07:53 +08:00
zval * IM ;
2014-08-26 01:24:55 +08:00
zend_long thick ;
2001-04-13 20:00:12 +08:00
gdImagePtr im ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rl " , & IM , & thick ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
2001-04-13 20:00:12 +08:00
}
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2003-02-27 07:22:09 +08:00
2008-06-22 06:07:53 +08:00
gdImageSetThickness ( im , thick ) ;
2001-04-13 20:00:12 +08:00
RETURN_TRUE ;
}
/* }}} */
2003-06-15 23:29:46 +08:00
/* {{{ proto bool imagefilledellipse(resource im, int cx, int cy, int w, int h, int color)
2001-10-09 02:39:42 +08:00
Draw an ellipse */
2001-04-13 20:00:12 +08:00
PHP_FUNCTION ( imagefilledellipse )
{
2008-06-22 06:07:53 +08:00
zval * IM ;
2014-08-26 01:24:55 +08:00
zend_long cx , cy , w , h , color ;
2001-04-13 20:00:12 +08:00
gdImagePtr im ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rlllll " , & IM , & cx , & cy , & w , & h , & color ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
2001-04-13 20:00:12 +08:00
}
2003-02-27 07:22:09 +08:00
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2001-04-13 20:00:12 +08:00
2008-06-22 06:07:53 +08:00
gdImageFilledEllipse ( im , cx , cy , w , h , color ) ;
2001-04-13 20:00:12 +08:00
RETURN_TRUE ;
}
/* }}} */
2003-06-15 23:29:46 +08: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 20:00:12 +08:00
Draw a filled partial ellipse */
PHP_FUNCTION ( imagefilledarc )
{
2008-06-22 06:07:53 +08:00
zval * IM ;
2014-08-26 01:24:55 +08:00
zend_long cx , cy , w , h , ST , E , col , style ;
2001-04-13 20:00:12 +08:00
gdImagePtr im ;
2001-08-12 00:39:07 +08:00
int e , st ;
2015-01-03 17:22:58 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rllllllll " , & IM , & cx , & cy , & w , & h , & ST , & E , & col , & style ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
2001-04-13 20:00:12 +08:00
}
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2001-04-13 20:00:12 +08:00
2008-06-22 06:07:53 +08:00
e = E ;
2003-03-20 09:12:57 +08:00
if ( e < 0 ) {
e % = 360 ;
}
2001-04-13 20:00:12 +08:00
2008-06-22 06:07:53 +08:00
st = ST ;
2003-03-20 09:12:57 +08:00
if ( st < 0 ) {
st % = 360 ;
}
2001-04-13 20:00:12 +08:00
2008-06-22 06:07:53 +08:00
gdImageFilledArc ( im , cx , cy , w , h , st , e , col , style ) ;
2003-03-20 09:12:57 +08:00
2001-04-13 20:00:12 +08:00
RETURN_TRUE ;
}
2003-02-27 07:22:09 +08:00
/* }}} */
2001-04-13 20:00:12 +08:00
2003-06-15 23:29:46 +08:00
/* {{{ proto bool imagealphablending(resource im, bool on)
2001-04-13 20:00:12 +08:00
Turn alpha blending mode on or off for the given image */
PHP_FUNCTION ( imagealphablending )
{
2008-06-22 06:07:53 +08:00
zval * IM ;
zend_bool blend ;
2001-04-13 20:00:12 +08:00
gdImagePtr im ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rb " , & IM , & blend ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
2001-04-13 20:00:12 +08:00
}
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2008-06-22 06:07:53 +08:00
gdImageAlphaBlending ( im , blend ) ;
2001-04-13 20:00:12 +08:00
RETURN_TRUE ;
}
/* }}} */
2003-06-15 23:29:46 +08:00
/* {{{ proto bool imagesavealpha(resource im, bool on)
2003-02-27 07:22:09 +08:00
Include alpha channel to a saved image */
PHP_FUNCTION ( imagesavealpha )
{
2008-06-22 06:07:53 +08:00
zval * IM ;
zend_bool save ;
2003-02-27 07:22:09 +08:00
gdImagePtr im ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rb " , & IM , & save ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
2003-02-27 07:22:09 +08:00
}
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2008-06-22 06:07:53 +08:00
gdImageSaveAlpha ( im , save ) ;
2003-02-27 07:22:09 +08:00
RETURN_TRUE ;
}
2006-03-11 02:07:27 +08:00
/* }}} */
2003-02-27 07:22:09 +08:00
2003-06-15 23:29:46 +08:00
/* {{{ proto bool imagelayereffect(resource im, int effect)
2002-08-22 15:28:26 +08:00
Set the alpha blending flag to use the bundled libgd layering effects */
PHP_FUNCTION ( imagelayereffect )
{
2008-06-22 06:07:53 +08:00
zval * IM ;
2014-08-26 01:24:55 +08:00
zend_long effect ;
2002-08-22 15:28:26 +08:00
gdImagePtr im ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rl " , & IM , & effect ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
2002-08-22 15:28:26 +08:00
}
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2008-06-22 06:07:53 +08:00
gdImageAlphaBlending ( im , effect ) ;
2002-08-22 15:28:26 +08:00
RETURN_TRUE ;
}
/* }}} */
2003-01-26 09:15:02 +08: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 ;
2014-08-26 01:24:55 +08:00
zend_long red , green , blue , alpha ;
2003-01-26 09:15:02 +08:00
gdImagePtr im ;
2006-01-17 23:23:29 +08:00
int ct = ( - 1 ) ;
2003-01-26 09:15:02 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rllll " , & IM , & red , & green , & blue , & alpha ) = = FAILURE ) {
2003-01-26 09:15:02 +08:00
RETURN_FALSE ;
}
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2006-01-17 23:23:29 +08:00
ct = gdImageColorAllocateAlpha ( im , red , green , blue , alpha ) ;
if ( ct < 0 ) {
RETURN_FALSE ;
}
2014-08-26 01:24:55 +08:00
RETURN_LONG ( ( zend_long ) ct ) ;
2003-01-26 09:15:02 +08:00
}
/* }}} */
2001-04-13 20:00:12 +08: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 )
{
2008-06-22 06:07:53 +08:00
zval * IM ;
2014-08-26 01:24:55 +08:00
zend_long red , green , blue , alpha ;
2001-04-13 20:00:12 +08:00
gdImagePtr im ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rllll " , & IM , & red , & green , & blue , & alpha ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
2001-04-13 20:00:12 +08:00
}
2003-02-27 07:22:09 +08:00
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2001-04-13 20:00:12 +08:00
2014-08-26 01:24:55 +08:00
RETURN_LONG ( gdImageColorResolveAlpha ( im , red , green , blue , alpha ) ) ;
2001-04-13 20:00:12 +08:00
}
/* }}} */
/* {{{ proto int imagecolorclosestalpha(resource im, int red, int green, int blue, int alpha)
2001-10-09 02:39:42 +08:00
Find the closest matching colour with alpha transparency */
2001-04-13 20:00:12 +08:00
PHP_FUNCTION ( imagecolorclosestalpha )
{
2008-06-22 06:07:53 +08:00
zval * IM ;
2014-08-26 01:24:55 +08:00
zend_long red , green , blue , alpha ;
2001-04-13 20:00:12 +08:00
gdImagePtr im ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rllll " , & IM , & red , & green , & blue , & alpha ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
2001-04-13 20:00:12 +08:00
}
2003-02-27 07:22:09 +08:00
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2001-04-13 20:00:12 +08:00
2014-08-26 01:24:55 +08:00
RETURN_LONG ( gdImageColorClosestAlpha ( im , red , green , blue , alpha ) ) ;
2001-04-13 20:00:12 +08:00
}
/* }}} */
/* {{{ proto int imagecolorexactalpha(resource im, int red, int green, int blue, int alpha)
2001-10-09 02:39:42 +08:00
Find exact match for colour with transparency */
2001-04-13 20:00:12 +08:00
PHP_FUNCTION ( imagecolorexactalpha )
{
2008-06-22 06:07:53 +08:00
zval * IM ;
2014-08-26 01:24:55 +08:00
zend_long red , green , blue , alpha ;
2001-04-13 20:00:12 +08:00
gdImagePtr im ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rllll " , & IM , & red , & green , & blue , & alpha ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
2001-04-13 20:00:12 +08:00
}
2003-02-27 07:22:09 +08:00
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2003-02-27 07:22:09 +08:00
2014-08-26 01:24:55 +08:00
RETURN_LONG ( gdImageColorExactAlpha ( im , red , green , blue , alpha ) ) ;
2001-04-13 20:00:12 +08:00
}
/* }}} */
2003-06-15 23:29:46 +08: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 20:00:12 +08:00
Copy and resize part of an image using resampling to help ensure clarity */
PHP_FUNCTION ( imagecopyresampled )
{
2008-06-22 06:07:53 +08:00
zval * SIM , * DIM ;
2014-08-26 01:24:55 +08:00
zend_long SX , SY , SW , SH , DX , DY , DW , DH ;
2001-04-13 20:00:12 +08:00
gdImagePtr im_dst , im_src ;
int srcH , srcW , dstH , dstW , srcY , srcX , dstY , dstX ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rrllllllll " , & DIM , & SIM , & DX , & DY , & SX , & SY , & DW , & DH , & SW , & SH ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
2001-04-13 20:00:12 +08:00
}
2015-02-02 13:23:16 +08:00
if ( ( im_dst = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( DIM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
if ( ( im_src = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( SIM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2001-04-13 20:00:12 +08:00
2008-06-22 06:07:53 +08:00
srcX = SX ;
srcY = SY ;
srcH = SH ;
srcW = SW ;
dstX = DX ;
dstY = DY ;
dstH = DH ;
dstW = DW ;
2001-04-13 20:00:12 +08:00
gdImageCopyResampled ( im_dst , im_src , dstX , dstY , srcX , srcY , dstW , dstH , srcW , srcH ) ;
2002-10-29 09:15:44 +08:00
2003-03-20 09:12:57 +08:00
RETURN_TRUE ;
2002-10-29 09:15:44 +08:00
}
/* }}} */
2007-04-17 23:31:45 +08:00
# ifdef PHP_WIN32
/* {{{ proto resource imagegrabwindow(int window_handle [, int client_area])
Grab a window or its client area using a windows handle ( HWND property in COM instance ) */
PHP_FUNCTION ( imagegrabwindow )
{
HWND window ;
2014-08-26 01:24:55 +08:00
zend_long client_area = 0 ;
2007-04-17 23:31:45 +08:00
RECT rc = { 0 } ;
RECT rc_win = { 0 } ;
int Width , Height ;
HDC hdc ;
HDC memDC ;
HBITMAP memBM ;
HBITMAP hOld ;
HINSTANCE handle ;
2014-08-26 01:24:55 +08:00
zend_long lwindow_handle ;
2007-04-17 23:31:45 +08:00
typedef BOOL ( WINAPI * tPrintWindow ) ( HWND , HDC , UINT ) ;
tPrintWindow pPrintWindow = 0 ;
2015-02-05 01:03:06 +08:00
gdImagePtr im = NULL ;
2007-04-17 23:31:45 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " l|l " , & lwindow_handle , & client_area ) = = FAILURE ) {
2007-04-17 23:31:45 +08:00
RETURN_FALSE ;
}
window = ( HWND ) lwindow_handle ;
if ( ! IsWindow ( window ) ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_NOTICE , " Invalid window handle " ) ;
2007-04-17 23:31:45 +08:00
RETURN_FALSE ;
}
hdc = GetDC ( 0 ) ;
if ( client_area ) {
GetClientRect ( window , & rc ) ;
Width = rc . right ;
Height = rc . bottom ;
} else {
GetWindowRect ( window , & rc ) ;
Width = rc . right - rc . left ;
Height = rc . bottom - rc . top ;
}
Width = ( Width / 4 ) * 4 ;
memDC = CreateCompatibleDC ( hdc ) ;
memBM = CreateCompatibleBitmap ( hdc , Width , Height ) ;
hOld = ( HBITMAP ) SelectObject ( memDC , memBM ) ;
handle = LoadLibrary ( " User32.dll " ) ;
if ( handle = = 0 ) {
goto clean ;
}
2015-01-03 17:22:58 +08:00
pPrintWindow = ( tPrintWindow ) GetProcAddress ( handle , " PrintWindow " ) ;
2007-04-17 23:31:45 +08:00
if ( pPrintWindow ) {
pPrintWindow ( window , memDC , ( UINT ) client_area ) ;
} else {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Windows API too old " ) ;
2007-04-17 23:31:45 +08:00
goto clean ;
}
FreeLibrary ( handle ) ;
im = gdImageCreateTrueColor ( Width , Height ) ;
if ( im ) {
int x , y ;
for ( y = 0 ; y < = Height ; y + + ) {
for ( x = 0 ; x < = Width ; x + + ) {
int c = GetPixel ( memDC , x , y ) ;
gdImageSetPixel ( im , x , y , gdTrueColor ( GetRValue ( c ) , GetGValue ( c ) , GetBValue ( c ) ) ) ;
}
}
}
clean :
SelectObject ( memDC , hOld ) ;
DeleteObject ( memBM ) ;
DeleteDC ( memDC ) ;
ReleaseDC ( 0 , hdc ) ;
if ( ! im ) {
RETURN_FALSE ;
} else {
2015-02-02 13:23:16 +08:00
RETURN_RES ( zend_register_resource ( im , le_gd ) ) ;
2007-04-17 23:31:45 +08:00
}
}
/* }}} */
2007-04-17 23:44:23 +08:00
/* {{{ proto resource imagegrabscreen()
2007-04-17 23:31:45 +08:00
Grab a screenshot */
PHP_FUNCTION ( imagegrabscreen )
{
HWND window = GetDesktopWindow ( ) ;
RECT rc = { 0 } ;
int Width , Height ;
HDC hdc ;
HDC memDC ;
HBITMAP memBM ;
HBITMAP hOld ;
typedef BOOL ( WINAPI * tPrintWindow ) ( HWND , HDC , UINT ) ;
tPrintWindow pPrintWindow = 0 ;
gdImagePtr im ;
hdc = GetDC ( 0 ) ;
2008-06-22 06:07:53 +08:00
if ( zend_parse_parameters_none ( ) = = FAILURE ) {
return ;
}
2007-04-17 23:31:45 +08:00
if ( ! hdc ) {
RETURN_FALSE ;
}
GetWindowRect ( window , & rc ) ;
Width = rc . right - rc . left ;
Height = rc . bottom - rc . top ;
Width = ( Width / 4 ) * 4 ;
memDC = CreateCompatibleDC ( hdc ) ;
memBM = CreateCompatibleBitmap ( hdc , Width , Height ) ;
hOld = ( HBITMAP ) SelectObject ( memDC , memBM ) ;
BitBlt ( memDC , 0 , 0 , Width , Height , hdc , rc . left , rc . top , SRCCOPY ) ;
im = gdImageCreateTrueColor ( Width , Height ) ;
if ( im ) {
int x , y ;
for ( y = 0 ; y < = Height ; y + + ) {
for ( x = 0 ; x < = Width ; x + + ) {
int c = GetPixel ( memDC , x , y ) ;
gdImageSetPixel ( im , x , y , gdTrueColor ( GetRValue ( c ) , GetGValue ( c ) , GetBValue ( c ) ) ) ;
}
}
}
SelectObject ( memDC , hOld ) ;
DeleteObject ( memBM ) ;
DeleteDC ( memDC ) ;
ReleaseDC ( 0 , hdc ) ;
if ( ! im ) {
RETURN_FALSE ;
} else {
2015-02-02 13:23:16 +08:00
RETURN_RES ( zend_register_resource ( im , le_gd ) ) ;
2007-04-17 23:31:45 +08:00
}
}
/* }}} */
2007-04-24 20:51:22 +08:00
# endif /* PHP_WIN32 */
2007-04-17 23:31:45 +08:00
2006-06-12 04:03:05 +08:00
/* {{{ proto resource imagerotate(resource src_im, float angle, int bgdcolor [, int ignoretransparent])
2002-10-29 09:15:44 +08:00
Rotate an image using a custom angle */
PHP_FUNCTION ( imagerotate )
{
2005-03-28 07:43:52 +08:00
zval * SIM ;
2002-10-29 09:15:44 +08:00
gdImagePtr im_dst , im_src ;
double degrees ;
2014-08-26 01:24:55 +08:00
zend_long color ;
zend_long ignoretransparent = 0 ;
2002-10-29 09:15:44 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rdl|l " , & SIM , & degrees , & color , & ignoretransparent ) = = FAILURE ) {
2005-03-28 07:43:52 +08:00
RETURN_FALSE ;
2002-10-29 09:15:44 +08:00
}
2015-02-02 13:23:16 +08:00
if ( ( im_src = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( SIM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2002-10-29 09:15:44 +08:00
2013-03-22 16:21:11 +08:00
im_dst = gdImageRotateInterpolated ( im_src , ( const float ) degrees , color ) ;
2002-10-29 09:15:44 +08:00
if ( im_dst ! = NULL ) {
2015-02-02 13:23:16 +08:00
RETURN_RES ( zend_register_resource ( im_dst , le_gd ) ) ;
2002-10-29 09:15:44 +08:00
} else {
RETURN_FALSE ;
}
2001-04-13 20:00:12 +08:00
}
2002-06-25 03:31:44 +08:00
/* }}} */
2001-04-13 20:00:12 +08:00
2003-06-15 23:29:46 +08:00
/* {{{ proto bool imagesettile(resource image, resource tile)
2001-10-09 02:39:42 +08:00
Set the tile image to $ tile when filling $ image with the " IMG_COLOR_TILED " color */
2001-04-13 20:00:12 +08:00
PHP_FUNCTION ( imagesettile )
{
2008-06-22 06:07:53 +08:00
zval * IM , * TILE ;
2001-04-13 20:00:12 +08:00
gdImagePtr im , tile ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rr " , & IM , & TILE ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
2001-04-13 20:00:12 +08:00
}
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
if ( ( tile = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( TILE ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2001-04-13 20:00:12 +08:00
2001-08-12 00:39:07 +08:00
gdImageSetTile ( im , tile ) ;
2001-04-13 20:00:12 +08:00
RETURN_TRUE ;
}
/* }}} */
2003-06-15 23:29:46 +08:00
/* {{{ proto bool imagesetbrush(resource image, resource brush)
2001-10-09 02:39:42 +08:00
Set the brush image to $ brush when filling $ image with the " IMG_COLOR_BRUSHED " color */
2001-04-13 20:00:12 +08:00
PHP_FUNCTION ( imagesetbrush )
{
2008-06-22 06:07:53 +08:00
zval * IM , * TILE ;
2001-04-13 20:00:12 +08:00
gdImagePtr im , tile ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rr " , & IM , & TILE ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
2001-04-13 20:00:12 +08:00
}
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
if ( ( tile = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( TILE ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2001-04-13 20:00:12 +08:00
2001-08-12 00:39:07 +08:00
gdImageSetBrush ( im , tile ) ;
2001-04-13 20:00:12 +08:00
RETURN_TRUE ;
}
/* }}} */
2003-06-15 23:29:46 +08:00
/* {{{ proto resource imagecreate(int x_size, int y_size)
1999-11-25 06:04:49 +08:00
Create a new image */
1999-07-24 00:03:18 +08:00
PHP_FUNCTION ( imagecreate )
{
2014-08-26 01:24:55 +08:00
zend_long x_size , y_size ;
1999-04-16 20:15:38 +08:00
gdImagePtr im ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " ll " , & x_size , & y_size ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
1999-04-16 20:15:38 +08:00
}
2008-06-22 06:07:53 +08:00
if ( x_size < = 0 | | y_size < = 0 | | x_size > = INT_MAX | | y_size > = INT_MAX ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Invalid image dimensions " ) ;
2003-04-04 03:18:57 +08:00
RETURN_FALSE ;
}
2008-06-22 06:07:53 +08:00
im = gdImageCreate ( x_size , y_size ) ;
1999-04-16 20:15:38 +08:00
2007-06-06 17:45:43 +08:00
if ( ! im ) {
RETURN_FALSE ;
}
2015-02-02 13:23:16 +08:00
RETURN_RES ( zend_register_resource ( im , le_gd ) ) ;
1999-04-16 20:15:38 +08:00
}
/* }}} */
2000-07-15 05:51:31 +08:00
/* {{{ proto int imagetypes(void)
2001-05-29 15:46:07 +08:00
Return the types of images supported in a bitfield - 1 = GIF , 2 = JPEG , 4 = PNG , 8 = WBMP , 16 = XPM */
2000-07-15 05:51:31 +08:00
PHP_FUNCTION ( imagetypes )
{
2003-02-27 07:22:09 +08:00
int ret = 0 ;
2000-07-15 05:51:31 +08:00
ret = 1 ;
# ifdef HAVE_GD_JPG
ret | = 2 ;
# endif
# ifdef HAVE_GD_PNG
ret | = 4 ;
# endif
ret | = 8 ;
2013-05-03 19:53:55 +08:00
# if defined(HAVE_GD_XPM)
2001-05-29 15:46:07 +08:00
ret | = 16 ;
2000-07-15 05:51:31 +08:00
# endif
2003-03-20 09:12:57 +08:00
2008-03-11 06:15:36 +08:00
if ( zend_parse_parameters_none ( ) = = FAILURE ) {
return ;
2001-08-13 15:55:39 +08:00
}
2001-08-13 14:43:47 +08:00
2014-08-26 01:24:55 +08:00
RETURN_LONG ( ret ) ;
2000-07-15 05:51:31 +08:00
}
2001-06-05 21:12:10 +08:00
/* }}} */
1999-10-17 22:57:49 +08:00
2013-04-25 19:39:35 +08:00
/* {{{ _php_ctx_getmbi
*/
2013-05-03 18:40:45 +08:00
static int _php_ctx_getmbi ( gdIOCtx * ctx )
2013-04-25 19:39:35 +08:00
{
int i , mbi = 0 ;
do {
i = ( ctx - > getC ) ( ctx ) ;
if ( i < 0 ) {
2013-05-03 18:40:45 +08:00
return - 1 ;
2013-04-25 19:39:35 +08:00
}
mbi = ( mbi < < 7 ) | ( i & 0x7f ) ;
} while ( i & 0x80 ) ;
2013-05-03 18:40:45 +08:00
return mbi ;
2013-04-25 19:39:35 +08:00
}
/* }}} */
2001-06-05 21:12:10 +08:00
/* {{{ _php_image_type
*/
2001-08-08 00:35:35 +08:00
static const char php_sig_gd2 [ 3 ] = { ' g ' , ' d ' , ' 2 ' } ;
2000-11-04 04:31:36 +08:00
static int _php_image_type ( char data [ 8 ] )
2000-11-04 03:53:42 +08:00
{
2003-01-09 02:11:40 +08:00
/* Based on ext/standard/image.c */
2000-11-04 03:53:42 +08:00
2003-03-20 09:12:57 +08:00
if ( data = = NULL ) {
2000-11-04 04:31:36 +08:00
return - 1 ;
2003-03-20 09:12:57 +08:00
}
2000-11-04 04:31:36 +08:00
2003-03-20 09:12:57 +08:00
if ( ! memcmp ( data , php_sig_gd2 , 3 ) ) {
2001-08-08 00:15:45 +08:00
return PHP_GDIMG_TYPE_GD2 ;
2003-03-20 09:12:57 +08:00
} else if ( ! memcmp ( data , php_sig_jpg , 3 ) ) {
2000-11-04 04:31:36 +08:00
return PHP_GDIMG_TYPE_JPG ;
2003-03-20 09:12:57 +08:00
} else if ( ! memcmp ( data , php_sig_png , 3 ) ) {
if ( ! memcmp ( data , php_sig_png , 8 ) ) {
2000-11-04 04:31:36 +08:00
return PHP_GDIMG_TYPE_PNG ;
2003-03-20 09:12:57 +08:00
}
} else if ( ! memcmp ( data , php_sig_gif , 3 ) ) {
2000-11-04 04:31:36 +08:00
return PHP_GDIMG_TYPE_GIF ;
2003-03-20 09:12:57 +08:00
}
2000-11-04 04:31:36 +08:00
else {
gdIOCtx * io_ctx ;
2004-07-27 08:27:06 +08:00
io_ctx = gdNewDynamicCtxEx ( 8 , data , 0 ) ;
2000-11-04 04:31:36 +08:00
if ( io_ctx ) {
2013-04-25 19:39:35 +08:00
if ( _php_ctx_getmbi ( io_ctx ) = = 0 & & _php_ctx_getmbi ( io_ctx ) > = 0 ) {
2002-10-30 07:08:01 +08:00
io_ctx - > gd_free ( io_ctx ) ;
2000-11-04 04:31:36 +08:00
return PHP_GDIMG_TYPE_WBM ;
2002-10-30 09:05:16 +08:00
} else {
2002-10-30 07:08:01 +08:00
io_ctx - > gd_free ( io_ctx ) ;
2003-02-27 07:22:09 +08:00
}
2000-11-04 04:31:36 +08:00
}
}
2000-11-04 03:53:42 +08:00
return - 1 ;
}
2001-06-05 21:12:10 +08:00
/* }}} */
2000-11-04 03:53:42 +08:00
2001-06-05 21:12:10 +08:00
/* {{{ _php_image_create_from_string
*/
2014-12-14 06:06:14 +08:00
gdImagePtr _php_image_create_from_string ( zval * data , char * tn , gdImagePtr ( * ioctx_func_p ) ( ) )
2000-11-04 04:31:36 +08:00
{
gdImagePtr im ;
gdIOCtx * io_ctx ;
2002-09-13 05:42:33 +08:00
2014-08-26 01:24:55 +08:00
io_ctx = gdNewDynamicCtxEx ( Z_STRLEN_P ( data ) , Z_STRVAL_P ( data ) , 0 ) ;
2002-09-13 05:42:33 +08:00
if ( ! io_ctx ) {
2000-11-04 04:31:36 +08:00
return NULL ;
2000-11-04 03:53:42 +08:00
}
2002-09-13 05:42:33 +08:00
2000-11-04 03:53:42 +08:00
im = ( * ioctx_func_p ) ( io_ctx ) ;
2000-11-04 04:31:36 +08:00
if ( ! im ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Passed data is not in '%s' format " , tn ) ;
2006-12-10 09:38:02 +08:00
io_ctx - > gd_free ( io_ctx ) ;
2000-11-04 04:31:36 +08:00
return NULL ;
}
2003-03-20 09:12:57 +08:00
2003-01-09 02:11:40 +08:00
io_ctx - > gd_free ( io_ctx ) ;
2003-03-20 09:12:57 +08:00
2000-11-04 04:31:36 +08:00
return im ;
2000-11-04 03:53:42 +08:00
}
2001-06-05 21:12:10 +08:00
/* }}} */
2000-11-04 03:53:42 +08:00
2003-06-15 23:29:46 +08:00
/* {{{ proto resource imagecreatefromstring(string image)
2000-11-04 04:31:36 +08:00
Create a new image from the image stream in the string */
2001-07-31 01:29:57 +08:00
PHP_FUNCTION ( imagecreatefromstring )
2000-11-04 03:53:42 +08:00
{
2014-05-12 15:53:35 +08:00
zval * data ;
2000-11-04 04:31:36 +08:00
gdImagePtr im ;
int imtype ;
char sig [ 8 ] ;
2000-11-04 03:53:42 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " z " , & data ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
2000-11-23 22:56:09 +08:00
}
2003-02-27 07:22:09 +08:00
2000-11-23 22:56:09 +08:00
convert_to_string_ex ( data ) ;
2014-08-26 01:24:55 +08:00
if ( Z_STRLEN_P ( data ) < 8 ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Empty string or invalid image " ) ;
2005-12-18 01:46:59 +08:00
RETURN_FALSE ;
}
2014-05-12 15:53:35 +08:00
memcpy ( sig , Z_STRVAL_P ( data ) , 8 ) ;
2000-11-04 04:31:36 +08:00
2003-03-20 09:12:57 +08:00
imtype = _php_image_type ( sig ) ;
2000-11-04 04:31:36 +08:00
switch ( imtype ) {
case PHP_GDIMG_TYPE_JPG :
# ifdef HAVE_GD_JPG
2014-12-14 06:06:14 +08:00
im = _php_image_create_from_string ( data , " JPEG " , gdImageCreateFromJpegCtx ) ;
2000-11-04 04:31:36 +08:00
# else
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " No JPEG support in this PHP build " ) ;
2000-11-05 04:43:53 +08:00
RETURN_FALSE ;
2000-11-04 04:31:36 +08:00
# endif
break ;
case PHP_GDIMG_TYPE_PNG :
# ifdef HAVE_GD_PNG
2014-12-14 06:06:14 +08:00
im = _php_image_create_from_string ( data , " PNG " , gdImageCreateFromPngCtx ) ;
2000-11-04 04:31:36 +08:00
# else
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " No PNG support in this PHP build " ) ;
2000-11-05 04:43:53 +08:00
RETURN_FALSE ;
2000-11-04 04:31:36 +08:00
# endif
break ;
2003-02-27 07:22:09 +08:00
2000-11-04 04:31:36 +08:00
case PHP_GDIMG_TYPE_GIF :
2014-12-14 06:06:14 +08:00
im = _php_image_create_from_string ( data , " GIF " , gdImageCreateFromGifCtx ) ;
2000-11-04 04:31:36 +08:00
break ;
case PHP_GDIMG_TYPE_WBM :
2014-12-14 06:06:14 +08:00
im = _php_image_create_from_string ( data , " WBMP " , gdImageCreateFromWBMPCtx ) ;
2001-08-08 00:15:45 +08:00
break ;
case PHP_GDIMG_TYPE_GD2 :
2014-12-14 06:06:14 +08:00
im = _php_image_create_from_string ( data , " GD2 " , gdImageCreateFromGd2Ctx ) ;
2001-08-08 00:15:45 +08:00
break ;
2000-11-04 04:31:36 +08:00
default :
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Data is not in a recognized format " ) ;
2002-09-13 05:42:33 +08:00
RETURN_FALSE ;
2000-11-04 04:31:36 +08:00
}
2002-09-13 05:42:33 +08:00
2000-11-04 04:31:36 +08:00
if ( ! im ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Couldn't create GD Image Stream out of Data " ) ;
2000-11-04 03:53:42 +08:00
RETURN_FALSE ;
2000-11-04 04:31:36 +08:00
}
2000-11-04 03:53:42 +08:00
2015-02-02 13:23:16 +08:00
RETURN_RES ( zend_register_resource ( im , le_gd ) ) ;
2000-11-04 03:53:42 +08:00
}
2000-11-04 04:31:36 +08:00
/* }}} */
2000-11-04 03:53:42 +08:00
2001-06-05 21:12:10 +08:00
/* {{{ _php_image_create_from
*/
2003-02-27 07:22:09 +08: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 22:56:09 +08:00
{
2008-08-05 02:23:33 +08:00
char * file ;
2014-08-27 21:31:48 +08:00
size_t file_len ;
2014-08-26 01:24:55 +08:00
zend_long srcx , srcy , width , height ;
2002-03-16 05:03:08 +08:00
gdImagePtr im = NULL ;
2002-03-16 09:28:57 +08:00
php_stream * stream ;
2002-03-16 05:03:08 +08:00
FILE * fp = NULL ;
2014-05-12 15:53:35 +08:00
# ifdef HAVE_GD_JPG
2006-02-05 23:53:58 +08:00
long ignore_warning ;
2014-05-12 15:53:35 +08:00
# endif
2013-05-03 19:53:55 +08:00
2008-08-05 02:23:33 +08:00
if ( image_type = = PHP_GDIMG_TYPE_GD2PART ) {
2015-04-14 16:20:31 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " pllll " , & file , & file_len , & srcx , & srcy , & width , & height ) = = FAILURE ) {
2008-08-05 02:23:33 +08:00
return ;
}
if ( width < 1 | | height < 1 ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Zero width or height not allowed " ) ;
2006-12-10 10:55:30 +08:00
RETURN_FALSE ;
}
2008-08-05 02:23:33 +08:00
} else {
2015-04-14 16:20:31 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " p " , & file , & file_len ) = = FAILURE ) {
2008-08-05 02:23:33 +08:00
return ;
}
2001-05-29 15:46:07 +08:00
}
2003-02-27 07:22:09 +08:00
2013-06-21 20:11:04 +08:00
2010-04-27 07:53:30 +08:00
stream = php_stream_open_wrapper ( file , " rb " , REPORT_ERRORS | IGNORE_PATH | IGNORE_URL_WIN , NULL ) ;
2002-03-16 05:03:08 +08:00
if ( stream = = NULL ) {
2000-02-29 00:52:03 +08:00
RETURN_FALSE ;
}
2000-06-08 07:04:39 +08:00
2002-03-16 05:03:08 +08: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-22 06:35:02 +08:00
if ( FAILURE = = php_stream_cast ( stream , PHP_STREAM_AS_STDIO , ( void * * ) & fp , REPORT_ERRORS ) ) {
goto out_err ;
}
2003-03-20 09:12:57 +08:00
} else if ( ioctx_func_p ) {
2002-03-16 05:03:08 +08:00
/* we can create an io context */
2000-09-26 17:08:02 +08:00
gdIOCtx * io_ctx ;
2014-05-12 15:53:35 +08:00
zend_string * buff ;
char * pstr ;
2000-09-26 17:08:02 +08:00
2014-05-12 15:53:35 +08:00
buff = php_stream_copy_to_mem ( stream , PHP_STREAM_COPY_ALL , 0 ) ;
2000-09-26 17:08:02 +08:00
2014-05-12 15:53:35 +08:00
if ( ! buff ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Cannot read image data " ) ;
2002-03-16 05:03:08 +08:00
goto out_err ;
2001-02-01 23:40:35 +08:00
}
2003-02-27 07:22:09 +08:00
2014-05-12 15:53:35 +08:00
/* needs to be malloc (persistent) - GD will free() it later */
2015-06-30 09:05:24 +08:00
pstr = pestrndup ( ZSTR_VAL ( buff ) , ZSTR_LEN ( buff ) , 1 ) ;
io_ctx = gdNewDynamicCtxEx ( ZSTR_LEN ( buff ) , pstr , 0 ) ;
2003-03-20 09:17:05 +08:00
if ( ! io_ctx ) {
2014-05-12 15:53:35 +08:00
pefree ( pstr , 1 ) ;
2014-08-26 01:24:55 +08:00
zend_string_release ( buff ) ;
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Cannot allocate GD IO context " ) ;
2002-03-16 05:03:08 +08:00
goto out_err ;
2000-09-26 17:08:02 +08:00
}
2003-03-20 09:12:57 +08:00
2001-05-29 15:46:07 +08:00
if ( image_type = = PHP_GDIMG_TYPE_GD2PART ) {
2008-08-05 02:23:33 +08:00
im = ( * ioctx_func_p ) ( io_ctx , srcx , srcy , width , height ) ;
2001-05-29 15:46:07 +08:00
} else {
im = ( * ioctx_func_p ) ( io_ctx ) ;
}
2002-10-30 07:08:01 +08:00
io_ctx - > gd_free ( io_ctx ) ;
2014-05-12 15:53:35 +08:00
pefree ( pstr , 1 ) ;
2014-08-26 01:24:55 +08:00
zend_string_release ( buff ) ;
2002-03-16 05:03:08 +08:00
}
2013-06-21 20:11:04 +08:00
else if ( php_stream_can_cast ( stream , PHP_STREAM_AS_STDIO ) ) {
2002-03-16 05:03:08 +08:00
/* try and force the stream to be FILE* */
2003-03-20 09:12:57 +08:00
if ( FAILURE = = php_stream_cast ( stream , PHP_STREAM_AS_STDIO | PHP_STREAM_CAST_TRY_HARD , ( void * * ) & fp , REPORT_ERRORS ) ) {
2002-03-16 05:03:08 +08:00
goto out_err ;
2003-03-20 09:12:57 +08:00
}
2002-03-16 05:03:08 +08:00
}
2003-02-27 07:22:09 +08:00
2003-03-20 09:12:57 +08:00
if ( ! im & & fp ) {
2002-12-05 04:58:04 +08:00
switch ( image_type ) {
case PHP_GDIMG_TYPE_GD2PART :
2008-08-05 02:23:33 +08:00
im = ( * func_p ) ( fp , srcx , srcy , width , height ) ;
2002-12-05 04:58:04 +08:00
break ;
2013-05-03 19:53:55 +08:00
# if defined(HAVE_GD_XPM)
2002-12-05 04:58:04 +08:00
case PHP_GDIMG_TYPE_XPM :
2008-08-05 07:48:09 +08:00
im = gdImageCreateFromXpm ( file ) ;
2002-12-05 04:58:04 +08:00
break ;
2002-12-05 07:21:30 +08:00
# endif
2006-02-05 23:53:58 +08:00
# ifdef HAVE_GD_JPG
case PHP_GDIMG_TYPE_JPG :
ignore_warning = INI_INT ( " gd.jpeg_ignore_warning " ) ;
2013-04-24 22:07:50 +08:00
im = gdImageCreateFromJpegEx ( fp , ignore_warning ) ;
2006-02-05 23:53:58 +08:00
break ;
# endif
2002-12-05 04:58:04 +08:00
default :
im = ( * func_p ) ( fp ) ;
break ;
2001-05-29 15:46:07 +08:00
}
2000-09-26 17:08:02 +08:00
fflush ( fp ) ;
}
2000-02-29 00:52:03 +08:00
2013-08-15 12:06:59 +08:00
/* register_im: */
2002-03-16 05:03:08 +08:00
if ( im ) {
2015-02-02 13:23:16 +08:00
RETVAL_RES ( zend_register_resource ( im , le_gd ) ) ;
2002-06-16 01:46:44 +08:00
php_stream_close ( stream ) ;
2002-03-16 05:03:08 +08:00
return ;
2000-04-21 10:23:16 +08:00
}
2000-06-07 08:37:49 +08:00
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " '%s' is not a valid %s file " , file , tn ) ;
2002-03-16 05:03:08 +08:00
out_err :
php_stream_close ( stream ) ;
RETURN_FALSE ;
2000-06-07 08:37:49 +08:00
}
2001-06-05 21:12:10 +08:00
/* }}} */
2000-06-07 08:37:49 +08:00
2003-06-15 23:29:46 +08:00
/* {{{ proto resource imagecreatefromgif(string filename)
2000-06-07 08:37:49 +08:00
Create a new image from GIF file or URL */
PHP_FUNCTION ( imagecreatefromgif )
{
2001-08-12 00:39:07 +08:00
_php_image_create_from ( INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GDIMG_TYPE_GIF , " GIF " , gdImageCreateFromGif , gdImageCreateFromGifCtx ) ;
2000-06-07 08:37:49 +08:00
}
/* }}} */
2002-06-25 03:31:44 +08:00
# ifdef HAVE_GD_JPG
2003-06-15 23:29:46 +08:00
/* {{{ proto resource imagecreatefromjpeg(string filename)
2000-06-07 08:37:49 +08:00
Create a new image from JPEG file or URL */
PHP_FUNCTION ( imagecreatefromjpeg )
{
2001-08-12 00:39:07 +08:00
_php_image_create_from ( INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GDIMG_TYPE_JPG , " JPEG " , gdImageCreateFromJpeg , gdImageCreateFromJpegCtx ) ;
2000-06-07 08:37:49 +08:00
}
/* }}} */
2002-06-25 03:31:44 +08:00
# endif /* HAVE_GD_JPG */
2000-06-07 08:37:49 +08:00
2002-06-25 03:31:44 +08:00
# ifdef HAVE_GD_PNG
2003-06-15 23:29:46 +08:00
/* {{{ proto resource imagecreatefrompng(string filename)
2000-06-07 08:37:49 +08:00
Create a new image from PNG file or URL */
PHP_FUNCTION ( imagecreatefrompng )
{
2001-08-12 00:39:07 +08:00
_php_image_create_from ( INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GDIMG_TYPE_PNG , " PNG " , gdImageCreateFromPng , gdImageCreateFromPngCtx ) ;
1999-10-17 22:57:49 +08:00
}
/* }}} */
2002-06-25 03:31:44 +08:00
# endif /* HAVE_GD_PNG */
1999-10-17 22:57:49 +08:00
2010-10-05 06:30:35 +08:00
# ifdef HAVE_GD_WEBP
2013-06-24 17:15:50 +08:00
/* {{{ proto resource imagecreatefromwebp(string filename)
Create a new image from WEBP file or URL */
2010-10-05 06:30:35 +08:00
PHP_FUNCTION ( imagecreatefromwebp )
{
2013-06-24 17:10:52 +08:00
_php_image_create_from ( INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GDIMG_TYPE_WEBP , " WEBP " , gdImageCreateFromWebp , gdImageCreateFromWebpCtx ) ;
2010-10-05 06:30:35 +08:00
}
/* }}} */
2015-07-19 00:28:42 +08:00
# endif /* HAVE_GD_WEBP */
2010-10-05 06:30:35 +08:00
2003-06-15 23:29:46 +08:00
/* {{{ proto resource imagecreatefromxbm(string filename)
2000-06-07 08:37:49 +08:00
Create a new image from XBM file or URL */
PHP_FUNCTION ( imagecreatefromxbm )
1999-12-18 05:50:07 +08:00
{
2001-08-12 00:39:07 +08:00
_php_image_create_from ( INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GDIMG_TYPE_XBM , " XBM " , gdImageCreateFromXbm , NULL ) ;
2000-06-07 08:37:49 +08:00
}
/* }}} */
2013-05-03 19:53:55 +08:00
# if defined(HAVE_GD_XPM)
2003-06-15 23:29:46 +08:00
/* {{{ proto resource imagecreatefromxpm(string filename)
2000-06-07 08:37:49 +08:00
Create a new image from XPM file or URL */
PHP_FUNCTION ( imagecreatefromxpm )
{
2001-08-12 00:39:07 +08:00
_php_image_create_from ( INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GDIMG_TYPE_XPM , " XPM " , gdImageCreateFromXpm , NULL ) ;
2000-06-07 08:37:49 +08:00
}
/* }}} */
2002-12-05 04:58:04 +08:00
# endif
2000-06-07 08:37:49 +08:00
2003-06-15 23:29:46 +08:00
/* {{{ proto resource imagecreatefromwbmp(string filename)
2000-06-25 09:44:15 +08:00
Create a new image from WBMP file or URL */
PHP_FUNCTION ( imagecreatefromwbmp )
{
2001-08-12 00:39:07 +08:00
_php_image_create_from ( INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GDIMG_TYPE_WBM , " WBMP " , gdImageCreateFromWBMP , gdImageCreateFromWBMPCtx ) ;
2000-06-25 09:44:15 +08:00
}
/* }}} */
2003-06-15 23:29:46 +08:00
/* {{{ proto resource imagecreatefromgd(string filename)
2001-05-29 15:46:07 +08:00
Create a new image from GD file or URL */
PHP_FUNCTION ( imagecreatefromgd )
{
2001-08-12 00:39:07 +08:00
_php_image_create_from ( INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GDIMG_TYPE_GD , " GD " , gdImageCreateFromGd , gdImageCreateFromGdCtx ) ;
2001-05-29 15:46:07 +08:00
}
/* }}} */
2003-06-15 23:29:46 +08:00
/* {{{ proto resource imagecreatefromgd2(string filename)
2001-05-29 15:46:07 +08:00
Create a new image from GD2 file or URL */
PHP_FUNCTION ( imagecreatefromgd2 )
{
2001-08-12 00:39:07 +08:00
_php_image_create_from ( INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GDIMG_TYPE_GD2 , " GD2 " , gdImageCreateFromGd2 , gdImageCreateFromGd2Ctx ) ;
2001-05-29 15:46:07 +08:00
}
/* }}} */
2003-06-15 23:29:46 +08:00
/* {{{ proto resource imagecreatefromgd2part(string filename, int srcX, int srcY, int width, int height)
2001-05-29 15:46:07 +08:00
Create a new image from a given part of GD2 file or URL */
PHP_FUNCTION ( imagecreatefromgd2part )
{
2001-08-12 00:39:07 +08:00
_php_image_create_from ( INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GDIMG_TYPE_GD2PART , " GD2 " , gdImageCreateFromGd2Part , gdImageCreateFromGd2PartCtx ) ;
2001-05-29 15:46:07 +08:00
}
/* }}} */
2001-06-05 21:12:10 +08:00
/* {{{ _php_image_output
*/
2003-02-27 07:22:09 +08:00
static void _php_image_output ( INTERNAL_FUNCTION_PARAMETERS , int image_type , char * tn , void ( * func_p ) ( ) )
2000-11-23 22:56:09 +08:00
{
2008-06-22 06:07:53 +08:00
zval * imgind ;
char * file = NULL ;
2014-08-26 01:24:55 +08:00
zend_long quality = 0 , type = 0 ;
2000-02-29 00:52:03 +08:00
gdImagePtr im ;
2000-06-08 07:04:39 +08:00
char * fn = NULL ;
2000-02-29 00:52:03 +08:00
FILE * fp ;
2014-08-28 01:25:28 +08:00
size_t file_len = 0 ;
int argc = ZEND_NUM_ARGS ( ) ;
2003-01-18 02:34:07 +08:00
int q = - 1 , i , t = 1 ;
2000-02-29 00:52:03 +08:00
2001-04-01 13:42:07 +08: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-18 02:34:07 +08:00
/* The quality parameter for gd2 stands for chunk size */
2001-01-24 17:24:26 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( argc , " r|pll " , & imgind , & file , & file_len , & quality , & type ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
2000-02-29 00:52:03 +08:00
}
2000-11-23 22:56:09 +08:00
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( imgind ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2000-02-29 00:52:03 +08:00
2000-06-08 07:04:39 +08:00
if ( argc > 1 ) {
2008-06-22 06:07:53 +08:00
fn = file ;
2000-06-08 07:04:39 +08:00
if ( argc = = 3 ) {
2008-06-22 06:07:53 +08:00
q = quality ;
2000-06-08 07:04:39 +08:00
}
2003-01-18 02:34:07 +08:00
if ( argc = = 4 ) {
2008-06-22 06:07:53 +08:00
t = type ;
2003-01-18 02:34:07 +08:00
}
2000-06-07 08:37:49 +08:00
}
2008-06-22 06:07:53 +08:00
if ( argc > = 2 & & file_len ) {
2005-11-02 01:05:09 +08:00
PHP_GD_CHECK_OPEN_BASEDIR ( fn , " Invalid filename " ) ;
2000-02-29 00:52:03 +08:00
2001-04-30 20:45:02 +08:00
fp = VCWD_FOPEN ( fn , " wb " ) ;
2000-02-29 00:52:03 +08:00
if ( ! fp ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Unable to open '%s' for writing " , fn ) ;
2000-02-29 00:52:03 +08:00
RETURN_FALSE ;
}
2003-02-27 07:22:09 +08:00
2003-03-20 09:17:05 +08:00
switch ( image_type ) {
2001-04-01 13:42:07 +08:00
case PHP_GDIMG_CONVERT_WBM :
2004-02-23 02:03:09 +08:00
if ( q = = - 1 ) {
q = 0 ;
} else if ( q < 0 | | q > 255 ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Invalid threshold value '%d'. It must be between 0 and 255 " , q ) ;
2004-02-22 00:49:39 +08:00
q = 0 ;
2001-04-01 13:42:07 +08:00
}
2004-02-18 05:30:00 +08:00
gdImageWBMP ( im , q , fp ) ;
break ;
2001-01-24 17:24:26 +08:00
case PHP_GDIMG_TYPE_JPG :
( * func_p ) ( im , fp , q ) ;
break ;
case PHP_GDIMG_TYPE_WBM :
2003-03-20 09:12:57 +08:00
for ( i = 0 ; i < gdImageColorsTotal ( im ) ; i + + ) {
if ( gdImageRed ( im , i ) = = 0 ) break ;
2001-01-24 17:24:26 +08:00
}
2001-04-01 13:42:07 +08:00
( * func_p ) ( im , i , fp ) ;
2001-01-24 17:24:26 +08:00
break ;
2002-12-04 10:37:21 +08:00
case PHP_GDIMG_TYPE_GD :
2003-03-20 09:12:57 +08:00
if ( im - > trueColor ) {
2002-12-04 10:48:23 +08:00
gdImageTrueColorToPalette ( im , 1 , 256 ) ;
2002-12-04 10:37:21 +08:00
}
( * func_p ) ( im , fp ) ;
break ;
2007-05-22 18:22:49 +08:00
case PHP_GDIMG_TYPE_GD2 :
if ( q = = - 1 ) {
q = 128 ;
}
( * func_p ) ( im , fp , q , t ) ;
break ;
2001-01-24 17:24:26 +08:00
default :
2003-01-18 02:34:07 +08:00
if ( q = = - 1 ) {
q = 128 ;
}
( * func_p ) ( im , fp , q , t ) ;
2001-01-24 17:24:26 +08:00
break ;
2000-06-07 08:37:49 +08:00
}
2000-02-29 00:52:03 +08:00
fflush ( fp ) ;
fclose ( fp ) ;
2000-06-07 08:37:49 +08:00
} else {
2000-02-29 00:52:03 +08:00
int b ;
FILE * tmp ;
char buf [ 4096 ] ;
2015-03-04 07:05:28 +08:00
zend_string * path ;
2000-06-08 07:04:39 +08:00
2014-12-14 06:06:14 +08:00
tmp = php_open_temporary_file ( NULL , NULL , & path ) ;
2000-02-29 00:52:03 +08:00
if ( tmp = = NULL ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Unable to open temporary file " ) ;
2000-02-29 00:52:03 +08:00
RETURN_FALSE ;
}
2001-01-24 17:24:26 +08:00
2003-03-20 09:12:57 +08:00
switch ( image_type ) {
2001-04-01 13:42:07 +08:00
case PHP_GDIMG_CONVERT_WBM :
2004-02-23 02:03:09 +08:00
if ( q = = - 1 ) {
q = 0 ;
} else if ( q < 0 | | q > 255 ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Invalid threshold value '%d'. It must be between 0 and 255 " , q ) ;
2004-02-23 02:03:09 +08:00
q = 0 ;
}
2004-02-18 05:30:00 +08:00
gdImageWBMP ( im , q , tmp ) ;
break ;
2001-02-15 22:49:01 +08:00
case PHP_GDIMG_TYPE_JPG :
( * func_p ) ( im , tmp , q ) ;
break ;
case PHP_GDIMG_TYPE_WBM :
2003-03-20 09:12:57 +08:00
for ( i = 0 ; i < gdImageColorsTotal ( im ) ; i + + ) {
if ( gdImageRed ( im , i ) = = 0 ) {
break ;
}
2001-02-15 22:49:01 +08:00
}
( * func_p ) ( im , q , tmp ) ;
break ;
2002-12-05 00:29:48 +08:00
case PHP_GDIMG_TYPE_GD :
if ( im - > trueColor ) {
gdImageTrueColorToPalette ( im , 1 , 256 ) ;
}
( * func_p ) ( im , tmp ) ;
break ;
2007-05-22 18:22:49 +08:00
case PHP_GDIMG_TYPE_GD2 :
if ( q = = - 1 ) {
q = 128 ;
}
( * func_p ) ( im , tmp , q , t ) ;
break ;
2001-02-15 22:49:01 +08:00
default :
( * func_p ) ( im , tmp ) ;
break ;
}
fseek ( tmp , 0 , SEEK_SET ) ;
1999-10-17 22:57:49 +08:00
# if APACHE && defined(CHARSET_EBCDIC)
2001-02-15 22:49:01 +08:00
/* XXX this is unlikely to work any more thies@thieso.net */
/* This is a binary file already: avoid EBCDIC->ASCII conversion */
ap_bsetflag ( php3_rqst - > connection - > client , B_EBCDIC2ASCII , 0 ) ;
# endif
while ( ( b = fread ( buf , 1 , sizeof ( buf ) , tmp ) ) > 0 ) {
2014-12-14 06:06:14 +08:00
php_write ( buf , b ) ;
2001-02-15 22:49:01 +08:00
}
2002-09-13 05:42:33 +08:00
fclose ( tmp ) ;
2015-06-30 09:05:24 +08:00
VCWD_UNLINK ( ( const char * ) ZSTR_VAL ( path ) ) ; /* make sure that the temporary file is removed */
2015-03-04 07:05:28 +08:00
zend_string_release ( path ) ;
2000-06-07 08:37:49 +08:00
}
2002-09-13 05:42:33 +08:00
RETURN_TRUE ;
2000-06-07 08:37:49 +08:00
}
2001-06-05 21:12:10 +08:00
/* }}} */
2000-06-07 08:37:49 +08:00
2003-06-16 04:00:08 +08:00
/* {{{ proto int imagexbm(int im, string filename [, int foreground])
Output XBM image to browser or file */
PHP_FUNCTION ( imagexbm )
{
2013-04-11 12:42:38 +08:00
_php_image_output_ctx ( INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GDIMG_TYPE_XBM , " XBM " , gdImageXbmCtx ) ;
2003-06-16 04:00:08 +08:00
}
/* }}} */
2003-06-15 23:29:46 +08:00
/* {{{ proto bool imagegif(resource im [, string filename])
2000-06-08 07:04:39 +08:00
Output GIF image to browser or file */
PHP_FUNCTION ( imagegif )
{
2001-02-01 23:40:35 +08:00
_php_image_output_ctx ( INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GDIMG_TYPE_GIF , " GIF " , gdImageGifCtx ) ;
2000-06-08 07:04:39 +08:00
}
/* }}} */
2002-06-25 03:31:44 +08:00
# ifdef HAVE_GD_PNG
2003-06-15 23:29:46 +08:00
/* {{{ proto bool imagepng(resource im [, string filename])
2000-06-07 08:37:49 +08:00
Output PNG image to browser or file */
PHP_FUNCTION ( imagepng )
{
2013-04-11 12:42:38 +08:00
_php_image_output_ctx ( INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GDIMG_TYPE_PNG , " PNG " , gdImagePngCtxEx ) ;
1999-10-17 22:57:49 +08:00
}
/* }}} */
2002-06-25 03:31:44 +08:00
# endif /* HAVE_GD_PNG */
1999-10-17 22:57:49 +08:00
2010-10-05 06:30:35 +08:00
# ifdef HAVE_GD_WEBP
2015-06-24 05:46:07 +08:00
/* {{{ proto bool imagewebp(resource im [, string filename[, int quality]] )
2013-06-24 17:15:50 +08:00
Output WEBP image to browser or file */
2010-10-05 06:30:35 +08:00
PHP_FUNCTION ( imagewebp )
{
2013-04-11 12:42:38 +08:00
_php_image_output_ctx ( INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GDIMG_TYPE_WEBP , " WEBP " , gdImageWebpCtx ) ;
2010-10-05 06:30:35 +08:00
}
/* }}} */
# endif /* HAVE_GD_WEBP */
2002-06-25 03:31:44 +08:00
# ifdef HAVE_GD_JPG
2003-06-15 23:29:46 +08:00
/* {{{ proto bool imagejpeg(resource im [, string filename [, int quality]])
2000-06-07 08:37:49 +08:00
Output JPEG image to browser or file */
PHP_FUNCTION ( imagejpeg )
2000-03-13 13:58:50 +08:00
{
2013-04-11 12:42:38 +08:00
_php_image_output_ctx ( INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GDIMG_TYPE_JPG , " JPEG " , gdImageJpegCtx ) ;
2000-03-13 13:58:50 +08:00
}
/* }}} */
2002-06-25 03:31:44 +08:00
# endif /* HAVE_GD_JPG */
2000-03-13 13:58:50 +08:00
2015-06-24 05:46:07 +08:00
/* {{{ proto bool imagewbmp(resource im [, string filename [, int foreground]])
2000-06-07 08:37:49 +08:00
Output WBMP image to browser or file */
PHP_FUNCTION ( imagewbmp )
2000-03-13 13:58:50 +08:00
{
2013-04-11 12:42:38 +08:00
_php_image_output_ctx ( INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GDIMG_TYPE_WBM , " WBMP " , gdImageWBMPCtx ) ;
2000-03-13 13:58:50 +08:00
}
/* }}} */
2003-06-15 23:29:46 +08:00
/* {{{ proto bool imagegd(resource im [, string filename])
2001-05-29 15:46:07 +08:00
Output GD image to browser or file */
PHP_FUNCTION ( imagegd )
{
_php_image_output ( INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GDIMG_TYPE_GD , " GD " , gdImageGd ) ;
}
/* }}} */
2015-06-24 05:46:07 +08:00
/* {{{ proto bool imagegd2(resource im [, string filename [, int chunk_size [, int type]]])
2001-05-29 15:46:07 +08: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 23:29:46 +08:00
/* {{{ proto bool imagedestroy(resource im)
1999-11-25 06:04:49 +08:00
Destroy an image */
1999-07-24 00:03:18 +08:00
PHP_FUNCTION ( imagedestroy )
{
2008-06-22 06:07:53 +08:00
zval * IM ;
2000-02-29 00:52:03 +08:00
gdImagePtr im ;
1999-04-16 20:15:38 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " r " , & IM ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
1999-04-16 20:15:38 +08:00
}
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
1999-04-16 20:15:38 +08:00
2014-05-12 15:53:35 +08:00
zend_list_close ( Z_RES_P ( IM ) ) ;
1999-04-16 20:15:38 +08:00
RETURN_TRUE ;
}
/* }}} */
2002-12-06 10:16:06 +08:00
2003-06-15 23:29:46 +08:00
/* {{{ proto int imagecolorallocate(resource im, int red, int green, int blue)
1999-11-25 06:04:49 +08:00
Allocate a color for an image */
1999-07-24 00:03:18 +08:00
PHP_FUNCTION ( imagecolorallocate )
{
2008-06-22 06:07:53 +08:00
zval * IM ;
2014-08-26 01:24:55 +08:00
zend_long red , green , blue ;
1999-04-16 20:15:38 +08:00
gdImagePtr im ;
2006-01-17 23:44:12 +08:00
int ct = ( - 1 ) ;
1999-04-16 20:15:38 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rlll " , & IM , & red , & green , & blue ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
1999-04-16 20:15:38 +08:00
}
2003-02-27 07:22:09 +08:00
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2000-02-29 00:52:03 +08:00
2008-06-22 06:07:53 +08:00
ct = gdImageColorAllocate ( im , red , green , blue ) ;
2006-01-17 23:44:12 +08:00
if ( ct < 0 ) {
RETURN_FALSE ;
}
2014-08-26 01:24:55 +08:00
RETURN_LONG ( ct ) ;
1999-04-16 20:15:38 +08:00
}
/* }}} */
2003-06-15 23:29:46 +08:00
/* {{{ proto void imagepalettecopy(resource dst, resource src)
2000-06-25 10:55:31 +08:00
Copy the palette from the src image onto the dst image */
PHP_FUNCTION ( imagepalettecopy )
{
2008-06-22 06:07:53 +08:00
zval * dstim , * srcim ;
2000-06-25 10:55:31 +08:00
gdImagePtr dst , src ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rr " , & dstim , & srcim ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
2000-06-25 10:55:31 +08:00
}
2003-02-27 07:22:09 +08:00
2015-02-02 13:23:16 +08:00
if ( ( dst = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( dstim ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
if ( ( src = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( srcim ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2000-06-25 10:55:31 +08:00
gdImagePaletteCopy ( dst , src ) ;
}
/* }}} */
2003-06-15 23:29:46 +08:00
/* {{{ proto int imagecolorat(resource im, int x, int y)
1999-11-25 06:04:49 +08:00
Get the index of the color of a pixel */
1999-07-24 00:03:18 +08:00
PHP_FUNCTION ( imagecolorat )
{
2008-06-22 06:07:53 +08:00
zval * IM ;
2014-08-26 01:24:55 +08:00
zend_long x , y ;
1999-04-16 20:15:38 +08:00
gdImagePtr im ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rll " , & IM , & x , & y ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
1999-04-16 20:15:38 +08:00
}
2003-02-27 07:22:09 +08:00
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2000-02-29 00:52:03 +08:00
2003-03-20 09:17:05 +08:00
if ( gdImageTrueColor ( im ) ) {
2008-06-22 06:07:53 +08:00
if ( im - > tpixels & & gdImageBoundsSafe ( im , x , y ) ) {
2014-08-26 01:24:55 +08:00
RETURN_LONG ( gdImageTrueColorPixel ( im , x , y ) ) ;
2001-11-10 23:06:09 +08:00
} else {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_NOTICE , " %pd,%pd is out of bounds " , x , y ) ;
2001-11-10 23:06:09 +08:00
RETURN_FALSE ;
}
} else {
2008-06-22 06:07:53 +08:00
if ( im - > pixels & & gdImageBoundsSafe ( im , x , y ) ) {
2014-08-26 01:24:55 +08:00
RETURN_LONG ( im - > pixels [ y ] [ x ] ) ;
2001-11-10 23:06:09 +08:00
} else {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_NOTICE , " %pd,%pd is out of bounds " , x , y ) ;
2001-11-10 23:06:09 +08:00
RETURN_FALSE ;
}
1999-04-16 20:15:38 +08:00
}
}
/* }}} */
2003-06-15 23:29:46 +08:00
/* {{{ proto int imagecolorclosest(resource im, int red, int green, int blue)
1999-11-25 06:04:49 +08:00
Get the index of the closest color to the specified color */
1999-07-24 00:03:18 +08:00
PHP_FUNCTION ( imagecolorclosest )
{
2008-06-22 06:07:53 +08:00
zval * IM ;
2014-08-26 01:24:55 +08:00
zend_long red , green , blue ;
1999-04-16 20:15:38 +08:00
gdImagePtr im ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rlll " , & IM , & red , & green , & blue ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
1999-04-16 20:15:38 +08:00
}
2003-02-27 07:22:09 +08:00
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2003-02-27 07:22:09 +08:00
2014-08-26 01:24:55 +08:00
RETURN_LONG ( gdImageColorClosest ( im , red , green , blue ) ) ;
1999-04-16 20:15:38 +08:00
}
/* }}} */
2003-06-15 23:29:46 +08:00
/* {{{ proto int imagecolorclosesthwb(resource im, int red, int green, int blue)
2000-06-25 10:55:31 +08:00
Get the index of the color which has the hue , white and blackness nearest to the given color */
PHP_FUNCTION ( imagecolorclosesthwb )
{
2008-06-22 06:07:53 +08:00
zval * IM ;
2014-08-26 01:24:55 +08:00
zend_long red , green , blue ;
2000-06-25 10:55:31 +08:00
gdImagePtr im ;
2003-02-27 07:22:09 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rlll " , & IM , & red , & green , & blue ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
2000-06-25 10:55:31 +08:00
}
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2000-06-25 10:55:31 +08:00
2014-08-26 01:24:55 +08:00
RETURN_LONG ( gdImageColorClosestHWB ( im , red , green , blue ) ) ;
2000-06-25 10:55:31 +08:00
}
/* }}} */
2003-06-15 23:29:46 +08:00
/* {{{ proto bool imagecolordeallocate(resource im, int index)
1999-11-25 06:04:49 +08:00
De - allocate a color for an image */
1999-07-24 00:03:18 +08:00
PHP_FUNCTION ( imagecolordeallocate )
{
2008-06-22 06:07:53 +08:00
zval * IM ;
2014-08-26 01:24:55 +08:00
zend_long index ;
2000-02-29 00:52:03 +08:00
int col ;
1999-04-16 20:15:38 +08:00
gdImagePtr im ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rl " , & IM , & index ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
1999-04-16 20:15:38 +08:00
}
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
1999-04-16 20:15:38 +08:00
2002-11-23 07:25:14 +08:00
/* We can return right away for a truecolor image as deallocating colours is meaningless here */
if ( gdImageTrueColor ( im ) ) {
RETURN_TRUE ;
}
2008-06-22 06:07:53 +08:00
col = index ;
1999-04-16 20:15:38 +08:00
if ( col > = 0 & & col < gdImageColorsTotal ( im ) ) {
gdImageColorDeallocate ( im , col ) ;
RETURN_TRUE ;
2000-11-23 22:56:09 +08:00
} else {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Color index %d out of range " , col ) ;
2000-02-29 00:52:03 +08:00
RETURN_FALSE ;
}
1999-04-16 20:15:38 +08:00
}
/* }}} */
2003-06-15 23:29:46 +08:00
/* {{{ proto int imagecolorresolve(resource im, int red, int green, int blue)
1999-11-25 06:04:49 +08:00
Get the index of the specified color or its closest possible alternative */
1999-07-24 00:03:18 +08:00
PHP_FUNCTION ( imagecolorresolve )
{
2008-06-22 06:07:53 +08:00
zval * IM ;
2014-08-26 01:24:55 +08:00
zend_long red , green , blue ;
1999-04-16 20:15:38 +08:00
gdImagePtr im ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rlll " , & IM , & red , & green , & blue ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
1999-04-16 20:15:38 +08:00
}
2003-02-27 07:22:09 +08:00
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2003-02-27 07:22:09 +08:00
2014-08-26 01:24:55 +08:00
RETURN_LONG ( gdImageColorResolve ( im , red , green , blue ) ) ;
1999-04-16 20:15:38 +08:00
}
/* }}} */
2003-06-15 23:29:46 +08:00
/* {{{ proto int imagecolorexact(resource im, int red, int green, int blue)
1999-11-25 06:04:49 +08:00
Get the index of the specified color */
1999-07-24 00:03:18 +08:00
PHP_FUNCTION ( imagecolorexact )
{
2008-06-22 06:07:53 +08:00
zval * IM ;
2014-08-26 01:24:55 +08:00
zend_long red , green , blue ;
1999-04-16 20:15:38 +08:00
gdImagePtr im ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rlll " , & IM , & red , & green , & blue ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
1999-04-16 20:15:38 +08:00
}
2003-02-27 07:22:09 +08:00
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2003-02-27 07:22:09 +08:00
2014-08-26 01:24:55 +08:00
RETURN_LONG ( gdImageColorExact ( im , red , green , blue ) ) ;
1999-04-16 20:15:38 +08:00
}
/* }}} */
2003-06-15 23:29:46 +08:00
/* {{{ proto void imagecolorset(resource im, int col, int red, int green, int blue)
1999-11-25 06:04:49 +08:00
Set the color for the specified palette index */
1999-07-24 00:03:18 +08:00
PHP_FUNCTION ( imagecolorset )
{
2008-06-22 06:07:53 +08:00
zval * IM ;
2014-08-26 01:24:55 +08:00
zend_long color , red , green , blue , alpha = 0 ;
1999-04-16 20:15:38 +08:00
int col ;
gdImagePtr im ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rllll|l " , & IM , & color , & red , & green , & blue , & alpha ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
1999-04-16 20:15:38 +08:00
}
2003-02-27 07:22:09 +08:00
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2003-02-27 07:22:09 +08:00
2008-06-22 06:07:53 +08:00
col = color ;
2003-02-27 07:22:09 +08:00
1999-04-16 20:15:38 +08:00
if ( col > = 0 & & col < gdImageColorsTotal ( im ) ) {
2008-06-22 06:07:53 +08:00
im - > red [ col ] = red ;
im - > green [ col ] = green ;
im - > blue [ col ] = blue ;
2010-05-18 20:38:57 +08:00
im - > alpha [ col ] = alpha ;
2000-11-23 22:56:09 +08:00
} else {
1999-04-16 20:15:38 +08:00
RETURN_FALSE ;
}
}
/* }}} */
2003-06-15 23:29:46 +08:00
/* {{{ proto array imagecolorsforindex(resource im, int col)
1999-11-25 06:04:49 +08:00
Get the colors for an index */
1999-07-24 00:03:18 +08:00
PHP_FUNCTION ( imagecolorsforindex )
{
2008-06-22 06:07:53 +08:00
zval * IM ;
2014-08-26 01:24:55 +08:00
zend_long index ;
2000-02-29 00:52:03 +08:00
int col ;
1999-04-16 20:15:38 +08:00
gdImagePtr im ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rl " , & IM , & index ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
1999-04-16 20:15:38 +08:00
}
2003-02-27 07:22:09 +08:00
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2008-06-22 06:07:53 +08:00
col = index ;
1999-04-16 20:15:38 +08:00
2001-11-10 23:06:09 +08:00
if ( ( col > = 0 & & gdImageTrueColor ( im ) ) | | ( ! gdImageTrueColor ( im ) & & col > = 0 & & col < gdImageColorsTotal ( im ) ) ) {
2003-01-18 05:37:56 +08:00
array_init ( return_value ) ;
2014-08-26 01:24:55 +08: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 ) ) ;
2008-07-18 09:51:49 +08:00
} else {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Color index %d out of range " , col ) ;
1999-04-16 20:15:38 +08:00
RETURN_FALSE ;
}
}
/* }}} */
2003-06-15 23:29:46 +08:00
/* {{{ proto bool imagegammacorrect(resource im, float inputgamma, float outputgamma)
2000-05-24 06:28:07 +08:00
Apply a gamma correction to a GD image */
2000-05-14 23:25:13 +08:00
PHP_FUNCTION ( imagegammacorrect )
{
2008-06-22 06:07:53 +08:00
zval * IM ;
2000-05-14 23:25:13 +08:00
gdImagePtr im ;
int i ;
2000-11-23 22:56:09 +08:00
double input , output ;
2000-05-14 23:25:13 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rdd " , & IM , & input , & output ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
2000-05-14 23:25:13 +08:00
}
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2000-05-14 23:25:13 +08:00
2001-07-06 05:23:28 +08: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-27 07:22:09 +08:00
gdImageSetPixel ( im , x , y ,
2015-06-06 20:57:38 +08:00
gdTrueColorAlpha (
2003-03-20 09:12:57 +08:00
( 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 ) ,
2015-06-06 20:57:38 +08:00
( int ) ( ( pow ( ( pow ( ( gdTrueColorGetBlue ( c ) / 255.0 ) , input ) ) , 1.0 / output ) * 255 ) + .5 ) ,
gdTrueColorGetAlpha ( c )
2003-03-20 09:12:57 +08:00
)
) ;
2001-07-06 05:23:28 +08:00
}
}
RETURN_TRUE ;
}
2008-07-18 09:51:49 +08:00
2000-05-14 23:25:13 +08:00
for ( i = 0 ; i < gdImageColorsTotal ( im ) ; i + + ) {
2003-03-20 09:12:57 +08: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 23:25:13 +08:00
}
RETURN_TRUE ;
}
2000-05-24 06:28:07 +08:00
/* }}} */
2000-05-14 23:25:13 +08:00
2003-06-15 23:29:46 +08:00
/* {{{ proto bool imagesetpixel(resource im, int x, int y, int col)
1999-11-25 06:04:49 +08:00
Set a single pixel */
1999-07-24 00:03:18 +08:00
PHP_FUNCTION ( imagesetpixel )
{
2008-06-22 06:07:53 +08:00
zval * IM ;
2014-08-26 01:24:55 +08:00
zend_long x , y , col ;
1999-04-16 20:15:38 +08:00
gdImagePtr im ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rlll " , & IM , & x , & y , & col ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
1999-04-16 20:15:38 +08:00
}
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2008-06-22 06:07:53 +08:00
gdImageSetPixel ( im , x , y , col ) ;
1999-04-16 20:15:38 +08:00
RETURN_TRUE ;
}
2003-02-27 07:22:09 +08:00
/* }}} */
1999-04-16 20:15:38 +08:00
2003-06-15 23:29:46 +08:00
/* {{{ proto bool imageline(resource im, int x1, int y1, int x2, int y2, int col)
1999-11-25 06:04:49 +08:00
Draw a line */
1999-07-24 00:03:18 +08:00
PHP_FUNCTION ( imageline )
{
2008-06-22 06:07:53 +08:00
zval * IM ;
2014-08-26 01:24:55 +08:00
zend_long x1 , y1 , x2 , y2 , col ;
1999-04-16 20:15:38 +08:00
gdImagePtr im ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rlllll " , & IM , & x1 , & y1 , & x2 , & y2 , & col ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
1999-04-16 20:15:38 +08:00
}
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
1999-04-16 20:15:38 +08:00
2002-12-12 04:44:44 +08:00
# ifdef HAVE_GD_BUNDLED
2003-03-20 09:12:57 +08:00
if ( im - > antialias ) {
2008-06-22 06:07:53 +08:00
gdImageAALine ( im , x1 , y1 , x2 , y2 , col ) ;
2003-03-20 09:12:57 +08:00
} else
2003-02-27 07:22:09 +08:00
# endif
2003-03-20 09:12:57 +08:00
{
2008-06-22 06:07:53 +08:00
gdImageLine ( im , x1 , y1 , x2 , y2 , col ) ;
2003-03-20 09:12:57 +08:00
}
1999-04-16 20:15:38 +08:00
RETURN_TRUE ;
}
2003-02-27 07:22:09 +08:00
/* }}} */
1999-04-16 20:15:38 +08:00
2003-06-15 23:29:46 +08:00
/* {{{ proto bool imagedashedline(resource im, int x1, int y1, int x2, int y2, int col)
1999-11-25 06:04:49 +08:00
Draw a dashed line */
1999-07-24 00:03:18 +08:00
PHP_FUNCTION ( imagedashedline )
{
2008-06-22 06:07:53 +08:00
zval * IM ;
2014-08-26 01:24:55 +08:00
zend_long x1 , y1 , x2 , y2 , col ;
1999-04-16 20:15:38 +08:00
gdImagePtr im ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rlllll " , & IM , & x1 , & y1 , & x2 , & y2 , & col ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
1999-04-16 20:15:38 +08:00
}
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2008-06-22 06:07:53 +08:00
gdImageDashedLine ( im , x1 , y1 , x2 , y2 , col ) ;
1999-04-16 20:15:38 +08:00
RETURN_TRUE ;
}
/* }}} */
2003-06-15 23:29:46 +08:00
/* {{{ proto bool imagerectangle(resource im, int x1, int y1, int x2, int y2, int col)
1999-11-25 06:04:49 +08:00
Draw a rectangle */
1999-07-24 00:03:18 +08:00
PHP_FUNCTION ( imagerectangle )
{
2008-06-22 06:07:53 +08:00
zval * IM ;
2014-08-26 01:24:55 +08:00
zend_long x1 , y1 , x2 , y2 , col ;
1999-04-16 20:15:38 +08:00
gdImagePtr im ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rlllll " , & IM , & x1 , & y1 , & x2 , & y2 , & col ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
1999-04-16 20:15:38 +08:00
}
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2008-06-22 06:07:53 +08:00
gdImageRectangle ( im , x1 , y1 , x2 , y2 , col ) ;
1999-04-16 20:15:38 +08:00
RETURN_TRUE ;
}
2003-02-27 07:22:09 +08:00
/* }}} */
1999-04-16 20:15:38 +08:00
2003-06-15 23:29:46 +08:00
/* {{{ proto bool imagefilledrectangle(resource im, int x1, int y1, int x2, int y2, int col)
1999-11-25 06:04:49 +08:00
Draw a filled rectangle */
1999-07-24 00:03:18 +08:00
PHP_FUNCTION ( imagefilledrectangle )
{
2008-06-22 06:07:53 +08:00
zval * IM ;
2014-08-26 01:24:55 +08:00
zend_long x1 , y1 , x2 , y2 , col ;
1999-04-16 20:15:38 +08:00
gdImagePtr im ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rlllll " , & IM , & x1 , & y1 , & x2 , & y2 , & col ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
1999-04-16 20:15:38 +08:00
}
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2008-06-22 06:07:53 +08:00
gdImageFilledRectangle ( im , x1 , y1 , x2 , y2 , col ) ;
1999-04-16 20:15:38 +08:00
RETURN_TRUE ;
}
2003-02-27 07:22:09 +08:00
/* }}} */
1999-04-16 20:15:38 +08:00
2003-06-15 23:29:46 +08:00
/* {{{ proto bool imagearc(resource im, int cx, int cy, int w, int h, int s, int e, int col)
1999-11-25 06:04:49 +08:00
Draw a partial ellipse */
1999-07-24 00:03:18 +08:00
PHP_FUNCTION ( imagearc )
{
2008-06-22 06:07:53 +08:00
zval * IM ;
2014-08-26 01:24:55 +08:00
zend_long cx , cy , w , h , ST , E , col ;
1999-04-16 20:15:38 +08:00
gdImagePtr im ;
2001-08-12 00:39:07 +08:00
int e , st ;
1999-04-16 20:15:38 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rlllllll " , & IM , & cx , & cy , & w , & h , & ST , & E , & col ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
1999-04-16 20:15:38 +08:00
}
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2000-02-29 00:52:03 +08:00
2008-06-22 06:07:53 +08:00
e = E ;
2003-03-20 09:12:57 +08:00
if ( e < 0 ) {
e % = 360 ;
}
2003-12-29 05:08:46 +08:00
2008-06-22 06:07:53 +08:00
st = ST ;
2003-03-20 09:12:57 +08:00
if ( st < 0 ) {
st % = 360 ;
}
2003-12-29 05:08:46 +08:00
2008-06-22 06:07:53 +08:00
gdImageArc ( im , cx , cy , w , h , st , e , col ) ;
1999-04-16 20:15:38 +08:00
RETURN_TRUE ;
}
2003-02-27 07:22:09 +08:00
/* }}} */
1999-04-16 20:15:38 +08:00
2003-06-15 23:29:46 +08:00
/* {{{ proto bool imageellipse(resource im, int cx, int cy, int w, int h, int color)
2002-07-28 18:00:37 +08:00
Draw an ellipse */
PHP_FUNCTION ( imageellipse )
{
2008-06-22 06:07:53 +08:00
zval * IM ;
2014-08-26 01:24:55 +08:00
zend_long cx , cy , w , h , color ;
2002-07-28 18:00:37 +08:00
gdImagePtr im ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rlllll " , & IM , & cx , & cy , & w , & h , & color ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
2002-07-28 18:00:37 +08:00
}
2003-02-27 07:22:09 +08:00
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2002-07-28 18:00:37 +08:00
2008-06-22 06:07:53 +08:00
gdImageEllipse ( im , cx , cy , w , h , color ) ;
2002-07-28 18:00:37 +08:00
RETURN_TRUE ;
}
/* }}} */
2003-06-15 23:29:46 +08:00
/* {{{ proto bool imagefilltoborder(resource im, int x, int y, int border, int col)
1999-11-25 06:04:49 +08:00
Flood fill to specific color */
1999-07-24 00:03:18 +08:00
PHP_FUNCTION ( imagefilltoborder )
{
2008-06-22 06:07:53 +08:00
zval * IM ;
2014-08-26 01:24:55 +08:00
zend_long x , y , border , col ;
1999-04-16 20:15:38 +08:00
gdImagePtr im ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rllll " , & IM , & x , & y , & border , & col ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
1999-04-16 20:15:38 +08:00
}
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2008-06-22 06:07:53 +08:00
gdImageFillToBorder ( im , x , y , border , col ) ;
1999-04-16 20:15:38 +08:00
RETURN_TRUE ;
}
2003-02-27 07:22:09 +08:00
/* }}} */
1999-04-16 20:15:38 +08:00
2003-06-15 23:29:46 +08:00
/* {{{ proto bool imagefill(resource im, int x, int y, int col)
1999-11-25 06:04:49 +08:00
Flood fill */
1999-07-24 00:03:18 +08:00
PHP_FUNCTION ( imagefill )
{
2008-06-22 06:07:53 +08:00
zval * IM ;
2014-08-26 01:24:55 +08:00
zend_long x , y , col ;
1999-04-16 20:15:38 +08:00
gdImagePtr im ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rlll " , & IM , & x , & y , & col ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
1999-04-16 20:15:38 +08:00
}
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2008-06-22 06:07:53 +08:00
gdImageFill ( im , x , y , col ) ;
1999-04-16 20:15:38 +08:00
RETURN_TRUE ;
}
2003-02-27 07:22:09 +08:00
/* }}} */
1999-04-16 20:15:38 +08:00
2003-06-15 23:29:46 +08:00
/* {{{ proto int imagecolorstotal(resource im)
1999-11-25 06:04:49 +08:00
Find out the number of colors in an image ' s palette */
1999-07-24 00:03:18 +08:00
PHP_FUNCTION ( imagecolorstotal )
{
2008-06-22 06:07:53 +08:00
zval * IM ;
1999-04-16 20:15:38 +08:00
gdImagePtr im ;
2009-05-26 21:57:07 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " r " , & IM ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
1999-04-16 20:15:38 +08:00
}
2000-11-23 22:56:09 +08:00
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
1999-04-16 20:15:38 +08:00
2014-08-26 01:24:55 +08:00
RETURN_LONG ( gdImageColorsTotal ( im ) ) ;
1999-04-16 20:15:38 +08:00
}
2003-02-27 07:22:09 +08:00
/* }}} */
1999-04-16 20:15:38 +08:00
2003-06-15 23:29:46 +08:00
/* {{{ proto int imagecolortransparent(resource im [, int col])
1999-11-25 06:04:49 +08:00
Define a color as transparent */
1999-07-24 00:03:18 +08:00
PHP_FUNCTION ( imagecolortransparent )
{
2008-06-22 06:07:53 +08:00
zval * IM ;
2014-08-26 01:24:55 +08:00
zend_long COL = 0 ;
1999-04-16 20:15:38 +08:00
gdImagePtr im ;
2008-06-22 06:07:53 +08:00
int argc = ZEND_NUM_ARGS ( ) ;
1999-04-16 20:15:38 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( argc , " r|l " , & IM , & COL ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
1999-04-16 20:15:38 +08:00
}
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
1999-04-16 20:15:38 +08:00
2008-06-22 06:07:53 +08:00
if ( argc > 1 ) {
gdImageColorTransparent ( im , COL ) ;
1999-04-16 20:15:38 +08:00
}
2000-11-23 22:56:09 +08:00
2014-08-26 01:24:55 +08:00
RETURN_LONG ( gdImageGetTransparent ( im ) ) ;
1999-04-16 20:15:38 +08:00
}
2003-02-27 07:22:09 +08:00
/* }}} */
1999-04-16 20:15:38 +08:00
2003-06-15 23:29:46 +08:00
/* {{{ proto int imageinterlace(resource im [, int interlace])
1999-11-25 06:04:49 +08:00
Enable or disable interlace */
1999-07-24 00:03:18 +08:00
PHP_FUNCTION ( imageinterlace )
{
2008-06-22 06:07:53 +08:00
zval * IM ;
int argc = ZEND_NUM_ARGS ( ) ;
2014-08-26 01:24:55 +08:00
zend_long INT = 0 ;
1999-04-16 20:15:38 +08:00
gdImagePtr im ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( argc , " r|l " , & IM , & INT ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
1999-04-16 20:15:38 +08:00
}
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
1999-04-16 20:15:38 +08:00
2008-06-22 06:07:53 +08:00
if ( argc > 1 ) {
gdImageInterlace ( im , INT ) ;
1999-04-16 20:15:38 +08:00
}
2000-11-23 22:56:09 +08:00
2014-08-26 01:24:55 +08:00
RETURN_LONG ( gdImageGetInterlaced ( im ) ) ;
1999-04-16 20:15:38 +08:00
}
2003-02-27 07:22:09 +08:00
/* }}} */
1999-04-16 20:15:38 +08:00
2001-06-05 21:12:10 +08:00
/* {{{ php_imagepolygon
arg = 0 normal polygon
1999-04-16 20:15:38 +08:00
arg = 1 filled polygon */
/* im, points, num_points, col */
2003-02-27 07:22:09 +08:00
static void php_imagepolygon ( INTERNAL_FUNCTION_PARAMETERS , int filled )
2001-06-07 21:17:02 +08:00
{
2008-06-22 06:07:53 +08:00
zval * IM , * POINTS ;
2014-08-26 01:24:55 +08:00
zend_long NPOINTS , COL ;
2014-05-12 15:53:35 +08:00
zval * var = NULL ;
1999-04-16 20:15:38 +08:00
gdImagePtr im ;
2003-02-27 07:22:09 +08:00
gdPointPtr points ;
1999-04-16 20:15:38 +08:00
int npoints , col , nelem , i ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rall " , & IM , & POINTS , & NPOINTS , & COL ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
1999-04-16 20:15:38 +08:00
}
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
1999-04-16 20:15:38 +08:00
2008-06-22 06:07:53 +08:00
npoints = NPOINTS ;
col = COL ;
1999-04-16 20:15:38 +08:00
2008-06-22 06:07:53 +08:00
nelem = zend_hash_num_elements ( Z_ARRVAL_P ( POINTS ) ) ;
1999-04-16 20:15:38 +08:00
if ( nelem < 6 ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " You must have at least 3 points in your array " ) ;
1999-04-16 20:15:38 +08:00
RETURN_FALSE ;
}
2010-01-14 19:11:56 +08:00
if ( npoints < = 0 ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " You must give a positive number of points " ) ;
2010-01-14 19:11:56 +08:00
RETURN_FALSE ;
}
1999-04-16 20:15:38 +08:00
if ( nelem < npoints * 2 ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Trying to use %d points in array with only %d points " , npoints , nelem / 2 ) ;
1999-04-16 20:15:38 +08:00
RETURN_FALSE ;
}
2003-08-12 08:58:52 +08:00
points = ( gdPointPtr ) safe_emalloc ( npoints , sizeof ( gdPoint ) , 0 ) ;
1999-04-16 20:15:38 +08:00
for ( i = 0 ; i < npoints ; i + + ) {
2014-05-12 15:53:35 +08:00
if ( ( var = zend_hash_index_find ( Z_ARRVAL_P ( POINTS ) , ( i * 2 ) ) ) ! = NULL ) {
2014-10-10 18:23:33 +08:00
points [ i ] . x = zval_get_long ( var ) ;
1999-04-16 20:15:38 +08:00
}
2014-05-12 15:53:35 +08:00
if ( ( var = zend_hash_index_find ( Z_ARRVAL_P ( POINTS ) , ( i * 2 ) + 1 ) ) ! = NULL ) {
2014-10-10 18:23:33 +08:00
points [ i ] . y = zval_get_long ( var ) ;
1999-04-16 20:15:38 +08:00
}
}
if ( filled ) {
gdImageFilledPolygon ( im , points , npoints , col ) ;
2000-11-23 22:56:09 +08:00
} else {
1999-04-16 20:15:38 +08:00
gdImagePolygon ( im , points , npoints , col ) ;
}
2000-05-02 02:56:58 +08:00
efree ( points ) ;
1999-04-16 20:15:38 +08:00
RETURN_TRUE ;
}
2001-06-05 21:12:10 +08:00
/* }}} */
1999-04-16 20:15:38 +08:00
2003-06-15 23:29:46 +08:00
/* {{{ proto bool imagepolygon(resource im, array point, int num_points, int col)
1999-11-25 06:04:49 +08:00
Draw a polygon */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( imagepolygon )
1999-04-16 20:15:38 +08:00
{
1999-12-18 05:50:07 +08:00
php_imagepolygon ( INTERNAL_FUNCTION_PARAM_PASSTHRU , 0 ) ;
1999-04-16 20:15:38 +08:00
}
/* }}} */
2003-06-15 23:29:46 +08:00
/* {{{ proto bool imagefilledpolygon(resource im, array point, int num_points, int col)
1999-11-25 06:04:49 +08:00
Draw a filled polygon */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( imagefilledpolygon )
1999-04-16 20:15:38 +08:00
{
1999-12-18 05:50:07 +08:00
php_imagepolygon ( INTERNAL_FUNCTION_PARAM_PASSTHRU , 1 ) ;
1999-04-16 20:15:38 +08:00
}
/* }}} */
2001-06-05 21:12:10 +08:00
/* {{{ php_find_gd_font
*/
2014-12-14 06:06:14 +08:00
static gdFontPtr php_find_gd_font ( int size )
1999-04-16 20:15:38 +08:00
{
gdFontPtr font ;
2003-02-27 07:22:09 +08:00
1999-04-16 20:15:38 +08:00
switch ( size ) {
2002-09-13 05:42:33 +08:00
case 1 :
2014-05-12 15:53:35 +08:00
font = gdFontTiny ;
break ;
2002-09-13 05:42:33 +08:00
case 2 :
2014-05-12 15:53:35 +08:00
font = gdFontSmall ;
break ;
2002-09-13 05:42:33 +08:00
case 3 :
2014-05-12 15:53:35 +08:00
font = gdFontMediumBold ;
break ;
2002-09-13 05:42:33 +08:00
case 4 :
2014-05-12 15:53:35 +08:00
font = gdFontLarge ;
break ;
2002-09-13 05:42:33 +08:00
case 5 :
2014-05-12 15:53:35 +08:00
font = gdFontGiant ;
break ;
default : {
zval * zv = zend_hash_index_find ( & EG ( regular_list ) , size - 5 ) ;
if ( ! zv | | ( Z_RES_P ( zv ) ) - > type ! = le_gd_font ) {
if ( size < 1 ) {
font = gdFontTiny ;
} else {
font = gdFontGiant ;
}
} else {
font = ( gdFontPtr ) Z_RES_P ( zv ) - > ptr ;
1999-04-16 20:15:38 +08:00
}
2014-05-12 15:53:35 +08:00
}
break ;
1999-04-16 20:15:38 +08:00
}
return font ;
}
2001-06-05 21:12:10 +08:00
/* }}} */
1999-04-16 20:15:38 +08:00
2001-06-05 21:12:10 +08:00
/* {{{ php_imagefontsize
1999-04-16 20:15:38 +08:00
* arg = 0 ImageFontWidth
* arg = 1 ImageFontHeight
*/
1999-12-18 05:50:07 +08:00
static void php_imagefontsize ( INTERNAL_FUNCTION_PARAMETERS , int arg )
1999-04-16 20:15:38 +08:00
{
2014-08-26 01:24:55 +08:00
zend_long SIZE ;
1999-04-16 20:15:38 +08:00
gdFontPtr font ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " l " , & SIZE ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
1999-04-16 20:15:38 +08:00
}
2003-02-27 07:22:09 +08:00
2014-12-14 06:06:14 +08:00
font = php_find_gd_font ( SIZE ) ;
2014-08-26 01:24:55 +08:00
RETURN_LONG ( arg ? font - > h : font - > w ) ;
1999-04-16 20:15:38 +08:00
}
2001-06-05 21:12:10 +08:00
/* }}} */
1999-04-16 20:15:38 +08:00
/* {{{ proto int imagefontwidth(int font)
1999-11-25 06:04:49 +08:00
Get font width */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( imagefontwidth )
1999-04-16 20:15:38 +08:00
{
1999-12-18 05:50:07 +08:00
php_imagefontsize ( INTERNAL_FUNCTION_PARAM_PASSTHRU , 0 ) ;
1999-04-16 20:15:38 +08:00
}
/* }}} */
/* {{{ proto int imagefontheight(int font)
2000-01-25 04:25:57 +08:00
Get font height */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( imagefontheight )
1999-04-16 20:15:38 +08:00
{
1999-12-18 05:50:07 +08:00
php_imagefontsize ( INTERNAL_FUNCTION_PARAM_PASSTHRU , 1 ) ;
1999-04-16 20:15:38 +08:00
}
/* }}} */
2001-06-05 21:12:10 +08:00
/* {{{ php_gdimagecharup
* workaround for a bug in gd 1.2 */
2001-08-22 16:34:04 +08:00
static void php_gdimagecharup ( gdImagePtr im , gdFontPtr f , int x , int y , int c , int color )
1999-04-16 20:15:38 +08:00
{
int cx , cy , px , py , fline ;
cx = 0 ;
cy = 0 ;
2003-03-20 09:12:57 +08:00
1999-04-16 20:15:38 +08:00
if ( ( c < f - > offset ) | | ( c > = ( f - > offset + f - > nchars ) ) ) {
return ;
}
2003-03-20 09:12:57 +08:00
1999-04-16 20:15:38 +08: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-27 07:22:09 +08:00
gdImageSetPixel ( im , px , py , color ) ;
1999-04-16 20:15:38 +08:00
}
cy + + ;
}
cy = 0 ;
cx + + ;
}
}
2001-06-05 21:12:10 +08:00
/* }}} */
1999-04-16 20:15:38 +08:00
2001-06-05 21:12:10 +08:00
/* {{{ php_imagechar
1999-04-16 20:15:38 +08:00
* arg = 0 ImageChar
* arg = 1 ImageCharUp
* arg = 2 ImageString
* arg = 3 ImageStringUp
*/
2003-02-27 07:22:09 +08:00
static void php_imagechar ( INTERNAL_FUNCTION_PARAMETERS , int mode )
2000-11-23 22:56:09 +08:00
{
2008-06-22 06:07:53 +08:00
zval * IM ;
2014-08-26 01:24:55 +08:00
zend_long SIZE , X , Y , COL ;
2008-06-22 06:07:53 +08:00
char * C ;
2014-08-27 21:31:48 +08:00
size_t C_len ;
1999-04-16 20:15:38 +08:00
gdImagePtr im ;
int ch = 0 , col , x , y , size , i , l = 0 ;
2000-02-09 06:21:43 +08:00
unsigned char * str = NULL ;
1999-04-16 20:15:38 +08:00
gdFontPtr font ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rlllsl " , & IM , & SIZE , & X , & Y , & C , & C_len , & COL ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
1999-04-16 20:15:38 +08:00
}
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
1999-04-16 20:15:38 +08:00
2008-06-22 06:07:53 +08:00
col = COL ;
1999-04-16 20:15:38 +08:00
if ( mode < 2 ) {
2008-06-22 06:07:53 +08:00
ch = ( int ) ( ( unsigned char ) * C ) ;
1999-04-16 20:15:38 +08:00
} else {
2008-06-22 06:07:53 +08:00
str = ( unsigned char * ) estrndup ( C , C_len ) ;
2006-08-08 19:56:36 +08:00
l = strlen ( ( char * ) str ) ;
1999-04-16 20:15:38 +08:00
}
2008-06-22 06:07:53 +08:00
y = Y ;
x = X ;
size = SIZE ;
1999-04-16 20:15:38 +08:00
2014-12-14 06:06:14 +08:00
font = php_find_gd_font ( size ) ;
1999-04-16 20:15:38 +08:00
2003-03-20 09:17:05 +08:00
switch ( mode ) {
2002-09-13 05:42:33 +08:00
case 0 :
1999-04-16 20:15:38 +08:00
gdImageChar ( im , font , x , y , ch , col ) ;
break ;
2002-09-13 05:42:33 +08:00
case 1 :
1999-12-18 05:50:07 +08:00
php_gdimagecharup ( im , font , x , y , ch , col ) ;
1999-04-16 20:15:38 +08:00
break ;
2002-09-13 05:42:33 +08:00
case 2 :
1999-04-16 20:15:38 +08:00
for ( i = 0 ; ( i < l ) ; i + + ) {
2003-03-20 09:12:57 +08:00
gdImageChar ( im , font , x , y , ( int ) ( ( unsigned char ) str [ i ] ) , col ) ;
1999-04-16 20:15:38 +08:00
x + = font - > w ;
}
break ;
2002-09-13 05:42:33 +08:00
case 3 : {
1999-04-16 20:15:38 +08:00
for ( i = 0 ; ( i < l ) ; i + + ) {
2003-03-20 09:12:57 +08:00
/* php_gdimagecharup(im, font, x, y, (int) str[i], col); */
gdImageCharUp ( im , font , x , y , ( int ) str [ i ] , col ) ;
1999-04-16 20:15:38 +08:00
y - = font - > w ;
}
break ;
}
}
2000-02-09 06:21:43 +08:00
if ( str ) {
efree ( str ) ;
1999-04-16 20:15:38 +08:00
}
RETURN_TRUE ;
2001-06-05 21:12:10 +08:00
}
/* }}} */
1999-04-16 20:15:38 +08:00
2003-06-15 23:29:46 +08:00
/* {{{ proto bool imagechar(resource im, int font, int x, int y, string c, int col)
2003-02-27 07:22:09 +08:00
Draw a character */
PHP_FUNCTION ( imagechar )
2000-11-23 22:56:09 +08:00
{
1999-12-18 05:50:07 +08:00
php_imagechar ( INTERNAL_FUNCTION_PARAM_PASSTHRU , 0 ) ;
1999-04-16 20:15:38 +08:00
}
/* }}} */
2003-06-15 23:29:46 +08:00
/* {{{ proto bool imagecharup(resource im, int font, int x, int y, string c, int col)
1999-11-25 06:04:49 +08:00
Draw a character rotated 90 degrees counter - clockwise */
2003-02-27 07:22:09 +08:00
PHP_FUNCTION ( imagecharup )
2000-11-23 22:56:09 +08:00
{
1999-12-18 05:50:07 +08:00
php_imagechar ( INTERNAL_FUNCTION_PARAM_PASSTHRU , 1 ) ;
1999-04-16 20:15:38 +08:00
}
/* }}} */
2003-06-15 23:29:46 +08:00
/* {{{ proto bool imagestring(resource im, int font, int x, int y, string str, int col)
1999-11-25 06:04:49 +08:00
Draw a string horizontally */
2003-02-27 07:22:09 +08:00
PHP_FUNCTION ( imagestring )
2000-11-23 22:56:09 +08:00
{
1999-12-18 05:50:07 +08:00
php_imagechar ( INTERNAL_FUNCTION_PARAM_PASSTHRU , 2 ) ;
1999-04-16 20:15:38 +08:00
}
/* }}} */
2003-06-15 23:29:46 +08:00
/* {{{ proto bool imagestringup(resource im, int font, int x, int y, string str, int col)
1999-11-25 06:04:49 +08:00
Draw a string vertically - rotated 90 degrees counter - clockwise */
2003-02-27 07:22:09 +08:00
PHP_FUNCTION ( imagestringup )
2000-11-23 22:56:09 +08:00
{
1999-12-18 05:50:07 +08:00
php_imagechar ( INTERNAL_FUNCTION_PARAM_PASSTHRU , 3 ) ;
1999-04-16 20:15:38 +08:00
}
/* }}} */
2003-06-15 23:29:46 +08: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-27 07:22:09 +08:00
Copy part of an image */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( imagecopy )
1999-04-16 20:15:38 +08:00
{
2008-06-22 06:07:53 +08:00
zval * SIM , * DIM ;
2014-08-26 01:24:55 +08:00
zend_long SX , SY , SW , SH , DX , DY ;
2000-11-23 22:56:09 +08:00
gdImagePtr im_dst , im_src ;
1999-04-16 20:15:38 +08:00
int srcH , srcW , srcY , srcX , dstY , dstX ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rrllllll " , & DIM , & SIM , & DX , & DY , & SX , & SY , & SW , & SH ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
1999-04-16 20:15:38 +08:00
}
2015-02-02 13:23:16 +08:00
if ( ( im_dst = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( DIM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
if ( ( im_src = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( SIM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2000-02-29 00:52:03 +08:00
2008-06-22 06:07:53 +08:00
srcX = SX ;
srcY = SY ;
srcH = SH ;
srcW = SW ;
dstX = DX ;
dstY = DY ;
1999-04-16 20:15:38 +08:00
gdImageCopy ( im_dst , im_src , dstX , dstY , srcX , srcY , srcW , srcH ) ;
RETURN_TRUE ;
}
/* }}} */
2003-06-15 23:29:46 +08: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 18:59:42 +08:00
Merge one part of an image with another */
2000-06-25 10:55:31 +08:00
PHP_FUNCTION ( imagecopymerge )
{
2008-06-22 06:07:53 +08:00
zval * SIM , * DIM ;
2014-08-26 01:24:55 +08:00
zend_long SX , SY , SW , SH , DX , DY , PCT ;
2000-11-23 22:56:09 +08:00
gdImagePtr im_dst , im_src ;
2000-06-25 10:55:31 +08:00
int srcH , srcW , srcY , srcX , dstY , dstX , pct ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rrlllllll " , & DIM , & SIM , & DX , & DY , & SX , & SY , & SW , & SH , & PCT ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
2000-06-25 10:55:31 +08:00
}
2015-02-02 13:23:16 +08:00
if ( ( im_dst = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( DIM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
if ( ( im_src = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( SIM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2000-06-25 10:55:31 +08:00
2008-06-22 06:07:53 +08:00
srcX = SX ;
srcY = SY ;
srcH = SH ;
srcW = SW ;
dstX = DX ;
dstY = DY ;
pct = PCT ;
2000-06-25 10:55:31 +08:00
gdImageCopyMerge ( im_dst , im_src , dstX , dstY , srcX , srcY , srcW , srcH , pct ) ;
RETURN_TRUE ;
}
2000-06-25 11:06:38 +08:00
/* }}} */
2000-06-25 10:55:31 +08:00
2003-06-15 23:29:46 +08: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 20:00:12 +08:00
Merge one part of an image with another */
PHP_FUNCTION ( imagecopymergegray )
{
2008-06-22 06:07:53 +08:00
zval * SIM , * DIM ;
2014-08-26 01:24:55 +08:00
zend_long SX , SY , SW , SH , DX , DY , PCT ;
2001-04-13 20:00:12 +08:00
gdImagePtr im_dst , im_src ;
int srcH , srcW , srcY , srcX , dstY , dstX , pct ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rrlllllll " , & DIM , & SIM , & DX , & DY , & SX , & SY , & SW , & SH , & PCT ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
2001-04-13 20:00:12 +08:00
}
2015-02-02 13:23:16 +08:00
if ( ( im_dst = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( DIM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
if ( ( im_src = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( SIM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2001-04-13 20:00:12 +08:00
2008-06-22 06:07:53 +08:00
srcX = SX ;
srcY = SY ;
srcH = SH ;
srcW = SW ;
dstX = DX ;
dstY = DY ;
pct = PCT ;
2001-04-13 20:00:12 +08:00
gdImageCopyMergeGray ( im_dst , im_src , dstX , dstY , srcX , srcY , srcW , srcH , pct ) ;
RETURN_TRUE ;
}
/* }}} */
2003-06-15 23:29:46 +08: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-25 06:04:49 +08:00
Copy and resize part of an image */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( imagecopyresized )
1999-04-16 20:15:38 +08:00
{
2008-06-22 06:07:53 +08:00
zval * SIM , * DIM ;
2014-08-26 01:24:55 +08:00
zend_long SX , SY , SW , SH , DX , DY , DW , DH ;
2000-11-23 22:56:09 +08:00
gdImagePtr im_dst , im_src ;
1999-04-16 20:15:38 +08:00
int srcH , srcW , dstH , dstW , srcY , srcX , dstY , dstX ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rrllllllll " , & DIM , & SIM , & DX , & DY , & SX , & SY , & DW , & DH , & SW , & SH ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
1999-04-16 20:15:38 +08:00
}
2015-02-02 13:23:16 +08:00
if ( ( im_dst = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( DIM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
if ( ( im_src = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( SIM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2000-02-29 00:52:03 +08:00
2008-06-22 06:07:53 +08:00
srcX = SX ;
srcY = SY ;
srcH = SH ;
srcW = SW ;
dstX = DX ;
dstY = DY ;
dstH = DH ;
dstW = DW ;
2003-12-29 05:08:46 +08:00
2003-04-04 09:33:57 +08:00
if ( dstW < = 0 | | dstH < = 0 | | srcW < = 0 | | srcH < = 0 ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Invalid image dimensions " ) ;
2003-04-04 08:16:47 +08:00
RETURN_FALSE ;
}
2000-11-23 22:56:09 +08:00
gdImageCopyResized ( im_dst , im_src , dstX , dstY , srcX , srcY , dstW , dstH , srcW , srcH ) ;
1999-04-16 20:15:38 +08:00
RETURN_TRUE ;
}
2003-02-27 07:22:09 +08:00
/* }}} */
1999-04-16 20:15:38 +08:00
2003-06-15 23:29:46 +08:00
/* {{{ proto int imagesx(resource im)
1999-11-25 06:04:49 +08:00
Get image width */
1999-07-28 03:44:46 +08:00
PHP_FUNCTION ( imagesx )
1999-04-16 20:15:38 +08:00
{
2008-06-22 06:07:53 +08:00
zval * IM ;
1999-04-16 20:15:38 +08:00
gdImagePtr im ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " r " , & IM ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
1999-04-16 20:15:38 +08:00
}
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
1999-04-16 20:15:38 +08:00
2014-08-26 01:24:55 +08:00
RETURN_LONG ( gdImageSX ( im ) ) ;
1999-04-16 20:15:38 +08:00
}
/* }}} */
2003-06-15 23:29:46 +08:00
/* {{{ proto int imagesy(resource im)
2000-01-25 04:25:57 +08:00
Get image height */
1999-07-28 03:44:46 +08:00
PHP_FUNCTION ( imagesy )
1999-04-16 20:15:38 +08:00
{
2008-06-22 06:07:53 +08:00
zval * IM ;
1999-04-16 20:15:38 +08:00
gdImagePtr im ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " r " , & IM ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
1999-04-16 20:15:38 +08:00
}
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
1999-04-16 20:15:38 +08:00
2014-08-26 01:24:55 +08:00
RETURN_LONG ( gdImageSY ( im ) ) ;
1999-04-16 20:15:38 +08:00
}
/* }}} */
1999-07-23 23:18:37 +08:00
# ifdef ENABLE_GD_TTF
1999-04-16 20:15:38 +08:00
# define TTFTEXT_DRAW 0
# define TTFTEXT_BBOX 1
2000-05-02 22:10:51 +08:00
# endif
1999-04-16 20:15:38 +08:00
2002-06-25 03:31:44 +08:00
# ifdef ENABLE_GD_TTF
2001-07-06 05:23:28 +08:00
2013-05-03 19:53:55 +08:00
# if HAVE_GD_FREETYPE && HAVE_LIBFREETYPE
2005-01-15 12:34:30 +08:00
/* {{{ proto array imageftbbox(float size, float angle, string font_file, string text [, array extrainfo])
2001-07-06 05:23:28 +08: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 12:34:30 +08: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-07 01:51:48 +08:00
Write text to the image using fonts via freetype2 */
2001-07-06 05:23:28 +08:00
PHP_FUNCTION ( imagefttext )
{
php_imagettftext_common ( INTERNAL_FUNCTION_PARAM_PASSTHRU , TTFTEXT_DRAW , 1 ) ;
}
/* }}} */
2013-05-03 19:53:55 +08:00
# endif /* HAVE_GD_FREETYPE && HAVE_LIBFREETYPE */
2001-07-06 05:23:28 +08:00
2005-01-15 12:34:30 +08:00
/* {{{ proto array imagettfbbox(float size, float angle, string font_file, string text)
1999-11-25 06:04:49 +08:00
Give the bounding box of a text using TrueType fonts */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( imagettfbbox )
1999-04-16 20:15:38 +08:00
{
2001-07-06 05:23:28 +08:00
php_imagettftext_common ( INTERNAL_FUNCTION_PARAM_PASSTHRU , TTFTEXT_BBOX , 0 ) ;
1999-04-16 20:15:38 +08:00
}
/* }}} */
2005-01-15 12:34:30 +08:00
/* {{{ proto array imagettftext(resource im, float size, float angle, int x, int y, int col, string font_file, string text)
1999-11-25 06:04:49 +08:00
Write text to the image using a TrueType font */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( imagettftext )
1999-04-16 20:15:38 +08:00
{
2001-07-06 05:23:28 +08:00
php_imagettftext_common ( INTERNAL_FUNCTION_PARAM_PASSTHRU , TTFTEXT_DRAW , 0 ) ;
1999-04-16 20:15:38 +08:00
}
/* }}} */
2001-06-05 21:12:10 +08:00
/* {{{ php_imagettftext_common
*/
2001-09-07 07:10:37 +08:00
static void php_imagettftext_common ( INTERNAL_FUNCTION_PARAMETERS , int mode , int extended )
1999-04-16 20:15:38 +08:00
{
2005-01-18 01:07:28 +08:00
zval * IM , * EXT = NULL ;
2000-05-24 16:58:40 +08:00
gdImagePtr im = NULL ;
2014-08-26 01:24:55 +08:00
zend_long col = - 1 , x = - 1 , y = - 1 ;
2014-08-27 21:31:48 +08:00
size_t str_len , fontname_len ;
int i , brect [ 8 ] ;
1999-04-16 20:15:38 +08:00
double ptsize , angle ;
2010-01-16 01:09:14 +08:00
char * str = NULL , * fontname = NULL ;
2003-01-25 03:23:53 +08:00
char * error = NULL ;
2005-01-18 01:07:28 +08:00
int argc = ZEND_NUM_ARGS ( ) ;
2003-12-26 06:12:12 +08:00
gdFTStringExtra strex = { 0 } ;
2003-02-27 07:22:09 +08:00
1999-04-16 20:15:38 +08:00
if ( mode = = TTFTEXT_BBOX ) {
2005-01-18 01:07:28 +08:00
if ( argc < 4 | | argc > ( ( extended ) ? 5 : 4 ) ) {
2001-07-31 01:29:57 +08:00
ZEND_WRONG_PARAM_COUNT ( ) ;
2014-12-14 06:06:14 +08:00
} else if ( zend_parse_parameters ( argc , " ddss|a " , & ptsize , & angle , & fontname , & fontname_len , & str , & str_len , & EXT ) = = FAILURE ) {
2005-01-18 01:07:28 +08:00
RETURN_FALSE ;
1999-04-16 20:15:38 +08:00
}
} else {
2005-01-18 01:07:28 +08:00
if ( argc < 8 | | argc > ( ( extended ) ? 9 : 8 ) ) {
2001-07-31 01:29:57 +08:00
ZEND_WRONG_PARAM_COUNT ( ) ;
2014-12-14 06:06:14 +08:00
} else if ( zend_parse_parameters ( argc , " rddlllss|a " , & IM , & ptsize , & angle , & x , & y , & col , & fontname , & fontname_len , & str , & str_len , & EXT ) = = FAILURE ) {
2005-01-18 01:07:28 +08:00
RETURN_FALSE ;
1999-04-16 20:15:38 +08:00
}
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
1999-04-16 20:15:38 +08:00
}
2005-01-18 01:07:28 +08:00
/* convert angle to radians */
angle = angle * ( M_PI / 180 ) ;
2001-07-06 05:23:28 +08:00
2005-01-18 01:07:28 +08:00
if ( extended & & EXT ) { /* parse extended info */
2014-05-12 15:53:35 +08:00
zval * item ;
zend_string * key ;
2003-02-27 07:22:09 +08:00
2005-01-15 12:34:30 +08:00
/* walk the assoc array */
2015-09-25 03:39:59 +08:00
ZEND_HASH_FOREACH_STR_KEY_VAL ( Z_ARRVAL_P ( EXT ) , key , item ) {
2014-05-12 15:53:35 +08:00
if ( key = = NULL ) {
2005-01-15 12:34:30 +08:00
continue ;
}
2015-06-30 09:05:24 +08:00
if ( strcmp ( " linespacing " , ZSTR_VAL ( key ) ) = = 0 ) {
2005-01-15 12:34:30 +08:00
strex . flags | = gdFTEX_LINESPACE ;
2014-10-10 18:23:33 +08:00
strex . linespacing = zval_get_double ( item ) ;
2005-01-15 12:34:30 +08:00
}
2014-05-12 15:53:35 +08:00
} ZEND_HASH_FOREACH_END ( ) ;
2005-01-15 12:34:30 +08:00
}
2003-02-27 07:22:09 +08:00
2001-07-20 19:25:13 +08:00
# ifdef VIRTUAL_DIR
2003-12-26 06:12:12 +08:00
{
char tmp_font_path [ MAXPATHLEN ] ;
2005-01-18 01:07:28 +08:00
2010-01-16 01:09:14 +08:00
if ( ! VCWD_REALPATH ( fontname , tmp_font_path ) ) {
2005-01-18 01:07:28 +08:00
fontname = NULL ;
2003-12-26 06:12:12 +08:00
}
2001-07-20 19:25:13 +08:00
}
2013-05-03 19:53:55 +08:00
# endif /* VIRTUAL_DIR */
2001-07-20 19:25:13 +08:00
2010-01-16 01:09:14 +08:00
PHP_GD_CHECK_OPEN_BASEDIR ( fontname , " Invalid font filename " ) ;
2015-01-03 17:22:58 +08:00
2013-05-03 19:53:55 +08:00
# ifdef HAVE_GD_FREETYPE
2003-03-20 09:12:57 +08:00
if ( extended ) {
2010-01-16 01:09:14 +08:00
error = gdImageStringFTEx ( im , brect , col , fontname , ptsize , angle , x , y , str , & strex ) ;
2001-07-06 05:23:28 +08:00
}
else
2013-05-03 19:53:55 +08:00
error = gdImageStringFT ( im , brect , col , fontname , ptsize , angle , x , y , str ) ;
2001-10-24 18:42:31 +08:00
2013-05-03 19:53:55 +08:00
# endif /* HAVE_GD_FREETYPE */
1999-04-16 20:15:38 +08:00
if ( error ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " %s " , error ) ;
1999-04-16 20:15:38 +08:00
RETURN_FALSE ;
}
2003-02-27 07:22:09 +08:00
2003-01-18 05:37:56 +08:00
array_init ( return_value ) ;
1999-04-16 20:15:38 +08:00
/* return array with the text's bounding box */
for ( i = 0 ; i < 8 ; i + + ) {
2014-08-26 01:24:55 +08:00
add_next_index_long ( return_value , brect [ i ] ) ;
1999-04-16 20:15:38 +08:00
}
}
2001-06-05 21:12:10 +08:00
/* }}} */
2000-02-25 14:43:51 +08:00
# endif /* ENABLE_GD_TTF */
2003-06-15 23:29:46 +08:00
/* {{{ proto bool image2wbmp(resource im [, string filename [, int threshold]])
2001-01-24 17:24:26 +08:00
Output WBMP image to browser or file */
PHP_FUNCTION ( image2wbmp )
{
2003-03-20 09:12:57 +08:00
_php_image_output ( INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GDIMG_CONVERT_WBM , " WBMP " , _php_image_bw_convert ) ;
2001-01-24 17:24:26 +08:00
}
2001-06-05 21:12:10 +08:00
/* }}} */
2001-01-24 17:24:26 +08:00
2013-05-03 19:53:55 +08:00
# if defined(HAVE_GD_JPG)
2003-06-15 23:29:46 +08:00
/* {{{ proto bool jpeg2wbmp (string f_org, string f_dest, int d_height, int d_width, int threshold)
2001-01-27 22:20:06 +08:00
Convert JPEG image to WBMP image */
2001-01-24 17:24:26 +08:00
PHP_FUNCTION ( jpeg2wbmp )
{
2003-03-20 09:12:57 +08:00
_php_image_convert ( INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GDIMG_TYPE_JPG ) ;
2001-01-24 17:24:26 +08:00
}
/* }}} */
2002-06-25 03:31:44 +08:00
# endif
2001-01-24 17:24:26 +08:00
2013-05-03 19:53:55 +08:00
# if defined(HAVE_GD_PNG)
2003-06-15 23:29:46 +08:00
/* {{{ proto bool png2wbmp (string f_org, string f_dest, int d_height, int d_width, int threshold)
2001-01-27 22:20:06 +08:00
Convert PNG image to WBMP image */
2001-01-24 17:24:26 +08:00
PHP_FUNCTION ( png2wbmp )
{
2003-03-20 09:12:57 +08:00
_php_image_convert ( INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GDIMG_TYPE_PNG ) ;
2001-01-24 17:24:26 +08:00
}
/* }}} */
2002-06-25 03:31:44 +08:00
# endif
2001-01-24 17:24:26 +08:00
2001-06-05 21:12:10 +08:00
/* {{{ _php_image_bw_convert
* It converts a gd Image to bw using a threshold value */
2003-03-20 09:12:57 +08:00
static void _php_image_bw_convert ( gdImagePtr im_org , gdIOCtx * out , int threshold )
2001-04-01 13:42:07 +08:00
{
2001-01-24 17:24:26 +08:00
gdImagePtr im_dest ;
int white , black ;
int color , color_org , median ;
2003-03-20 09:12:57 +08:00
int dest_height = gdImageSY ( im_org ) ;
int dest_width = gdImageSX ( im_org ) ;
2001-08-12 00:39:07 +08:00
int x , y ;
2003-02-27 07:22:09 +08:00
2003-03-20 09:12:57 +08:00
im_dest = gdImageCreate ( dest_width , dest_height ) ;
2001-01-24 17:24:26 +08:00
if ( im_dest = = NULL ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Unable to allocate temporary buffer " ) ;
2001-01-24 17:24:26 +08:00
return ;
}
2003-03-20 09:12:57 +08:00
white = gdImageColorAllocate ( im_dest , 255 , 255 , 255 ) ;
if ( white = = - 1 ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Unable to allocate the colors for the destination buffer " ) ;
2001-01-24 17:24:26 +08:00
return ;
}
2003-03-20 09:12:57 +08:00
black = gdImageColorAllocate ( im_dest , 0 , 0 , 0 ) ;
2001-01-24 17:24:26 +08:00
if ( black = = - 1 ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Unable to allocate the colors for the destination buffer " ) ;
2001-01-24 17:24:26 +08:00
return ;
}
2004-02-18 05:30:00 +08:00
if ( im_org - > trueColor ) {
gdImageTrueColorToPalette ( im_org , 1 , 256 ) ;
}
2001-01-24 17:24:26 +08:00
for ( y = 0 ; y < dest_height ; y + + ) {
for ( x = 0 ; x < dest_width ; x + + ) {
2003-03-20 09:12:57 +08:00
color_org = gdImageGetPixel ( im_org , x , y ) ;
2001-01-24 17:24:26 +08: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 09:12:57 +08:00
} else {
2001-01-24 17:24:26 +08:00
color = white ;
}
gdImageSetPixel ( im_dest , x , y , color ) ;
}
}
2001-04-01 13:42:07 +08:00
gdImageWBMPCtx ( im_dest , black , out ) ;
2001-01-24 17:24:26 +08:00
2001-04-01 13:42:07 +08:00
}
2001-06-05 21:12:10 +08:00
/* }}} */
2001-01-24 17:24:26 +08:00
2001-06-05 21:12:10 +08:00
/* {{{ _php_image_convert
* _php_image_convert converts jpeg / png images to wbmp and resizes them as needed */
2003-02-27 07:22:09 +08:00
static void _php_image_convert ( INTERNAL_FUNCTION_PARAMETERS , int image_type )
2001-06-07 21:17:02 +08:00
{
2008-06-22 06:07:53 +08:00
char * f_org , * f_dest ;
2014-08-27 21:31:48 +08:00
size_t f_org_len , f_dest_len ;
2014-08-26 01:24:55 +08:00
zend_long height , width , threshold ;
2001-01-24 17:24:26 +08:00
gdImagePtr im_org , im_dest , im_tmp ;
char * fn_org = NULL ;
char * fn_dest = NULL ;
2001-08-12 00:39:07 +08:00
FILE * org , * dest ;
2001-01-24 17:24:26 +08: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 ;
2014-05-12 15:53:35 +08:00
# ifdef HAVE_GD_JPG
2014-08-26 01:24:55 +08:00
zend_long ignore_warning ;
2014-05-12 15:53:35 +08:00
# endif
2015-01-03 17:22:58 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " pplll " , & f_org , & f_org_len , & f_dest , & f_dest_len , & height , & width , & threshold ) = = FAILURE ) {
2008-06-22 06:07:53 +08:00
return ;
2001-01-24 17:24:26 +08:00
}
2008-06-22 06:07:53 +08:00
fn_org = f_org ;
fn_dest = f_dest ;
dest_height = height ;
dest_width = width ;
int_threshold = threshold ;
2002-01-02 09:25:48 +08:00
/* Check threshold value */
2003-03-20 09:12:57 +08:00
if ( int_threshold < 0 | | int_threshold > 8 ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Invalid threshold value '%d' " , int_threshold ) ;
2002-01-02 09:25:48 +08:00
RETURN_FALSE ;
}
2001-01-24 17:24:26 +08:00
2002-01-02 09:25:48 +08:00
/* Check origin file */
2005-11-02 01:05:09 +08:00
PHP_GD_CHECK_OPEN_BASEDIR ( fn_org , " Invalid origin filename " ) ;
2001-01-24 17:24:26 +08:00
2002-01-02 09:25:48 +08:00
/* Check destination file */
2005-11-02 01:05:09 +08:00
PHP_GD_CHECK_OPEN_BASEDIR ( fn_dest , " Invalid destination filename " ) ;
2001-01-24 17:24:26 +08:00
2002-01-02 09:25:48 +08:00
/* Open origin file */
org = VCWD_FOPEN ( fn_org , " rb " ) ;
if ( ! org ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Unable to open '%s' for reading " , fn_org ) ;
2002-01-02 09:25:48 +08:00
RETURN_FALSE ;
}
2001-01-24 17:24:26 +08:00
2002-01-02 09:25:48 +08:00
/* Open destination file */
dest = VCWD_FOPEN ( fn_dest , " wb " ) ;
if ( ! dest ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Unable to open '%s' for writing " , fn_dest ) ;
2002-01-02 09:25:48 +08:00
RETURN_FALSE ;
}
2001-01-24 17:24:26 +08:00
2002-01-02 09:25:48 +08:00
switch ( image_type ) {
case PHP_GDIMG_TYPE_GIF :
2003-03-20 09:12:57 +08:00
im_org = gdImageCreateFromGif ( org ) ;
2002-01-02 09:25:48 +08:00
if ( im_org = = NULL ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Unable to open '%s' Not a valid GIF file " , fn_dest ) ;
2002-01-02 09:25:48 +08:00
RETURN_FALSE ;
}
break ;
2001-02-10 05:14:30 +08:00
# ifdef HAVE_GD_JPG
2002-01-02 09:25:48 +08:00
case PHP_GDIMG_TYPE_JPG :
2006-02-05 23:53:58 +08:00
ignore_warning = INI_INT ( " gd.jpeg_ignore_warning " ) ;
2013-04-24 22:07:50 +08:00
im_org = gdImageCreateFromJpegEx ( org , ignore_warning ) ;
2002-01-02 09:25:48 +08:00
if ( im_org = = NULL ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Unable to open '%s' Not a valid JPEG file " , fn_dest ) ;
2002-01-02 09:25:48 +08:00
RETURN_FALSE ;
}
break ;
2001-02-10 05:14:30 +08:00
# endif /* HAVE_GD_JPG */
# ifdef HAVE_GD_PNG
2002-01-02 09:25:48 +08:00
case PHP_GDIMG_TYPE_PNG :
im_org = gdImageCreateFromPng ( org ) ;
if ( im_org = = NULL ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Unable to open '%s' Not a valid PNG file " , fn_dest ) ;
2002-01-02 09:25:48 +08:00
RETURN_FALSE ;
}
break ;
2001-02-10 05:14:30 +08:00
# endif /* HAVE_GD_PNG */
2002-01-02 09:25:48 +08:00
default :
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Format not supported " ) ;
2002-01-02 09:25:48 +08:00
RETURN_FALSE ;
break ;
}
2001-01-24 17:24:26 +08:00
2002-01-02 09:25:48 +08:00
org_width = gdImageSX ( im_org ) ;
org_height = gdImageSY ( im_org ) ;
2001-01-24 17:24:26 +08:00
2002-01-02 09:25:48 +08:00
x_ratio = ( float ) org_width / ( float ) dest_width ;
y_ratio = ( float ) org_height / ( float ) dest_height ;
2001-01-24 17:24:26 +08:00
2002-01-02 09:25:48 +08:00
if ( x_ratio > 1 & & y_ratio > 1 ) {
if ( y_ratio > x_ratio ) {
x_ratio = y_ratio ;
2003-03-20 09:12:57 +08:00
} else {
2002-01-02 09:25:48 +08:00
y_ratio = x_ratio ;
2001-01-24 17:24:26 +08:00
}
2003-03-20 09:12:57 +08:00
dest_width = ( int ) ( org_width / x_ratio ) ;
dest_height = ( int ) ( org_height / y_ratio ) ;
} else {
2002-01-02 09:25:48 +08:00
x_ratio = ( float ) dest_width / ( float ) org_width ;
y_ratio = ( float ) dest_height / ( float ) org_height ;
2001-01-24 17:24:26 +08:00
2002-01-02 09:25:48 +08:00
if ( y_ratio < x_ratio ) {
x_ratio = y_ratio ;
2003-03-20 09:12:57 +08:00
} else {
2002-01-02 09:25:48 +08:00
y_ratio = x_ratio ;
}
2003-03-20 09:12:57 +08:00
dest_width = ( int ) ( org_width * x_ratio ) ;
dest_height = ( int ) ( org_height * y_ratio ) ;
2002-01-02 09:25:48 +08:00
}
2001-01-24 17:24:26 +08:00
2002-01-02 09:25:48 +08:00
im_tmp = gdImageCreate ( dest_width , dest_height ) ;
if ( im_tmp = = NULL ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Unable to allocate temporary buffer " ) ;
2002-01-02 09:25:48 +08:00
RETURN_FALSE ;
}
2001-01-24 17:24:26 +08:00
2002-01-02 09:25:48 +08:00
gdImageCopyResized ( im_tmp , im_org , 0 , 0 , 0 , 0 , dest_width , dest_height , org_width , org_height ) ;
2001-01-24 17:24:26 +08:00
2002-01-02 09:25:48 +08:00
gdImageDestroy ( im_org ) ;
2001-01-24 17:24:26 +08:00
2002-01-02 09:25:48 +08:00
fclose ( org ) ;
2001-01-24 17:24:26 +08:00
2002-01-02 09:25:48 +08:00
im_dest = gdImageCreate ( dest_width , dest_height ) ;
if ( im_dest = = NULL ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Unable to allocate destination buffer " ) ;
2002-01-02 09:25:48 +08:00
RETURN_FALSE ;
}
2003-03-20 09:12:57 +08:00
2002-01-02 09:25:48 +08:00
white = gdImageColorAllocate ( im_dest , 255 , 255 , 255 ) ;
if ( white = = - 1 ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Unable to allocate the colors for the destination buffer " ) ;
2002-01-02 09:25:48 +08:00
RETURN_FALSE ;
}
2001-01-24 17:24:26 +08:00
2002-01-02 09:25:48 +08:00
black = gdImageColorAllocate ( im_dest , 0 , 0 , 0 ) ;
if ( black = = - 1 ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Unable to allocate the colors for the destination buffer " ) ;
2002-01-02 09:25:48 +08:00
RETURN_FALSE ;
}
2001-01-24 17:24:26 +08:00
2002-01-02 09:25:48 +08:00
int_threshold = int_threshold * 32 ;
for ( y = 0 ; y < dest_height ; y + + ) {
2003-03-20 09:12:57 +08:00
for ( x = 0 ; x < dest_width ; x + + ) {
2002-01-02 09:25:48 +08: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 09:12:57 +08:00
} else {
2002-01-02 09:25:48 +08:00
color = white ;
2001-01-24 17:24:26 +08:00
}
2002-01-02 09:25:48 +08:00
gdImageSetPixel ( im_dest , x , y , color ) ;
2001-01-24 17:24:26 +08:00
}
2002-01-02 09:25:48 +08:00
}
2001-01-24 17:24:26 +08:00
2002-01-02 09:25:48 +08:00
gdImageDestroy ( im_tmp ) ;
2001-01-24 17:24:26 +08:00
2003-03-20 09:12:57 +08:00
gdImageWBMP ( im_dest , black , dest ) ;
2001-01-24 17:24:26 +08:00
2002-01-02 09:25:48 +08:00
fflush ( dest ) ;
fclose ( dest ) ;
2001-01-24 17:24:26 +08:00
2003-03-20 09:12:57 +08:00
gdImageDestroy ( im_dest ) ;
2003-02-27 07:22:09 +08:00
2002-01-02 09:25:48 +08:00
RETURN_TRUE ;
2001-01-24 17:24:26 +08:00
}
2001-06-05 21:12:10 +08:00
/* }}} */
1999-04-16 20:15:38 +08:00
2002-11-14 04:02:58 +08:00
/* Section Filters */
2004-05-10 01:39:20 +08:00
# define PHP_GD_SINGLE_RES \
2008-08-05 02:23:33 +08:00
zval * SIM ; \
2004-05-10 01:39:20 +08:00
gdImagePtr im_src ; \
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( 1 , " r " , & SIM ) = = FAILURE ) { \
2004-05-10 01:39:20 +08:00
RETURN_FALSE ; \
} \
2015-02-02 13:23:16 +08:00
if ( ( im_src = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( SIM ) , " Image " , le_gd ) ) = = NULL ) { \
2004-05-10 01:39:20 +08:00
RETURN_FALSE ; \
2003-02-27 07:22:09 +08:00
}
2002-11-14 04:02:58 +08:00
2004-05-10 01:39:20 +08:00
static void php_image_filter_negate ( INTERNAL_FUNCTION_PARAMETERS )
{
PHP_GD_SINGLE_RES
2003-03-20 09:12:57 +08:00
if ( gdImageNegate ( im_src ) = = 1 ) {
2002-11-14 04:02:58 +08:00
RETURN_TRUE ;
}
2003-03-20 09:12:57 +08:00
2002-11-14 04:02:58 +08:00
RETURN_FALSE ;
}
static void php_image_filter_grayscale ( INTERNAL_FUNCTION_PARAMETERS )
{
2004-05-10 01:39:20 +08:00
PHP_GD_SINGLE_RES
2003-03-20 09:12:57 +08:00
if ( gdImageGrayScale ( im_src ) = = 1 ) {
2002-11-14 04:02:58 +08:00
RETURN_TRUE ;
}
2003-03-20 09:12:57 +08:00
2002-11-14 04:02:58 +08:00
RETURN_FALSE ;
}
static void php_image_filter_brightness ( INTERNAL_FUNCTION_PARAMETERS )
{
zval * SIM ;
gdImagePtr im_src ;
2014-08-26 01:24:55 +08:00
zend_long brightness , tmp ;
2002-11-14 04:02:58 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " zll " , & SIM , & tmp , & brightness ) = = FAILURE ) {
2004-05-10 01:39:20 +08:00
RETURN_FALSE ;
2003-02-27 07:22:09 +08:00
}
2002-11-14 04:02:58 +08:00
2015-02-02 13:23:16 +08:00
if ( ( im_src = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( SIM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2003-03-20 09:12:57 +08:00
if ( im_src = = NULL ) {
2002-11-14 04:02:58 +08:00
RETURN_FALSE ;
}
2003-03-20 09:12:57 +08:00
if ( gdImageBrightness ( im_src , ( int ) brightness ) = = 1 ) {
2002-11-14 04:02:58 +08:00
RETURN_TRUE ;
}
2003-03-20 09:12:57 +08:00
2002-11-14 04:02:58 +08:00
RETURN_FALSE ;
}
static void php_image_filter_contrast ( INTERNAL_FUNCTION_PARAMETERS )
{
zval * SIM ;
gdImagePtr im_src ;
2014-08-26 01:24:55 +08:00
zend_long contrast , tmp ;
2003-02-27 07:22:09 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rll " , & SIM , & tmp , & contrast ) = = FAILURE ) {
2004-05-10 01:39:20 +08:00
RETURN_FALSE ;
2003-02-27 07:22:09 +08:00
}
2002-11-14 04:02:58 +08:00
2015-02-02 13:23:16 +08:00
if ( ( im_src = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( SIM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2003-03-20 09:12:57 +08:00
if ( im_src = = NULL ) {
2002-11-14 04:02:58 +08:00
RETURN_FALSE ;
}
2003-03-20 09:12:57 +08:00
2004-05-10 01:39:20 +08:00
if ( gdImageContrast ( im_src , ( int ) contrast ) = = 1 ) {
2002-11-14 04:02:58 +08:00
RETURN_TRUE ;
}
2003-03-20 09:12:57 +08:00
2002-11-14 04:02:58 +08:00
RETURN_FALSE ;
}
static void php_image_filter_colorize ( INTERNAL_FUNCTION_PARAMETERS )
{
zval * SIM ;
gdImagePtr im_src ;
2014-08-26 01:24:55 +08:00
zend_long r , g , b , tmp ;
zend_long a = 0 ;
2002-11-14 04:02:58 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rllll|l " , & SIM , & tmp , & r , & g , & b , & a ) = = FAILURE ) {
2004-05-10 01:39:20 +08:00
RETURN_FALSE ;
2003-02-27 07:22:09 +08:00
}
2002-11-14 04:02:58 +08:00
2015-02-02 13:23:16 +08:00
if ( ( im_src = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( SIM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2003-03-20 09:12:57 +08:00
if ( im_src = = NULL ) {
2002-11-14 04:02:58 +08:00
RETURN_FALSE ;
}
2003-03-20 09:12:57 +08:00
2007-09-12 05:03:48 +08:00
if ( gdImageColor ( im_src , ( int ) r , ( int ) g , ( int ) b , ( int ) a ) = = 1 ) {
2002-11-14 04:02:58 +08:00
RETURN_TRUE ;
}
2003-03-20 09:12:57 +08:00
2002-11-14 04:02:58 +08:00
RETURN_FALSE ;
}
static void php_image_filter_edgedetect ( INTERNAL_FUNCTION_PARAMETERS )
{
2004-05-10 01:39:20 +08:00
PHP_GD_SINGLE_RES
2003-03-20 09:12:57 +08:00
if ( gdImageEdgeDetectQuick ( im_src ) = = 1 ) {
2002-11-14 04:02:58 +08:00
RETURN_TRUE ;
}
2003-03-20 09:12:57 +08:00
2002-11-14 04:02:58 +08:00
RETURN_FALSE ;
}
static void php_image_filter_emboss ( INTERNAL_FUNCTION_PARAMETERS )
{
2004-05-10 01:39:20 +08:00
PHP_GD_SINGLE_RES
2003-03-20 09:12:57 +08:00
if ( gdImageEmboss ( im_src ) = = 1 ) {
2002-11-14 04:02:58 +08:00
RETURN_TRUE ;
}
2003-03-20 09:12:57 +08:00
2002-11-14 04:02:58 +08:00
RETURN_FALSE ;
}
static void php_image_filter_gaussian_blur ( INTERNAL_FUNCTION_PARAMETERS )
{
2004-05-10 01:39:20 +08:00
PHP_GD_SINGLE_RES
2003-03-20 09:12:57 +08:00
if ( gdImageGaussianBlur ( im_src ) = = 1 ) {
2002-11-14 04:02:58 +08:00
RETURN_TRUE ;
}
2003-03-20 09:12:57 +08:00
2002-11-14 04:02:58 +08:00
RETURN_FALSE ;
}
static void php_image_filter_selective_blur ( INTERNAL_FUNCTION_PARAMETERS )
{
2004-05-10 01:39:20 +08:00
PHP_GD_SINGLE_RES
2003-03-20 09:12:57 +08:00
if ( gdImageSelectiveBlur ( im_src ) = = 1 ) {
2002-11-14 04:02:58 +08:00
RETURN_TRUE ;
}
2003-03-20 09:12:57 +08:00
2002-11-14 04:02:58 +08:00
RETURN_FALSE ;
}
static void php_image_filter_mean_removal ( INTERNAL_FUNCTION_PARAMETERS )
{
2004-05-10 01:39:20 +08:00
PHP_GD_SINGLE_RES
2003-03-20 09:12:57 +08:00
if ( gdImageMeanRemoval ( im_src ) = = 1 ) {
2002-11-14 04:02:58 +08:00
RETURN_TRUE ;
}
2003-03-20 09:12:57 +08:00
2002-11-14 04:02:58 +08:00
RETURN_FALSE ;
}
static void php_image_filter_smooth ( INTERNAL_FUNCTION_PARAMETERS )
{
zval * SIM ;
2014-08-26 01:24:55 +08:00
zend_long tmp ;
2002-11-14 04:02:58 +08:00
gdImagePtr im_src ;
double weight ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rld " , & SIM , & tmp , & weight ) = = FAILURE ) {
2004-05-10 01:39:20 +08:00
RETURN_FALSE ;
2003-02-27 07:22:09 +08:00
}
2002-11-14 04:02:58 +08:00
2015-02-02 13:23:16 +08:00
if ( ( im_src = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( SIM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2003-03-20 09:12:57 +08:00
if ( im_src = = NULL ) {
2002-11-14 04:02:58 +08:00
RETURN_FALSE ;
}
2003-03-20 09:12:57 +08:00
2002-11-29 06:48:20 +08:00
if ( gdImageSmooth ( im_src , ( float ) weight ) = = 1 ) {
2002-11-14 04:02:58 +08:00
RETURN_TRUE ;
}
2003-03-20 09:12:57 +08:00
2002-11-14 04:02:58 +08:00
RETURN_FALSE ;
}
2009-01-15 03:06:12 +08:00
static void php_image_filter_pixelate ( INTERNAL_FUNCTION_PARAMETERS )
{
zval * IM ;
gdImagePtr im ;
2014-08-26 01:24:55 +08:00
zend_long tmp , blocksize ;
2009-01-15 15:57:11 +08:00
zend_bool mode = 0 ;
2009-01-15 03:06:12 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rll|b " , & IM , & tmp , & blocksize , & mode ) = = FAILURE ) {
2009-01-15 03:06:12 +08:00
RETURN_FALSE ;
}
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2009-01-15 03:06:12 +08:00
if ( im = = NULL ) {
RETURN_FALSE ;
}
if ( gdImagePixelate ( im , ( int ) blocksize , ( const unsigned int ) mode ) ) {
RETURN_TRUE ;
}
RETURN_FALSE ;
}
2015-06-24 05:46:07 +08:00
/* {{{ proto bool imagefilter(resource src_im, int filtertype[, int arg1 [, int arg2 [, int arg3 [, int arg4 ]]]] )
2002-11-14 04:02:58 +08:00
Applies Filter an image using a custom angle */
PHP_FUNCTION ( imagefilter )
{
zval * tmp ;
typedef void ( * image_filter ) ( INTERNAL_FUNCTION_PARAMETERS ) ;
2014-08-26 01:24:55 +08:00
zend_long filtertype ;
2003-02-27 07:22:09 +08:00
image_filter filters [ ] =
2002-11-14 04:02:58 +08: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 ,
2009-01-15 03:06:12 +08:00
php_image_filter_smooth ,
php_image_filter_pixelate
2002-11-14 04:02:58 +08:00
} ;
2009-01-20 00:35:58 +08:00
if ( ZEND_NUM_ARGS ( ) < 2 | | ZEND_NUM_ARGS ( ) > IMAGE_FILTER_MAX_ARGS ) {
2006-11-03 23:13:17 +08:00
WRONG_PARAM_COUNT ;
2014-12-14 06:06:14 +08:00
} else if ( zend_parse_parameters ( 2 , " rl " , & tmp , & filtertype ) = = FAILURE ) {
2006-11-03 23:13:17 +08:00
return ;
2003-02-27 07:22:09 +08:00
}
2002-11-14 04:02:58 +08:00
2003-03-20 09:12:57 +08:00
if ( filtertype > = 0 & & filtertype < = IMAGE_FILTER_MAX ) {
2002-11-14 04:02:58 +08:00
filters [ filtertype ] ( INTERNAL_FUNCTION_PARAM_PASSTHRU ) ;
}
}
/* }}} */
2005-04-16 20:12:24 +08: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 ;
2014-05-12 15:53:35 +08:00
zval * var = NULL , * var2 = NULL ;
2005-04-16 20:12:24 +08:00
gdImagePtr im_src = NULL ;
2005-10-26 07:00:19 +08:00
double div , offset ;
2005-04-16 20:12:24 +08:00
int nelem , i , j , res ;
2005-04-17 18:17:03 +08:00
float matrix [ 3 ] [ 3 ] = { { 0 , 0 , 0 } , { 0 , 0 , 0 } , { 0 , 0 , 0 } } ;
2005-04-16 20:12:24 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " radd " , & SIM , & hash_matrix , & div , & offset ) = = FAILURE ) {
2005-04-16 20:12:24 +08:00
RETURN_FALSE ;
}
2015-02-02 13:23:16 +08:00
if ( ( im_src = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( SIM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2005-04-16 20:12:24 +08:00
nelem = zend_hash_num_elements ( Z_ARRVAL_P ( hash_matrix ) ) ;
if ( nelem ! = 3 ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " You must have 3x3 array " ) ;
2005-04-16 20:12:24 +08:00
RETURN_FALSE ;
}
for ( i = 0 ; i < 3 ; i + + ) {
2014-05-12 15:53:35 +08:00
if ( ( var = zend_hash_index_find ( Z_ARRVAL_P ( hash_matrix ) , ( i ) ) ) ! = NULL & & Z_TYPE_P ( var ) = = IS_ARRAY ) {
if ( zend_hash_num_elements ( Z_ARRVAL_P ( var ) ) ! = 3 ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " You must have 3x3 array " ) ;
2005-04-16 20:12:24 +08:00
RETURN_FALSE ;
}
for ( j = 0 ; j < 3 ; j + + ) {
2014-10-10 18:23:33 +08:00
if ( ( var2 = zend_hash_index_find ( Z_ARRVAL_P ( var ) , j ) ) ! = NULL ) {
matrix [ i ] [ j ] = ( float ) zval_get_double ( var2 ) ;
2005-04-16 20:12:24 +08:00
} else {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " You must have a 3x3 matrix " ) ;
2005-04-16 20:12:24 +08:00
RETURN_FALSE ;
}
}
}
}
2013-02-27 17:39:25 +08:00
res = gdImageConvolution ( im_src , matrix , ( float ) div , ( float ) offset ) ;
2005-04-16 20:12:24 +08:00
if ( res ) {
RETURN_TRUE ;
} else {
RETURN_FALSE ;
}
}
/* }}} */
2002-12-12 06:25:23 +08:00
/* End section: Filters */
2002-12-12 04:44:44 +08:00
2013-02-27 17:39:25 +08:00
/* {{{ proto void imageflip(resource im, int mode)
Flip an image ( in place ) horizontally , vertically or both directions . */
PHP_FUNCTION ( imageflip )
{
zval * IM ;
2014-08-26 01:24:55 +08:00
zend_long mode ;
2013-02-27 17:39:25 +08:00
gdImagePtr im ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rl " , & IM , & mode ) = = FAILURE ) {
2013-02-27 17:39:25 +08:00
return ;
}
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2013-02-27 17:39:25 +08:00
switch ( mode ) {
case GD_FLIP_VERTICAL :
2013-03-20 14:46:59 +08:00
gdImageFlipVertical ( im ) ;
2013-02-27 17:39:25 +08:00
break ;
case GD_FLIP_HORINZONTAL :
2013-03-20 14:46:59 +08:00
gdImageFlipHorizontal ( im ) ;
2013-02-27 17:39:25 +08:00
break ;
case GD_FLIP_BOTH :
gdImageFlipBoth ( im ) ;
break ;
default :
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Unknown flip mode " ) ;
2013-02-27 17:39:25 +08:00
RETURN_FALSE ;
}
RETURN_TRUE ;
}
/* }}} */
2013-04-24 20:32:03 +08:00
# ifdef HAVE_GD_BUNDLED
/* {{{ proto bool imageantialias(resource im, bool on)
Should antialiased functions used or not */
PHP_FUNCTION ( imageantialias )
{
zval * IM ;
zend_bool alias ;
gdImagePtr im ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rb " , & IM , & alias ) = = FAILURE ) {
2013-04-24 20:32:03 +08:00
return ;
}
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2013-04-24 20:32:03 +08:00
gdImageAntialias ( im , alias ) ;
RETURN_TRUE ;
}
/* }}} */
2013-04-25 19:39:35 +08:00
# endif
2013-03-01 00:24:23 +08:00
2013-03-01 15:10:49 +08:00
/* {{{ proto void imagecrop(resource im, array rect)
Crop an image using the given coordinates and size , x , y , width and height . */
PHP_FUNCTION ( imagecrop )
{
zval * IM ;
gdImagePtr im ;
gdImagePtr im_crop ;
gdRect rect ;
2013-03-03 12:30:12 +08:00
zval * z_rect ;
2014-05-12 15:53:35 +08:00
zval * tmp ;
2013-03-01 00:24:23 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " ra " , & IM , & z_rect ) = = FAILURE ) {
2013-03-01 15:10:49 +08:00
return ;
}
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2013-03-01 15:10:49 +08:00
2015-09-25 03:39:59 +08:00
if ( ( tmp = zend_hash_str_find ( Z_ARRVAL_P ( z_rect ) , " x " , sizeof ( " x " ) - 1 ) ) ! = NULL ) {
2014-10-10 18:23:33 +08:00
rect . x = zval_get_long ( tmp ) ;
2013-03-01 15:10:49 +08:00
} else {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Missing x position " ) ;
2013-03-01 15:10:49 +08:00
RETURN_FALSE ;
}
2015-09-25 03:39:59 +08:00
if ( ( tmp = zend_hash_str_find ( Z_ARRVAL_P ( z_rect ) , " y " , sizeof ( " y " ) - 1 ) ) ! = NULL ) {
2014-10-10 18:23:33 +08:00
rect . y = zval_get_long ( tmp ) ;
2013-03-01 15:10:49 +08:00
} else {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Missing y position " ) ;
2013-03-01 15:10:49 +08:00
RETURN_FALSE ;
}
2015-09-25 03:39:59 +08:00
if ( ( tmp = zend_hash_str_find ( Z_ARRVAL_P ( z_rect ) , " width " , sizeof ( " width " ) - 1 ) ) ! = NULL ) {
2014-10-10 18:23:33 +08:00
rect . width = zval_get_long ( tmp ) ;
2013-03-01 15:10:49 +08:00
} else {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Missing width " ) ;
2013-03-01 15:10:49 +08:00
RETURN_FALSE ;
}
2015-09-25 03:39:59 +08:00
if ( ( tmp = zend_hash_str_find ( Z_ARRVAL_P ( z_rect ) , " height " , sizeof ( " height " ) - 1 ) ) ! = NULL ) {
2014-10-10 18:23:33 +08:00
rect . height = zval_get_long ( tmp ) ;
2013-03-01 15:10:49 +08:00
} else {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Missing height " ) ;
2013-03-01 15:10:49 +08:00
RETURN_FALSE ;
}
im_crop = gdImageCrop ( im , & rect ) ;
if ( im_crop = = NULL ) {
RETURN_FALSE ;
} else {
2015-02-02 13:23:16 +08:00
RETURN_RES ( zend_register_resource ( im_crop , le_gd ) ) ;
2013-03-01 15:10:49 +08:00
}
}
/* }}} */
2015-06-24 05:46:07 +08:00
/* {{{ proto void imagecropauto(resource im [, int mode [, float threshold [, int color]]])
2013-03-01 15:10:49 +08:00
Crop an image automatically using one of the available modes . */
2013-03-01 00:24:23 +08:00
PHP_FUNCTION ( imagecropauto )
{
zval * IM ;
2014-08-26 01:24:55 +08:00
zend_long mode = - 1 ;
zend_long color = - 1 ;
2013-03-01 02:22:06 +08:00
double threshold = 0.5f ;
2013-03-01 00:24:23 +08:00
gdImagePtr im ;
gdImagePtr im_crop ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " r|ldl " , & IM , & mode , & threshold , & color ) = = FAILURE ) {
2013-03-01 00:24:23 +08:00
return ;
}
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2013-03-01 00:24:23 +08:00
switch ( mode ) {
case - 1 :
mode = GD_CROP_DEFAULT ;
case GD_CROP_DEFAULT :
case GD_CROP_TRANSPARENT :
case GD_CROP_BLACK :
case GD_CROP_WHITE :
case GD_CROP_SIDES :
im_crop = gdImageCropAuto ( im , mode ) ;
break ;
2013-03-03 12:30:12 +08:00
2013-03-01 02:22:06 +08:00
case GD_CROP_THRESHOLD :
if ( color < 0 ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Color argument missing with threshold mode " ) ;
2013-03-01 02:22:06 +08:00
RETURN_FALSE ;
}
im_crop = gdImageCropThreshold ( im , color , ( float ) threshold ) ;
break ;
2013-03-03 12:30:12 +08:00
2013-03-01 00:24:23 +08:00
default :
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Unknown crop mode " ) ;
2013-03-01 00:24:23 +08:00
RETURN_FALSE ;
}
if ( im_crop = = NULL ) {
RETURN_FALSE ;
} else {
2015-02-02 13:23:16 +08:00
RETURN_RES ( zend_register_resource ( im_crop , le_gd ) ) ;
2013-03-01 00:24:23 +08:00
}
}
/* }}} */
2013-03-20 14:46:59 +08:00
2015-06-24 05:46:07 +08:00
/* {{{ proto resource imagescale(resource im, int new_width[, int new_height[, int method]])
2013-04-24 20:42:51 +08:00
Scale an image using the given new width and height . */
2013-03-20 14:46:59 +08:00
PHP_FUNCTION ( imagescale )
{
zval * IM ;
gdImagePtr im ;
2014-03-12 22:33:41 +08:00
gdImagePtr im_scaled = NULL ;
2014-03-12 20:44:58 +08:00
int new_width , new_height ;
2014-08-26 01:24:55 +08:00
zend_long tmp_w , tmp_h = - 1 , tmp_m = GD_BILINEAR_FIXED ;
2014-03-12 20:44:58 +08:00
gdInterpolationMethod method ;
2013-03-20 14:46:59 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " rl|ll " , & IM , & tmp_w , & tmp_h , & tmp_m ) = = FAILURE ) {
2013-03-20 14:46:59 +08:00
return ;
}
2014-03-12 20:44:58 +08:00
method = tmp_m ;
2013-03-20 14:46:59 +08:00
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2013-03-20 14:46:59 +08:00
2014-10-16 01:13:25 +08:00
if ( tmp_h < 0 ) {
/* preserve ratio */
long src_x , src_y ;
src_x = gdImageSX ( im ) ;
src_y = gdImageSY ( im ) ;
if ( src_x ) {
tmp_h = tmp_w * src_y / src_x ;
}
}
new_width = tmp_w ;
new_height = tmp_h ;
2014-03-12 22:33:41 +08:00
if ( gdImageSetInterpolationMethod ( im , method ) ) {
im_scaled = gdImageScale ( im , new_width , new_height ) ;
2013-03-20 14:46:59 +08:00
}
2014-03-12 22:33:41 +08:00
2013-03-20 14:46:59 +08:00
if ( im_scaled = = NULL ) {
RETURN_FALSE ;
} else {
2015-02-02 13:23:16 +08:00
RETURN_RES ( zend_register_resource ( im_scaled , le_gd ) ) ;
2013-03-20 14:46:59 +08:00
}
}
/* }}} */
2013-05-16 03:59:43 +08:00
/* {{{ proto resource imageaffine(resource src, array affine[, array clip])
2013-03-20 14:46:59 +08:00
Return an image containing the affine tramsformed src image , using an optional clipping area */
PHP_FUNCTION ( imageaffine )
{
zval * IM ;
gdImagePtr src ;
gdImagePtr dst ;
gdRect rect ;
gdRectPtr pRect = NULL ;
zval * z_rect = NULL ;
zval * z_affine ;
2014-05-12 15:53:35 +08:00
zval * tmp ;
2013-03-20 14:46:59 +08:00
double affine [ 6 ] ;
int i , nelems ;
2014-05-12 15:53:35 +08:00
zval * zval_affine_elem = NULL ;
2013-03-20 18:01:37 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " ra|a " , & IM , & z_affine , & z_rect ) = = FAILURE ) {
2013-03-20 14:46:59 +08:00
return ;
}
2015-02-02 13:23:16 +08:00
if ( ( src = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2013-03-20 14:46:59 +08:00
if ( ( nelems = zend_hash_num_elements ( Z_ARRVAL_P ( z_affine ) ) ) ! = 6 ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Affine array must have six elements " ) ;
2013-03-20 14:46:59 +08:00
RETURN_FALSE ;
}
for ( i = 0 ; i < nelems ; i + + ) {
2014-05-12 15:53:35 +08:00
if ( ( zval_affine_elem = zend_hash_index_find ( Z_ARRVAL_P ( z_affine ) , i ) ) ! = NULL ) {
switch ( Z_TYPE_P ( zval_affine_elem ) ) {
2014-08-26 01:24:55 +08:00
case IS_LONG :
affine [ i ] = Z_LVAL_P ( zval_affine_elem ) ;
2013-03-20 14:46:59 +08:00
break ;
case IS_DOUBLE :
2014-05-12 15:53:35 +08:00
affine [ i ] = Z_DVAL_P ( zval_affine_elem ) ;
2013-03-20 14:46:59 +08:00
break ;
case IS_STRING :
2014-10-10 18:23:33 +08:00
affine [ i ] = zval_get_double ( zval_affine_elem ) ;
2013-03-20 14:46:59 +08:00
break ;
default :
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Invalid type for element %i " , i ) ;
2013-03-20 14:46:59 +08:00
RETURN_FALSE ;
}
}
}
if ( z_rect ! = NULL ) {
2015-09-25 03:39:59 +08:00
if ( ( tmp = zend_hash_str_find ( Z_ARRVAL_P ( z_rect ) , " x " , sizeof ( " x " ) - 1 ) ) ! = NULL ) {
2014-10-10 18:23:33 +08:00
rect . x = zval_get_long ( tmp ) ;
2013-03-20 14:46:59 +08:00
} else {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Missing x position " ) ;
2013-03-20 14:46:59 +08:00
RETURN_FALSE ;
}
2015-09-25 03:39:59 +08:00
if ( ( tmp = zend_hash_str_find ( Z_ARRVAL_P ( z_rect ) , " y " , sizeof ( " y " ) - 1 ) ) ! = NULL ) {
2014-10-10 18:23:33 +08:00
rect . y = zval_get_long ( tmp ) ;
2013-03-20 14:46:59 +08:00
} else {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Missing y position " ) ;
2013-03-20 14:46:59 +08:00
RETURN_FALSE ;
}
2015-09-25 03:39:59 +08:00
if ( ( tmp = zend_hash_str_find ( Z_ARRVAL_P ( z_rect ) , " width " , sizeof ( " width " ) - 1 ) ) ! = NULL ) {
2014-10-10 18:23:33 +08:00
rect . width = zval_get_long ( tmp ) ;
2013-03-20 14:46:59 +08:00
} else {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Missing width " ) ;
2013-03-20 14:46:59 +08:00
RETURN_FALSE ;
}
2015-09-25 03:39:59 +08:00
if ( ( tmp = zend_hash_str_find ( Z_ARRVAL_P ( z_rect ) , " height " , sizeof ( " height " ) - 1 ) ) ! = NULL ) {
2014-10-10 18:23:33 +08:00
rect . height = zval_get_long ( tmp ) ;
2013-03-20 14:46:59 +08:00
} else {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Missing height " ) ;
2013-03-20 14:46:59 +08:00
RETURN_FALSE ;
}
pRect = & rect ;
} else {
rect . x = - 1 ;
rect . y = - 1 ;
rect . width = gdImageSX ( src ) ;
rect . height = gdImageSY ( src ) ;
pRect = NULL ;
}
if ( gdTransformAffineGetImage ( & dst , src , pRect , affine ) ! = GD_TRUE ) {
RETURN_FALSE ;
}
if ( dst = = NULL ) {
RETURN_FALSE ;
} else {
2015-02-02 13:23:16 +08:00
RETURN_RES ( zend_register_resource ( dst , le_gd ) ) ;
2013-03-20 14:46:59 +08:00
}
}
/* }}} */
2015-06-24 05:46:07 +08:00
/* {{{ proto array imageaffinematrixget(int type[, array options])
2013-03-20 18:01:37 +08:00
Return an image containing the affine tramsformed src image , using an optional clipping area */
2013-03-20 19:19:03 +08:00
PHP_FUNCTION ( imageaffinematrixget )
2013-03-20 18:01:37 +08:00
{
double affine [ 6 ] ;
2014-08-26 01:24:55 +08:00
zend_long type ;
2014-05-12 09:14:57 +08:00
zval * options = NULL ;
2014-05-12 15:53:35 +08:00
zval * tmp ;
2013-04-26 14:15:33 +08:00
int res = GD_FALSE , i ;
2013-03-20 18:01:37 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " l|z " , & type , & options ) = = FAILURE ) {
2013-03-20 18:01:37 +08:00
return ;
}
2013-03-20 19:19:03 +08:00
2013-06-03 20:15:18 +08:00
switch ( ( gdAffineStandardMatrix ) type ) {
2013-03-20 18:01:37 +08:00
case GD_AFFINE_TRANSLATE :
case GD_AFFINE_SCALE : {
double x , y ;
2014-05-12 09:14:57 +08:00
if ( ! options | | Z_TYPE_P ( options ) ! = IS_ARRAY ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Array expected as options " ) ;
2014-03-10 04:12:19 +08:00
RETURN_FALSE ;
2013-03-20 18:01:37 +08:00
}
2015-09-25 03:39:59 +08:00
if ( ( tmp = zend_hash_str_find ( Z_ARRVAL_P ( options ) , " x " , sizeof ( " x " ) - 1 ) ) ! = NULL ) {
2014-10-10 18:23:33 +08:00
x = zval_get_double ( tmp ) ;
2013-03-20 18:01:37 +08:00
} else {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Missing x position " ) ;
2013-03-20 18:01:37 +08:00
RETURN_FALSE ;
}
2015-09-25 03:39:59 +08:00
if ( ( tmp = zend_hash_str_find ( Z_ARRVAL_P ( options ) , " y " , sizeof ( " y " ) - 1 ) ) ! = NULL ) {
2014-10-10 18:23:33 +08:00
y = zval_get_double ( tmp ) ;
2013-03-20 18:01:37 +08:00
} else {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Missing y position " ) ;
2013-03-20 18:01:37 +08:00
RETURN_FALSE ;
}
2015-01-03 17:22:58 +08:00
2013-03-20 18:01:37 +08:00
if ( type = = GD_AFFINE_TRANSLATE ) {
res = gdAffineTranslate ( affine , x , y ) ;
} else {
res = gdAffineScale ( affine , x , y ) ;
}
break ;
}
case GD_AFFINE_ROTATE :
case GD_AFFINE_SHEAR_HORIZONTAL :
case GD_AFFINE_SHEAR_VERTICAL : {
double angle ;
2014-05-12 09:14:57 +08:00
if ( ! options ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Number is expected as option " ) ;
2014-05-12 09:14:57 +08:00
RETURN_FALSE ;
}
2014-10-10 18:23:33 +08:00
angle = zval_get_double ( options ) ;
2013-03-20 18:01:37 +08:00
if ( type = = GD_AFFINE_SHEAR_HORIZONTAL ) {
res = gdAffineShearHorizontal ( affine , angle ) ;
} else if ( type = = GD_AFFINE_SHEAR_VERTICAL ) {
res = gdAffineShearVertical ( affine , angle ) ;
} else {
res = gdAffineRotate ( affine , angle ) ;
}
break ;
}
default :
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Invalid type for element %li " , type ) ;
2013-03-20 18:01:37 +08:00
RETURN_FALSE ;
}
2013-03-20 19:19:03 +08:00
2013-04-27 23:52:30 +08:00
if ( res = = GD_FALSE ) {
2013-04-26 14:15:33 +08:00
RETURN_FALSE ;
} else {
array_init ( return_value ) ;
for ( i = 0 ; i < 6 ; i + + ) {
add_index_double ( return_value , i , affine [ i ] ) ;
}
2013-03-20 19:19:03 +08:00
}
2014-05-12 15:53:35 +08:00
} /* }}} */
2013-03-20 19:19:03 +08:00
/* {{{ proto array imageaffineconcat(array m1, array m2)
Concat two matrices ( as in doing many ops in one go ) */
PHP_FUNCTION ( imageaffinematrixconcat )
{
double m1 [ 6 ] ;
double m2 [ 6 ] ;
double mr [ 6 ] ;
2014-05-12 15:53:35 +08:00
zval * tmp ;
2013-03-20 19:19:03 +08:00
zval * z_m1 ;
zval * z_m2 ;
int i , nelems ;
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " aa " , & z_m1 , & z_m2 ) = = FAILURE ) {
2013-03-20 19:19:03 +08:00
return ;
}
if ( ( ( nelems = zend_hash_num_elements ( Z_ARRVAL_P ( z_m1 ) ) ) ! = 6 ) | | ( nelems = zend_hash_num_elements ( Z_ARRVAL_P ( z_m2 ) ) ) ! = 6 ) {
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Affine arrays must have six elements " ) ;
2013-03-20 19:19:03 +08:00
RETURN_FALSE ;
}
for ( i = 0 ; i < 6 ; i + + ) {
2014-05-12 15:53:35 +08:00
if ( ( tmp = zend_hash_index_find ( Z_ARRVAL_P ( z_m1 ) , i ) ) ! = NULL ) {
switch ( Z_TYPE_P ( tmp ) ) {
2014-08-26 01:24:55 +08:00
case IS_LONG :
m1 [ i ] = Z_LVAL_P ( tmp ) ;
2013-03-20 19:19:03 +08:00
break ;
case IS_DOUBLE :
2014-05-12 15:53:35 +08:00
m1 [ i ] = Z_DVAL_P ( tmp ) ;
2013-03-20 19:19:03 +08:00
break ;
case IS_STRING :
2014-10-10 18:23:33 +08:00
m1 [ i ] = zval_get_double ( tmp ) ;
2013-03-20 19:19:03 +08:00
break ;
default :
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Invalid type for element %i " , i ) ;
2013-03-20 19:19:03 +08:00
RETURN_FALSE ;
}
}
2014-05-12 15:53:35 +08:00
if ( ( tmp = zend_hash_index_find ( Z_ARRVAL_P ( z_m2 ) , i ) ) ! = NULL ) {
switch ( Z_TYPE_P ( tmp ) ) {
2014-08-26 01:24:55 +08:00
case IS_LONG :
m2 [ i ] = Z_LVAL_P ( tmp ) ;
2013-03-20 19:19:03 +08:00
break ;
case IS_DOUBLE :
2014-05-12 15:53:35 +08:00
m2 [ i ] = Z_DVAL_P ( tmp ) ;
2013-03-20 19:19:03 +08:00
break ;
case IS_STRING :
2014-10-10 18:23:33 +08:00
m2 [ i ] = zval_get_double ( tmp ) ;
2013-03-20 19:19:03 +08:00
break ;
default :
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Invalid type for element %i " , i ) ;
2013-03-20 19:19:03 +08:00
RETURN_FALSE ;
}
}
}
if ( gdAffineConcat ( mr , m1 , m2 ) ! = GD_TRUE ) {
RETURN_FALSE ;
}
array_init ( return_value ) ;
for ( i = 0 ; i < 6 ; i + + ) {
add_index_double ( return_value , i , mr [ i ] ) ;
}
2014-05-12 15:53:35 +08:00
} /* }}} */
2013-03-20 18:01:37 +08:00
2015-06-24 05:46:07 +08:00
/* {{{ proto resource imagesetinterpolation(resource im [, int method]])
2013-03-20 14:46:59 +08:00
Set the default interpolation method , passing - 1 or 0 sets it to the libgd default ( bilinear ) . */
PHP_FUNCTION ( imagesetinterpolation )
{
zval * IM ;
gdImagePtr im ;
2014-08-26 01:24:55 +08:00
zend_long method = GD_BILINEAR_FIXED ;
2013-03-20 14:46:59 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " r|l " , & IM , & method ) = = FAILURE ) {
2013-03-20 14:46:59 +08:00
return ;
}
2015-02-02 13:23:16 +08:00
if ( ( im = ( gdImagePtr ) zend_fetch_resource ( Z_RES_P ( IM ) , " Image " , le_gd ) ) = = NULL ) {
RETURN_FALSE ;
}
2013-03-20 14:46:59 +08:00
if ( method = = - 1 ) {
method = GD_BILINEAR_FIXED ;
}
RETURN_BOOL ( gdImageSetInterpolationMethod ( im , ( gdInterpolationMethod ) method ) ) ;
}
/* }}} */
2013-02-27 17:39:25 +08:00
1999-04-16 20:15:38 +08:00
/*
* Local variables :
* tab - width : 4
* c - basic - offset : 4
* End :
2001-09-09 21:29:31 +08:00
* vim600 : sw = 4 ts = 4 fdm = marker
* vim < 600 : sw = 4 ts = 4
1999-04-16 20:15:38 +08:00
*/