1--TEST-- 2avif decoding/encoding tests 3--EXTENSIONS-- 4gd 5--SKIPIF-- 6<?php 7 if (!function_exists("imagecreatefrompng") || !function_exists("imagepng")) { 8 die("skip png support unavailable"); 9 } 10 if (!function_exists("imagecreatefromavif") || !function_exists("imageavif")) { 11 die("skip avif support unavailable"); 12 } 13?> 14--FILE-- 15<?php 16 17 require_once __DIR__ . '/similarity.inc'; 18 19 $infile = __DIR__ . '/girl.avif'; 20 $outfile = __DIR__ . '/test.avif'; 21 22 echo 'Decoding AVIF image: '; 23 $img = imagecreatefromavif($infile); 24 echo_status($img); 25 26 echo 'Default AVIF encoding: '; 27 echo_status(imageavif($img, $outfile)); 28 29 echo 'Encoding AVIF at quality 70: '; 30 echo_status(imageavif($img, $outfile, 70)); 31 32 echo 'Encoding AVIF at quality 70 with speed 5: '; 33 echo_status(imageavif($img, $outfile, 70, 5)); 34 35 echo 'Encoding AVIF with default quality: '; 36 echo_status(imageavif($img, $outfile, -1)); 37 38 echo 'Encoding AVIF with illegal quality: '; 39 try { 40 imageavif($img, $outfile, 1234); 41 } catch (\ValueError $e) { 42 echo $e->getMessage() . PHP_EOL; 43 } 44 45 echo 'Encoding AVIF with illegal speed: '; 46 47 try { 48 imageavif($img, $outfile, 70, 1234); 49 } catch (\ValueError $e) { 50 echo $e->getMessage() . PHP_EOL; 51 } 52 53 echo 'Encoding AVIF losslessly... '; 54 echo_status(imageavif($img, $outfile, 100, 0)); 55 56 echo "Decoding the AVIF we just wrote...\n"; 57 $img_from_avif = imagecreatefromavif($outfile); 58 59 // Note we could also forgive a certain number of pixel differences. 60 // With the current test image, we just didn't need to. 61 echo 'How many pixels are different in the two images? '; 62 print_r(calc_image_dissimilarity($img, $img_from_avif)); 63 64 unlink($outfile); 65 66 67 function echo_status($success) { 68 echo $success ? "ok\n" : "failed\n"; 69 } 70?> 71 72--EXPECT-- 73Decoding AVIF image: ok 74Default AVIF encoding: ok 75Encoding AVIF at quality 70: ok 76Encoding AVIF at quality 70 with speed 5: ok 77Encoding AVIF with default quality: ok 78Encoding AVIF with illegal quality: imageavif(): Argument #3 ($quality) must be between -1 and 100 79Encoding AVIF with illegal speed: imageavif(): Argument #4 ($speed) must be between -1 and 10 80Encoding AVIF losslessly... ok 81Decoding the AVIF we just wrote... 82How many pixels are different in the two images? 0 83