webp_basic.phpt 1.1 KB

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