AVIF is a pretty new image format compared with PNG or JPEG. Since PHP 8.1, GD extension can be compiled with AVIF support.
gd_info function returns features of the currently installed GD extension. This function can be used to determine if AVIF image format is available in GD extension.
<?php $avifSupport = gd_info()['AVIF Support'] ?? false; var_dump($avifSupport);
If GD extension compiled with AVIF support, we can use
imageavif function which can be used to save AVIF image. For example, the following code reads JPEG image and converts to AVIF image which save to a file:
<?php $image = imagecreatefromjpeg('test.jpg'); imageavif($image, 'test.avif');
We can also use
imagecreatefromavif function which allows to create a new image from AVIF file or URL. For example, the following code allows to read AVIF image and convert to PNG image and save to a file:
<?php $image = imagecreatefromavif('test.avif'); imagejpeg($image, 'test.jpg');