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    echo_status(imageavif($img, $outfile, 1234));
40
41    echo 'Encoding AVIF with illegal speed: ';
42    echo_status(imageavif($img, $outfile, 70, 1234));
43
44    echo 'Encoding AVIF losslessly... ';
45    echo_status(imageavif($img, $outfile, 100, 0));
46
47    echo "Decoding the AVIF we just wrote...\n";
48    $img_from_avif = imagecreatefromavif($outfile);
49
50    // Note we could also forgive a certain number of pixel differences.
51    // With the current test image, we just didn't need to.
52    echo 'How many pixels are different in the two images? ';
53    print_r(calc_image_dissimilarity($img, $img_from_avif));
54
55    unlink($outfile);
56
57
58    function echo_status($success) {
59        echo $success ? "ok\n" : "failed\n";
60    }
61?>
62
63--EXPECT--
64Decoding AVIF image: ok
65Default AVIF encoding: ok
66Encoding AVIF at quality 70: ok
67Encoding AVIF at quality 70 with speed 5: ok
68Encoding AVIF with default quality: ok
69Encoding AVIF with illegal quality: ok
70Encoding AVIF with illegal speed: ok
71Encoding AVIF losslessly... ok
72Decoding the AVIF we just wrote...
73How many pixels are different in the two images? 0
74