From: Christoph M. Becker Date: Sun, 19 Jul 2015 21:03:02 +0000 (+0200) Subject: Added basic test for imagewebp() and imagecreatefromwebp() X-Git-Tag: php-5.6.12RC1~8 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=90de2aeaac3de8f0744853ba197457c2241a4bdf;p=php Added basic test for imagewebp() and imagecreatefromwebp() --- diff --git a/ext/gd/tests/similarity.inc b/ext/gd/tests/similarity.inc new file mode 100644 index 0000000000..cb0dba77f2 --- /dev/null +++ b/ext/gd/tests/similarity.inc @@ -0,0 +1,64 @@ +> 16) & 0xFF; + $green = ($color >> 8) & 0xFF; + $blue = $color & 0xFF; +} + +/** + * Calculates the euclidean distance of two RGB values. + * + * @param int $color1 + * @param int $color2 + * + * @return int + */ +function calc_pixel_distance($color1, $color2) +{ + get_rgb($color1, $red1, $green1, $blue1); + get_rgb($color2, $red2, $green2, $blue2); + return sqrt( + pow($red1 - $red2, 2) + pow($green1 - $green2, 2) + pow($blue1 - $blue2, 2) + ); +} + +/** + * Calculates dissimilarity of two images. + * + * @param resource $image1 + * @param resource $image2 + * + * @return int The dissimilarity. 0 means the images are identical. The higher + * the value, the more dissimilar are the images. + */ +function calc_image_dissimilarity($image1, $image2) +{ + // assumes image1 and image2 have same width and height + $dissimilarity = 0; + for ($i = 0, $n = imagesx($image1); $i < $n; $i++) { + for ($j = 0, $m = imagesy($image1); $j < $m; $j++) { + $color1 = imagecolorat($image1, $i, $j); + $color2 = imagecolorat($image2, $i, $j); + $dissimilarity += calc_pixel_distance($color1, $color2); + } + } + return $dissimilarity; +} diff --git a/ext/gd/tests/webp_basic.phpt b/ext/gd/tests/webp_basic.phpt new file mode 100644 index 0000000000..75933a9ca4 --- /dev/null +++ b/ext/gd/tests/webp_basic.phpt @@ -0,0 +1,35 @@ +--TEST-- +imagewebp() and imagecreatefromwebp() - basic test +--SKIPIF-- + +--FILE-- + +--CLEAN-- + +--EXPECT-- +bool(true)