函数名:imagecreatefromavif()
适用版本:PHP 8.1.0 及以上版本
用法:imagecreatefromavif() 函数用于从 AVIF 格式的图像文件创建一个新的图像资源。
语法:imagecreatefromavif(string $filename): resource|false
参数:
返回值:
示例:
$filename = 'path/to/image.avif';
// 创建一个新的图像资源
$image = imagecreatefromavif($filename);
if ($image !== false) {
// 成功加载图像,可以进行后续操作
// 获取图像的宽度和高度
$width = imagesx($image);
$height = imagesy($image);
// 在浏览器中显示图像
header('Content-Type: image/avif');
imageavif($image);
// 释放图像资源
imagedestroy($image);
} else {
// 图像加载失败
echo '无法加载 AVIF 图像文件。';
}
注意事项: