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