avif_decode_encode.phpt 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. --TEST--
  2. avif decoding/encoding tests
  3. --EXTENSIONS--
  4. gd
  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. require_once __DIR__ . '/similarity.inc';
  17. $infile = __DIR__ . '/girl.avif';
  18. $outfile = __DIR__ . '/test.avif';
  19. echo 'Decoding AVIF image: ';
  20. $img = imagecreatefromavif($infile);
  21. echo_status($img);
  22. echo 'Default AVIF encoding: ';
  23. echo_status(imageavif($img, $outfile));
  24. echo 'Encoding AVIF at quality 70: ';
  25. echo_status(imageavif($img, $outfile, 70));
  26. echo 'Encoding AVIF at quality 70 with speed 5: ';
  27. echo_status(imageavif($img, $outfile, 70, 5));
  28. echo 'Encoding AVIF with default quality: ';
  29. echo_status(imageavif($img, $outfile, -1));
  30. echo 'Encoding AVIF with illegal quality: ';
  31. echo_status(imageavif($img, $outfile, 1234));
  32. echo 'Encoding AVIF with illegal speed: ';
  33. echo_status(imageavif($img, $outfile, 70, 1234));
  34. echo 'Encoding AVIF losslessly... ';
  35. echo_status(imageavif($img, $outfile, 100, 0));
  36. echo "Decoding the AVIF we just wrote...\n";
  37. $img_from_avif = imagecreatefromavif($outfile);
  38. // Note we could also forgive a certain number of pixel differences.
  39. // With the current test image, we just didn't need to.
  40. echo 'How many pixels are different in the two images? ';
  41. print_r(calc_image_dissimilarity($img, $img_from_avif));
  42. unlink($outfile);
  43. function echo_status($success) {
  44. echo $success ? "ok\n" : "failed\n";
  45. }
  46. ?>
  47. --EXPECT--
  48. Decoding AVIF image: ok
  49. Default AVIF encoding: ok
  50. Encoding AVIF at quality 70: ok
  51. Encoding AVIF at quality 70 with speed 5: ok
  52. Encoding AVIF with default quality: ok
  53. Encoding AVIF with illegal quality: ok
  54. Encoding AVIF with illegal speed: ok
  55. Encoding AVIF losslessly... ok
  56. Decoding the AVIF we just wrote...
  57. How many pixels are different in the two images? 0