Skip to content

Commit 2fd40be

Browse files
committed
Include image-to-image test
New test writes AVIF image losslessly, reads that back in, and compares that to the original
1 parent 3c5c5ab commit 2fd40be

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

ext/gd/tests/avif_decode_encode.phpt

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ gd
1313
?>
1414
--FILE--
1515
<?php
16-
$cwd = __DIR__;
17-
$infile = $cwd . '/girl.avif';
18-
$outfile = $cwd . '/test.avif';
16+
17+
require_once __DIR__ . '/similarity.inc';
18+
19+
$infile = __DIR__ . '/girl.avif';
20+
$outfile = __DIR__ . '/test.avif';
1921

2022
echo 'Decoding AVIF image: ';
2123
$img = imagecreatefromavif($infile);
@@ -39,8 +41,20 @@ gd
3941
echo 'Encoding AVIF with illegal speed: ';
4042
echo_status(imageavif($img, $outfile, 70, 1234));
4143

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+
4255
unlink($outfile);
4356

57+
4458
function echo_status($success) {
4559
echo $success ? "ok\n" : "failed\n";
4660
}
@@ -53,3 +67,6 @@ Encoding AVIF at quality 70 with speed 5: ok
5367
Encoding AVIF with default quality: ok
5468
Encoding AVIF with illegal quality: ok
5569
Encoding AVIF with illegal speed: ok
70+
Encoding AVIF losslessly... ok
71+
Decoding the AVIF we just wrote...
72+
How many pixels are different in the two images? 0

0 commit comments

Comments
 (0)