5454# include <X11/xpm.h>
5555#endif
5656
57-
5857#include "gd_compat.h"
5958
6059#ifdef HAVE_GD_BUNDLED
@@ -371,6 +370,7 @@ PHP_MINIT_FUNCTION(gd)
371370
372371 REGISTER_INI_ENTRIES ();
373372
373+ REGISTER_LONG_CONSTANT ("IMG_AVIF" , PHP_IMG_AVIF , CONST_CS | CONST_PERSISTENT );
374374 REGISTER_LONG_CONSTANT ("IMG_GIF" , PHP_IMG_GIF , CONST_CS | CONST_PERSISTENT );
375375 REGISTER_LONG_CONSTANT ("IMG_JPG" , PHP_IMG_JPG , CONST_CS | CONST_PERSISTENT );
376376 REGISTER_LONG_CONSTANT ("IMG_JPEG" , PHP_IMG_JPEG , CONST_CS | CONST_PERSISTENT );
@@ -601,6 +601,9 @@ PHP_MINFO_FUNCTION(gd)
601601#ifdef HAVE_GD_BMP
602602 php_info_print_table_row (2 , "BMP Support" , "enabled" );
603603#endif
604+ #ifdef HAVE_GD_AVIF
605+ php_info_print_table_row (2 , "AVIF Support" , "enabled" );
606+ #endif
604607#ifdef HAVE_GD_TGA
605608 php_info_print_table_row (2 , "TGA Read Support" , "enabled" );
606609#endif
@@ -655,6 +658,11 @@ PHP_FUNCTION(gd_info)
655658#else
656659 add_assoc_bool (return_value , "BMP Support" , 0 );
657660#endif
661+ #ifdef HAVE_GD_AVIF
662+ add_assoc_bool (return_value , "AVIF Support" , 1 );
663+ #else
664+ add_assoc_bool (return_value , "AVIF Support" , 0 );
665+ #endif
658666#ifdef HAVE_GD_TGA
659667 add_assoc_bool (return_value , "TGA Read Support" , 1 );
660668#else
@@ -1407,7 +1415,7 @@ PHP_FUNCTION(imagecreate)
14071415}
14081416/* }}} */
14091417
1410- /* {{{ Return the types of images supported in a bitfield - 1=GIF, 2=JPEG, 4=PNG, 8=WBMP, 16=XPM */
1418+ /* {{{ Return the types of images supported in a bitfield - 1=GIF, 2=JPEG, 4=PNG, 8=WBMP, 16=XPM, etc */
14111419PHP_FUNCTION (imagetypes )
14121420{
14131421 int ret = 0 ;
@@ -1431,6 +1439,9 @@ PHP_FUNCTION(imagetypes)
14311439#ifdef HAVE_GD_TGA
14321440 ret |= PHP_IMG_TGA ;
14331441#endif
1442+ #ifdef HAVE_GD_AVIF
1443+ ret |= PHP_IMG_AVIF ;
1444+ #endif
14341445
14351446 if (zend_parse_parameters_none () == FAILURE ) {
14361447 RETURN_THROWS ();
@@ -1589,6 +1600,15 @@ PHP_FUNCTION(imagecreatefromstring)
15891600 RETURN_FALSE ;
15901601#endif
15911602
1603+ case PHP_GDIMG_TYPE_AVIF :
1604+ #ifdef HAVE_GD_AVIF
1605+ im = _php_image_create_from_string (data , "AVIF" , gdImageCreateFromAvifCtx );
1606+ break ;
1607+ #else
1608+ php_error_docref (NULL , E_WARNING , "No AVIF support in this PHP build" );
1609+ RETURN_FALSE ;
1610+ #endif
1611+
15921612 default :
15931613 php_error_docref (NULL , E_WARNING , "Data is not in a recognized format" );
15941614 RETURN_FALSE ;
@@ -1769,6 +1789,15 @@ PHP_FUNCTION(imagecreatefromxbm)
17691789}
17701790/* }}} */
17711791
1792+ #ifdef HAVE_GD_AVIF
1793+ /* {{{ Create a new image from AVIF file or URL */
1794+ PHP_FUNCTION (imagecreatefromavif )
1795+ {
1796+ _php_image_create_from (INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GDIMG_TYPE_AVIF , "AVIF" , gdImageCreateFromAvif , gdImageCreateFromAvifCtx );
1797+ }
1798+ /* }}} */
1799+ #endif /* HAVE_GD_AVIF */
1800+
17721801#ifdef HAVE_GD_XPM
17731802/* {{{ Create a new image from XPM file or URL */
17741803PHP_FUNCTION (imagecreatefromxpm )
@@ -1996,6 +2025,15 @@ PHP_FUNCTION(imagewebp)
19962025/* }}} */
19972026#endif /* HAVE_GD_WEBP */
19982027
2028+ #ifdef HAVE_GD_AVIF
2029+ /* {{{ Output AVIF image to browser or file */
2030+ PHP_FUNCTION (imageavif )
2031+ {
2032+ _php_image_output_ctx (INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GDIMG_TYPE_AVIF , "AVIF" , gdImageAvifCtx );
2033+ }
2034+ /* }}} */
2035+ #endif /* HAVE_GD_AVIF */
2036+
19992037#ifdef HAVE_GD_JPG
20002038/* {{{ Output JPEG image to browser or file */
20012039PHP_FUNCTION (imagejpeg )
@@ -4178,7 +4216,7 @@ static gdIOCtx *create_output_context() {
41784216static void _php_image_output_ctx (INTERNAL_FUNCTION_PARAMETERS , int image_type , char * tn , void (* func_p )())
41794217{
41804218 zval * imgind ;
4181- zend_long quality = -1 , basefilter = -1 ;
4219+ zend_long quality = -1 , basefilter = -1 , speed = -1 ;
41824220 gdImagePtr im ;
41834221 gdIOCtx * ctx = NULL ;
41844222 zval * to_zval = NULL ;
@@ -4191,6 +4229,10 @@ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type,
41914229 if (zend_parse_parameters (ZEND_NUM_ARGS (), "O|z!ll" , & imgind , gd_image_ce , & to_zval , & quality , & basefilter ) == FAILURE ) {
41924230 RETURN_THROWS ();
41934231 }
4232+ } else if (image_type == PHP_GDIMG_TYPE_AVIF ) {
4233+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "O|z!ll" , & imgind , gd_image_ce , & to_zval , & quality , & speed ) == FAILURE ) {
4234+ RETURN_THROWS ();
4235+ }
41944236 } else {
41954237 if (zend_parse_parameters (ZEND_NUM_ARGS (), "O|z!l" , & imgind , gd_image_ce , & to_zval , & quality ) == FAILURE ) {
41964238 RETURN_THROWS ();
@@ -4218,6 +4260,12 @@ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type,
42184260 }
42194261 (* func_p )(im , ctx , (int ) quality );
42204262 break ;
4263+ case PHP_GDIMG_TYPE_AVIF :
4264+ if (speed == -1 ) {
4265+ speed = 6 ;
4266+ }
4267+ (* func_p )(im , ctx , (int ) quality , (int ) speed );
4268+ break ;
42214269 case PHP_GDIMG_TYPE_PNG :
42224270 (* func_p )(im , ctx , (int ) quality , (int ) basefilter );
42234271 break ;
0 commit comments