@@ -126,9 +126,6 @@ static gdIOCtx *create_stream_context(php_stream *stream, int close_stream);
126
126
static gdIOCtx * create_output_context (void );
127
127
static int _php_image_type (zend_string * data );
128
128
129
- /* output streaming (formerly gd_ctx.c) */
130
- static void _php_image_output_ctx (INTERNAL_FUNCTION_PARAMETERS , int image_type , char * tn );
131
-
132
129
/*********************************************************
133
130
*
134
131
* GD Object Representation
@@ -1912,15 +1909,74 @@ PHP_FUNCTION(imagexbm)
1912
1909
/* {{{ Output GIF image to browser or file */
1913
1910
PHP_FUNCTION (imagegif )
1914
1911
{
1915
- _php_image_output_ctx (INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GDIMG_TYPE_GIF , "GIF" );
1912
+ zval * imgind ;
1913
+ gdImagePtr im ;
1914
+ gdIOCtx * ctx ;
1915
+ zval * to_zval = NULL ;
1916
+
1917
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "O|z!" , & imgind , gd_image_ce , & to_zval ) == FAILURE ) {
1918
+ RETURN_THROWS ();
1919
+ }
1920
+
1921
+ im = php_gd_libgdimageptr_from_zval_p (imgind );
1922
+
1923
+ if (to_zval != NULL ) {
1924
+ ctx = create_stream_context_from_zval (to_zval );
1925
+ if (!ctx ) {
1926
+ RETURN_FALSE ;
1927
+ }
1928
+ } else {
1929
+ ctx = create_output_context ();
1930
+ }
1931
+
1932
+ gdImageGifCtx (im , ctx );
1933
+
1934
+ ctx -> gd_free (ctx );
1935
+
1936
+ RETURN_TRUE ;
1916
1937
}
1917
1938
/* }}} */
1918
1939
1919
1940
#ifdef HAVE_GD_PNG
1920
1941
/* {{{ Output PNG image to browser or file */
1921
1942
PHP_FUNCTION (imagepng )
1922
1943
{
1923
- _php_image_output_ctx (INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GDIMG_TYPE_PNG , "PNG" );
1944
+ zval * imgind ;
1945
+ zend_long quality = -1 , basefilter = -1 ;
1946
+ gdImagePtr im ;
1947
+ gdIOCtx * ctx ;
1948
+ zval * to_zval = NULL ;
1949
+
1950
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "O|z!ll" , & imgind , gd_image_ce , & to_zval , & quality , & basefilter ) == FAILURE ) {
1951
+ RETURN_THROWS ();
1952
+ }
1953
+
1954
+ im = php_gd_libgdimageptr_from_zval_p (imgind );
1955
+
1956
+ if (to_zval != NULL ) {
1957
+ ctx = create_stream_context_from_zval (to_zval );
1958
+ if (!ctx ) {
1959
+ RETURN_FALSE ;
1960
+ }
1961
+ } else {
1962
+ ctx = create_output_context ();
1963
+ }
1964
+
1965
+ if (quality < -1 || quality > 9 ) {
1966
+ zend_argument_value_error (3 , "must be between -1 and 9" );
1967
+ ctx -> gd_free (ctx );
1968
+ RETURN_THROWS ();
1969
+ }
1970
+
1971
+ #ifdef HAVE_GD_BUNDLED
1972
+ gdImagePngCtxEx (im , ctx , (int ) quality , (int ) basefilter );
1973
+ #else
1974
+ gdImagePngCtxEx (im , ctx , (int ) quality );
1975
+ #endif
1976
+
1977
+ ctx -> gd_free (ctx );
1978
+
1979
+ RETURN_TRUE ;
1924
1980
}
1925
1981
/* }}} */
1926
1982
#endif /* HAVE_GD_PNG */
@@ -1929,7 +1985,38 @@ PHP_FUNCTION(imagepng)
1929
1985
/* {{{ Output WEBP image to browser or file */
1930
1986
PHP_FUNCTION (imagewebp )
1931
1987
{
1932
- _php_image_output_ctx (INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GDIMG_TYPE_WEBP , "WEBP" );
1988
+ zval * imgind ;
1989
+ zend_long quality = -1 ;
1990
+ gdImagePtr im ;
1991
+ gdIOCtx * ctx ;
1992
+ zval * to_zval = NULL ;
1993
+
1994
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "O|z!l" , & imgind , gd_image_ce , & to_zval , & quality ) == FAILURE ) {
1995
+ RETURN_THROWS ();
1996
+ }
1997
+
1998
+ im = php_gd_libgdimageptr_from_zval_p (imgind );
1999
+
2000
+ if (to_zval != NULL ) {
2001
+ ctx = create_stream_context_from_zval (to_zval );
2002
+ if (!ctx ) {
2003
+ RETURN_FALSE ;
2004
+ }
2005
+ } else {
2006
+ ctx = create_output_context ();
2007
+ }
2008
+
2009
+ if (quality < -1 ) {
2010
+ zend_argument_value_error (3 , "must be greater than or equal to -1" );
2011
+ ctx -> gd_free (ctx );
2012
+ RETURN_THROWS ();
2013
+ }
2014
+
2015
+ gdImageWebpCtx (im , ctx , (int ) quality );
2016
+
2017
+ ctx -> gd_free (ctx );
2018
+
2019
+ RETURN_TRUE ;
1933
2020
}
1934
2021
/* }}} */
1935
2022
#endif /* HAVE_GD_WEBP */
@@ -1938,7 +2025,46 @@ PHP_FUNCTION(imagewebp)
1938
2025
/* {{{ Output AVIF image to browser or file */
1939
2026
PHP_FUNCTION (imageavif )
1940
2027
{
1941
- _php_image_output_ctx (INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GDIMG_TYPE_AVIF , "AVIF" );
2028
+ zval * imgind ;
2029
+ zend_long quality = -1 , speed = -1 ;
2030
+ gdImagePtr im ;
2031
+ gdIOCtx * ctx ;
2032
+ zval * to_zval = NULL ;
2033
+
2034
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "O|z!ll" , & imgind , gd_image_ce , & to_zval , & quality , & speed ) == FAILURE ) {
2035
+ RETURN_THROWS ();
2036
+ }
2037
+
2038
+ im = php_gd_libgdimageptr_from_zval_p (imgind );
2039
+
2040
+ if (to_zval != NULL ) {
2041
+ ctx = create_stream_context_from_zval (to_zval );
2042
+ if (!ctx ) {
2043
+ RETURN_FALSE ;
2044
+ }
2045
+ } else {
2046
+ ctx = create_output_context ();
2047
+ }
2048
+
2049
+ if (quality < -1 || quality > 100 ) {
2050
+ zend_argument_value_error (3 , "must be between -1 and 100" );
2051
+ ctx -> gd_free (ctx );
2052
+ RETURN_THROWS ();
2053
+ }
2054
+
2055
+ if (speed < -1 || speed > 10 ) {
2056
+ zend_argument_value_error (4 , "must be between -1 and 10" );
2057
+ ctx -> gd_free (ctx );
2058
+ RETURN_THROWS ();
2059
+ } else if (speed == -1 ) {
2060
+ speed = 6 ;
2061
+ }
2062
+
2063
+ gdImageAvifCtx (im , ctx , (int ) quality , (int ) speed );
2064
+
2065
+ ctx -> gd_free (ctx );
2066
+
2067
+ RETURN_TRUE ;
1942
2068
}
1943
2069
/* }}} */
1944
2070
#endif /* HAVE_GD_AVIF */
@@ -1947,7 +2073,38 @@ PHP_FUNCTION(imageavif)
1947
2073
/* {{{ Output JPEG image to browser or file */
1948
2074
PHP_FUNCTION (imagejpeg )
1949
2075
{
1950
- _php_image_output_ctx (INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GDIMG_TYPE_JPG , "JPEG" );
2076
+ zval * imgind ;
2077
+ zend_long quality = -1 ;
2078
+ gdImagePtr im ;
2079
+ gdIOCtx * ctx ;
2080
+ zval * to_zval = NULL ;
2081
+
2082
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "O|z!l" , & imgind , gd_image_ce , & to_zval , & quality ) == FAILURE ) {
2083
+ RETURN_THROWS ();
2084
+ }
2085
+
2086
+ im = php_gd_libgdimageptr_from_zval_p (imgind );
2087
+
2088
+ if (to_zval != NULL ) {
2089
+ ctx = create_stream_context_from_zval (to_zval );
2090
+ if (!ctx ) {
2091
+ RETURN_FALSE ;
2092
+ }
2093
+ } else {
2094
+ ctx = create_output_context ();
2095
+ }
2096
+
2097
+ if (quality < -1 || quality > 100 ) {
2098
+ zend_argument_value_error (3 , "must be at between -1 and 100" );
2099
+ ctx -> gd_free (ctx );
2100
+ RETURN_THROWS ();
2101
+ }
2102
+
2103
+ gdImageJpegCtx (im , ctx , (int ) quality );
2104
+
2105
+ ctx -> gd_free (ctx );
2106
+
2107
+ RETURN_TRUE ;
1951
2108
}
1952
2109
/* }}} */
1953
2110
#endif /* HAVE_GD_JPG */
@@ -1960,7 +2117,7 @@ PHP_FUNCTION(imagewbmp)
1960
2117
bool foreground_color_is_null = true;
1961
2118
gdImagePtr im ;
1962
2119
int i ;
1963
- gdIOCtx * ctx = NULL ;
2120
+ gdIOCtx * ctx ;
1964
2121
zval * to_zval = NULL ;
1965
2122
1966
2123
ZEND_PARSE_PARAMETERS_START (1 , 3 )
@@ -1982,7 +2139,7 @@ PHP_FUNCTION(imagewbmp)
1982
2139
}
1983
2140
1984
2141
if (foreground_color_is_null ) {
1985
- for (i = 0 ; i < gdImageColorsTotal (im ); i ++ ) {
2142
+ for (i = 0 ; i < gdImageColorsTotal (im ); i ++ ) {
1986
2143
if (!gdImageRed (im , i ) && !gdImageGreen (im , i ) && !gdImageBlue (im , i )) {
1987
2144
break ;
1988
2145
}
@@ -4283,104 +4440,4 @@ static gdIOCtx *create_output_context(void) {
4283
4440
return ctx ;
4284
4441
}
4285
4442
4286
- static void _php_image_output_ctx (INTERNAL_FUNCTION_PARAMETERS , int image_type , char * tn )
4287
- {
4288
- zval * imgind ;
4289
- zend_long quality = -1 , basefilter = -1 , speed = -1 ;
4290
- gdImagePtr im ;
4291
- gdIOCtx * ctx = NULL ;
4292
- zval * to_zval = NULL ;
4293
-
4294
- if (image_type == PHP_GDIMG_TYPE_GIF ) {
4295
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "O|z!" , & imgind , gd_image_ce , & to_zval ) == FAILURE ) {
4296
- RETURN_THROWS ();
4297
- }
4298
- } else if (image_type == PHP_GDIMG_TYPE_PNG ) {
4299
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "O|z!ll" , & imgind , gd_image_ce , & to_zval , & quality , & basefilter ) == FAILURE ) {
4300
- RETURN_THROWS ();
4301
- }
4302
- } else if (image_type == PHP_GDIMG_TYPE_AVIF ) {
4303
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "O|z!ll" , & imgind , gd_image_ce , & to_zval , & quality , & speed ) == FAILURE ) {
4304
- RETURN_THROWS ();
4305
- }
4306
- } else {
4307
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "O|z!l" , & imgind , gd_image_ce , & to_zval , & quality ) == FAILURE ) {
4308
- RETURN_THROWS ();
4309
- }
4310
- }
4311
-
4312
- im = php_gd_libgdimageptr_from_zval_p (imgind );
4313
-
4314
- if (to_zval != NULL ) {
4315
- ctx = create_stream_context_from_zval (to_zval );
4316
- if (!ctx ) {
4317
- RETURN_FALSE ;
4318
- }
4319
- } else {
4320
- ctx = create_output_context ();
4321
- }
4322
-
4323
- switch (image_type ) {
4324
- #ifdef HAVE_GD_JPG
4325
- case PHP_GDIMG_TYPE_JPG :
4326
- if (quality < -1 || quality > 100 ) {
4327
- zend_argument_value_error (3 , "must be at between -1 and 100" );
4328
- ctx -> gd_free (ctx );
4329
- RETURN_THROWS ();
4330
- }
4331
- gdImageJpegCtx (im , ctx , (int ) quality );
4332
- break ;
4333
- #endif
4334
- #ifdef HAVE_GD_WEBP
4335
- case PHP_GDIMG_TYPE_WEBP :
4336
- if (quality < -1 ) {
4337
- zend_argument_value_error (3 , "must be greater than or equal to -1" );
4338
- ctx -> gd_free (ctx );
4339
- RETURN_THROWS ();
4340
- }
4341
- gdImageWebpCtx (im , ctx , (int ) quality );
4342
- break ;
4343
- #endif
4344
- #ifdef HAVE_GD_AVIF
4345
- case PHP_GDIMG_TYPE_AVIF :
4346
- if (quality < -1 || quality > 100 ) {
4347
- zend_argument_value_error (3 , "must be between -1 and 100" );
4348
- ctx -> gd_free (ctx );
4349
- RETURN_THROWS ();
4350
- }
4351
- if (speed < -1 || speed > 10 ) {
4352
- zend_argument_value_error (4 , "must be between -1 and 10" );
4353
- ctx -> gd_free (ctx );
4354
- RETURN_THROWS ();
4355
- } else if (speed == -1 ) {
4356
- speed = 6 ;
4357
- }
4358
- gdImageAvifCtx (im , ctx , (int ) quality , (int ) speed );
4359
- break ;
4360
- #endif
4361
- #ifdef HAVE_GD_PNG
4362
- case PHP_GDIMG_TYPE_PNG :
4363
- if (quality < -1 || quality > 9 ) {
4364
- zend_argument_value_error (3 , "must be between -1 and 9" );
4365
- ctx -> gd_free (ctx );
4366
- RETURN_THROWS ();
4367
- }
4368
- #ifdef HAVE_GD_BUNDLED
4369
- gdImagePngCtxEx (im , ctx , (int ) quality , (int ) basefilter );
4370
- #else
4371
- gdImagePngCtxEx (im , ctx , (int ) quality );
4372
- #endif
4373
- break ;
4374
- #endif
4375
- case PHP_GDIMG_TYPE_GIF :
4376
- gdImageGifCtx (im , ctx );
4377
- break ;
4378
- EMPTY_SWITCH_DEFAULT_CASE ()
4379
- }
4380
-
4381
- ctx -> gd_free (ctx );
4382
-
4383
- RETURN_TRUE ;
4384
- }
4385
-
4386
4443
/* }}} */
0 commit comments