webp_basic.phpt 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. --TEST--
  2. imagewebp() and imagecreatefromwebp() - basic test
  3. --EXTENSIONS--
  4. gd
  5. --SKIPIF--
  6. <?php
  7. if (!GD_BUNDLED && version_compare(GD_VERSION, '2.2.0', '<')) {
  8. die("skip test requires GD 2.2.0 or higher");
  9. }
  10. if (!function_exists('imagewebp') || !function_exists('imagecreatefromwebp'))
  11. die('skip WebP support not available');
  12. ?>
  13. --FILE--
  14. <?php
  15. require_once __DIR__ . '/similarity.inc';
  16. $filename = __DIR__ . '/webp_basic.webp';
  17. $im1 = imagecreatetruecolor(75, 75);
  18. $white = imagecolorallocate($im1, 255, 255, 255);
  19. $red = imagecolorallocate($im1, 255, 0, 0);
  20. $green = imagecolorallocate($im1, 0, 255, 0);
  21. $blue = imagecolorallocate($im1, 0, 0, 255);
  22. imagefilledrectangle($im1, 0, 0, 74, 74, $white);
  23. imageline($im1, 3, 3, 71, 71, $red);
  24. imageellipse($im1, 18, 54, 36, 36, $green);
  25. imagerectangle($im1, 41, 3, 71, 33, $blue);
  26. imagewebp($im1, $filename);
  27. $im2 = imagecreatefromwebp($filename);
  28. imagewebp($im2, $filename);
  29. echo 'Is lossy conversion close enough? ';
  30. var_dump(calc_image_dissimilarity($im1, $im2) < 10e5);
  31. imagewebp($im1, $filename, IMG_WEBP_LOSSLESS);
  32. $im_lossless = imagecreatefromwebp($filename);
  33. echo 'Does lossless conversion work? ';
  34. var_dump(calc_image_dissimilarity($im1, $im_lossless) == 0);
  35. ?>
  36. --CLEAN--
  37. <?php
  38. @unlink(__DIR__ . '/webp_basic.webp');
  39. ?>
  40. --EXPECT--
  41. Is lossy conversion close enough? bool(true)
  42. Does lossless conversion work? bool(true)