summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorChristoph M. Becker <cmbecker69@gmx.de>2016-06-19 14:29:27 +0200
committerChristoph M. Becker <cmbecker69@gmx.de>2016-09-11 12:56:53 +0200
commitdc09f309335cf8df7d39adc03580ac8d4f0c78f5 (patch)
tree1fbcf941a8fa538c889be5780e7e8dd24b81f07d /ext
parent326a4e38fbe8fd776624fc9891ad6a91a034504b (diff)
downloadphp-git-dc09f309335cf8df7d39adc03580ac8d4f0c78f5.tar.gz
A picture is worth a thousand message digests
The bundled GD test suites makes heavy use of md5() to verify the result of drawing operations. This leads to fragile tests (even a slight change in a PNG header would cause failure, and of course there is the possibility of collisions), and even worse, eventual test failures are rather unrevealing. Therefore we replace all md5() verification with a simplistic test_image_equals_file(), which is basically a simplified port of libgd's gdTestImageCompareToFile(), adapted to the needs of PHPTs. In the long run better tests helpers should be introduced (see also <http://news.php.net/php.internals/94081>), but for now this solution is preferable over the former. (cherry picked from commit 24f9e96792518ec2a75f26b1eb2471dd7694f2b7)
Diffstat (limited to 'ext')
-rw-r--r--ext/gd/tests/bug22544.phpt9
-rw-r--r--ext/gd/tests/bug22544.pngbin0 -> 284 bytes
-rw-r--r--ext/gd/tests/bug43828.phpt8
-rw-r--r--ext/gd/tests/bug43828.pngbin0 -> 656 bytes
-rw-r--r--ext/gd/tests/bug66005.phpt7
-rw-r--r--ext/gd/tests/bug66005.pngbin0 -> 430 bytes
-rw-r--r--ext/gd/tests/bug72604.phpt9
-rw-r--r--ext/gd/tests/bug72604.pngbin0 -> 700 bytes
-rw-r--r--ext/gd/tests/bug72913.phpt7
-rw-r--r--ext/gd/tests/bug72913.pngbin0 -> 147 bytes
-rw-r--r--ext/gd/tests/func.inc68
-rw-r--r--ext/gd/tests/imagearc_basic.phpt10
-rw-r--r--ext/gd/tests/imagearc_basic.pngbin0 -> 216 bytes
-rw-r--r--ext/gd/tests/imagearc_error1.phpt10
-rw-r--r--ext/gd/tests/imagearc_error1.pngbin0 -> 109 bytes
-rw-r--r--ext/gd/tests/imagearc_variation1.phpt10
-rw-r--r--ext/gd/tests/imagearc_variation1.pngbin0 -> 272 bytes
-rw-r--r--ext/gd/tests/imagearc_variation2.phpt10
-rw-r--r--ext/gd/tests/imagearc_variation2.pngbin0 -> 186 bytes
-rw-r--r--ext/gd/tests/imagechar_basic.phpt10
-rw-r--r--ext/gd/tests/imagechar_basic.pngbin0 -> 128 bytes
-rw-r--r--ext/gd/tests/imagecharup_basic.phpt10
-rw-r--r--ext/gd/tests/imagecharup_basic.pngbin0 -> 129 bytes
-rw-r--r--ext/gd/tests/imagecolorallocatealpha_basic.phpt10
-rw-r--r--ext/gd/tests/imagecolorallocatealpha_basic.pngbin0 -> 565 bytes
-rw-r--r--ext/gd/tests/imagecolorset_basic.phpt10
-rw-r--r--ext/gd/tests/imagecolorset_basic.pngbin0 -> 99 bytes
-rw-r--r--ext/gd/tests/imageconvolution_basic.phpt10
-rw-r--r--ext/gd/tests/imageconvolution_basic.pngbin0 -> 978 bytes
-rw-r--r--ext/gd/tests/imagecreatetruecolor_basic.phpt10
-rw-r--r--ext/gd/tests/imagecreatetruecolor_basic.pngbin0 -> 95 bytes
-rw-r--r--ext/gd/tests/imageellipse_basic.phpt10
-rw-r--r--ext/gd/tests/imageellipse_basic.pngbin0 -> 1474 bytes
-rw-r--r--ext/gd/tests/imagefilledarc_basic.phpt10
-rw-r--r--ext/gd/tests/imagefilledarc_basic.pngbin0 -> 200 bytes
-rw-r--r--ext/gd/tests/imagefilledarc_error1.phpt10
-rw-r--r--ext/gd/tests/imagefilledarc_error1.pngbin0 -> 109 bytes
-rw-r--r--ext/gd/tests/imagefilledarc_variation1.phpt10
-rw-r--r--ext/gd/tests/imagefilledarc_variation1.pngbin0 -> 281 bytes
-rw-r--r--ext/gd/tests/imagefilledarc_variation2.phpt10
-rw-r--r--ext/gd/tests/imagefilledarc_variation2.pngbin0 -> 197 bytes
-rw-r--r--ext/gd/tests/imagefilledellipse_basic.phpt10
-rw-r--r--ext/gd/tests/imagefilledellipse_basic.pngbin0 -> 274 bytes
-rw-r--r--ext/gd/tests/imagefilltoborder_basic.phpt10
-rw-r--r--ext/gd/tests/imagefilltoborder_basic.pngbin0 -> 530 bytes
-rw-r--r--ext/gd/tests/imagegammacorrect_basic.phpt14
-rw-r--r--ext/gd/tests/imagegammacorrect_basic.pngbin0 -> 363 bytes
-rw-r--r--ext/gd/tests/imagegammacorrect_variation1.phpt14
-rw-r--r--ext/gd/tests/imagegammacorrect_variation1.pngbin0 -> 199 bytes
-rw-r--r--ext/gd/tests/imagelayereffect_basic.phpt14
-rw-r--r--ext/gd/tests/imagelayereffect_basic.pngbin0 -> 95 bytes
-rw-r--r--ext/gd/tests/imagerectangle_basic.phpt11
-rw-r--r--ext/gd/tests/imagerectangle_basic.pngbin0 -> 220 bytes
-rw-r--r--ext/gd/tests/imagesetbrush_basic.phpt10
-rw-r--r--ext/gd/tests/imagesetbrush_basic.pngbin0 -> 161 bytes
-rw-r--r--ext/gd/tests/imagesetthickness_basic.phpt10
-rw-r--r--ext/gd/tests/imagesetthickness_basic.pngbin0 -> 377 bytes
-rw-r--r--ext/gd/tests/imagestring_basic.phpt10
-rw-r--r--ext/gd/tests/imagestring_basic.pngbin0 -> 234 bytes
-rw-r--r--ext/gd/tests/imagestringup_basic.phpt10
-rw-r--r--ext/gd/tests/imagestringup_basic.pngbin0 -> 163 bytes
-rw-r--r--ext/gd/tests/imagetruecolortopalette_basic.phpt10
-rw-r--r--ext/gd/tests/imagetruecolortopalette_basic.pngbin0 -> 208 bytes
-rw-r--r--ext/gd/tests/libgd00100.phpt10
-rw-r--r--ext/gd/tests/libgd00100.pngbin0 -> 2103 bytes
65 files changed, 172 insertions, 219 deletions
diff --git a/ext/gd/tests/bug22544.phpt b/ext/gd/tests/bug22544.phpt
index b18eef4332..3d4335d461 100644
--- a/ext/gd/tests/bug22544.phpt
+++ b/ext/gd/tests/bug22544.phpt
@@ -8,16 +8,13 @@ Bug #22544 (TrueColor transparency in PNG images).
?>
--FILE--
<?php
- $dest = dirname(realpath(__FILE__)) . '/bug22544.png';
- @unlink($dest);
$image = imageCreateTruecolor(640, 100);
$transparent = imageColorAllocate($image, 0, 0, 0);
$red = imageColorAllocate($image, 255, 50, 50);
imageColorTransparent($image, $transparent);
imageFilledRectangle($image, 0, 0, 640-1, 100-1, $transparent);
- imagegd($image, $dest);
- echo md5_file($dest) . "\n";
- @unlink($dest);
+ include_once __DIR__ . '/func.inc';
+ test_image_equals_file(__DIR__ . '/bug22544.png', $image);
?>
--EXPECT--
-7643ef115f642a79c2de6e411f485ddd
+The images are equal.
diff --git a/ext/gd/tests/bug22544.png b/ext/gd/tests/bug22544.png
new file mode 100644
index 0000000000..5e6251f440
--- /dev/null
+++ b/ext/gd/tests/bug22544.png
Binary files differ
diff --git a/ext/gd/tests/bug43828.phpt b/ext/gd/tests/bug43828.phpt
index 43d11ae356..0f130d28fd 100644
--- a/ext/gd/tests/bug43828.phpt
+++ b/ext/gd/tests/bug43828.phpt
@@ -17,10 +17,10 @@ imagefilledrectangle($im, 0,0, 99,99, $transparent);
$color = imagecolorallocatealpha($im, 0, 255, 0, 100);
imagefilledarc($im, 49, 49, 99,99, 0 , 360, $color, IMG_ARC_PIE);
-ob_start();
-imagegd($im);
-echo md5(ob_get_clean());
+include_once __DIR__ . '/func.inc';
+test_image_equals_file(__DIR__ . '/bug43828.png', $im);
+
imagedestroy($im);
?>
--EXPECT--
-2400a58cd7570b5472c25264715321cd
+The images are equal.
diff --git a/ext/gd/tests/bug43828.png b/ext/gd/tests/bug43828.png
new file mode 100644
index 0000000000..bb7fcd543e
--- /dev/null
+++ b/ext/gd/tests/bug43828.png
Binary files differ
diff --git a/ext/gd/tests/bug66005.phpt b/ext/gd/tests/bug66005.phpt
index a01c5c32b8..307b06855c 100644
--- a/ext/gd/tests/bug66005.phpt
+++ b/ext/gd/tests/bug66005.phpt
@@ -25,11 +25,10 @@ imagecopy($dest, $png_palette, 0, 0, 0, 0, 50, 50);
imagecopy($dest, $png_24, 50, 0, 0, 0, 50, 50);
imagecopy($dest, $png_full, 100, 0, 0, 0, 50, 50);
-ob_start();
-imagegd($dest);
-echo md5(ob_get_clean()), PHP_EOL;
+include_once __DIR__ . '/func.inc';
+test_image_equals_file(__DIR__ . '/bug66005.png', $dest);
?>
==DONE==
--EXPECT--
-9b36049de01006b367efd433f1689043
+The images are equal.
==DONE==
diff --git a/ext/gd/tests/bug66005.png b/ext/gd/tests/bug66005.png
new file mode 100644
index 0000000000..f654b3d0cd
--- /dev/null
+++ b/ext/gd/tests/bug66005.png
Binary files differ
diff --git a/ext/gd/tests/bug72604.phpt b/ext/gd/tests/bug72604.phpt
index edc3ce327f..f9592c05b7 100644
--- a/ext/gd/tests/bug72604.phpt
+++ b/ext/gd/tests/bug72604.phpt
@@ -10,10 +10,9 @@ if (!(imagetypes() & IMG_PNG)) die('skip requires PNG support');
$im = imagecreatetruecolor(100, 100);
imagesetthickness($im, 5);
imagearc($im, 50, 50, 90, 90, 0, 360, 0xffffff);
-ob_start();
-imagegd($im);
-$imagestring = ob_get_clean();
-echo md5($imagestring);
+
+include_once __DIR__ . '/func.inc';
+test_image_equals_file(__DIR__ . '/bug72604.png', $im);
?>
--EXPECT--
-4f5080080a774efe4fc8d55cd4a5849c
+The images are equal.
diff --git a/ext/gd/tests/bug72604.png b/ext/gd/tests/bug72604.png
new file mode 100644
index 0000000000..a3daed2bc0
--- /dev/null
+++ b/ext/gd/tests/bug72604.png
Binary files differ
diff --git a/ext/gd/tests/bug72913.phpt b/ext/gd/tests/bug72913.phpt
index 0ad03a7d3c..3ab068a134 100644
--- a/ext/gd/tests/bug72913.phpt
+++ b/ext/gd/tests/bug72913.phpt
@@ -19,11 +19,10 @@ imagesavealpha($dst, true);
imagecopy($dst, $src, 0,0, 0,0, 50,50);
-ob_start();
-imagegd($dst);
-echo md5(ob_get_clean()), PHP_EOL;
+include_once __DIR__ . '/func.inc';
+test_image_equals_file(__DIR__ . '/bug72913.png', $dst);
?>
==DONE==
--EXPECT--
-f03c27f20710e21debd7090c660f1a1e
+The images are equal.
==DONE==
diff --git a/ext/gd/tests/bug72913.png b/ext/gd/tests/bug72913.png
new file mode 100644
index 0000000000..83eeb81fb1
--- /dev/null
+++ b/ext/gd/tests/bug72913.png
Binary files differ
diff --git a/ext/gd/tests/func.inc b/ext/gd/tests/func.inc
index f17227eccd..01ba83102e 100644
--- a/ext/gd/tests/func.inc
+++ b/ext/gd/tests/func.inc
@@ -59,3 +59,71 @@ function get_libxpm_version()
return $version;
}
+/**
+ * Tests that an in-memory image equals a PNG file.
+ *
+ * It checks for equal image sizes, and whether any pixels are different.
+ * The textual result is printed, so the EXPECT section should contain the line
+ * "The images are equal."
+ *
+ * If the PNG file does not exists, or the images are not equal, a diagnostic
+ * message is printed, and the actual file is stored right beside the temporary
+ * .php test file with the extension .out.png, to be able to manually inspect
+ * the result.
+ *
+ * @param string $filename
+ * @param resource $actual
+ * @return void
+ */
+function test_image_equals_file($filename, $actual)
+{
+ if (!file_exists($filename)) {
+ echo "The expected image does not exist.\n";
+ save_actual_image($actual);
+ return;
+ }
+ $expected = imagecreatefrompng($filename);
+ $exp_x = imagesx($expected);
+ $exp_y = imagesy($expected);
+ $act_x = imagesx($actual);
+ $act_y = imagesy($actual);
+ if ($exp_x != $act_x || $exp_y != $act_y) {
+ echo "The image size differs: expected {$exp_x}x{$exp_y}, got {$act_x}x{$act_y}.\n";
+ save_actual_image($actual);
+ imagedestroy($expected);
+ return;
+ }
+ $pixels_changed = 0;
+ for ($y = 0; $y < $exp_y; $y++) {
+ for ($x = 0; $x < $exp_x; $x ++) {
+ $exp_c = imagecolorat($expected, $x, $y);
+ $act_c = imagecolorat($actual, $x, $y);
+ if ($exp_c != $act_c) {
+ $pixels_changed++;
+ }
+ }
+ }
+ if (!$pixels_changed) {
+ echo "The images are equal.\n";
+ } else {
+ echo "The images differ in {$pixels_changed} pixels.\n";
+ save_actual_image($actual);
+ }
+ imagedestroy($expected);
+}
+
+/**
+ * Saves an actual image to disk.
+ *
+ * The image is saved right beside the temporary .php test file with the
+ * extension .out.png.
+ *
+ * @param resource $image
+ * @return void
+ */
+function save_actual_image($image)
+{
+ $pathinfo = pathinfo($_SERVER['SCRIPT_FILENAME']);
+ $filename = "{$pathinfo['dirname']}/{$pathinfo['filename']}.out.png";
+ imagepng($image, $filename);
+}
diff --git a/ext/gd/tests/imagearc_basic.phpt b/ext/gd/tests/imagearc_basic.phpt
index 953428def9..b4761f2399 100644
--- a/ext/gd/tests/imagearc_basic.phpt
+++ b/ext/gd/tests/imagearc_basic.phpt
@@ -17,12 +17,8 @@ $white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
//create an arc with white color
imagearc($image, 50, 50, 30, 30, 0, 180, $white);
-ob_start();
-imagegd($image);
-$img = ob_get_contents();
-ob_end_clean();
-
-echo md5(base64_encode($img));
+include_once __DIR__ . '/func.inc';
+test_image_equals_file(__DIR__ . '/imagearc_basic.png', $image);
?>
--EXPECT--
-13149c3fd54a92a0d43cd5083a19b1d7
+The images are equal.
diff --git a/ext/gd/tests/imagearc_basic.png b/ext/gd/tests/imagearc_basic.png
new file mode 100644
index 0000000000..42a4d68988
--- /dev/null
+++ b/ext/gd/tests/imagearc_basic.png
Binary files differ
diff --git a/ext/gd/tests/imagearc_error1.phpt b/ext/gd/tests/imagearc_error1.phpt
index 05d1cd8186..1e63406832 100644
--- a/ext/gd/tests/imagearc_error1.phpt
+++ b/ext/gd/tests/imagearc_error1.phpt
@@ -17,13 +17,9 @@ $white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
//create an arc with white color
imagearc($image, 50, 50, 30, 30, 0, 180);
-ob_start();
-imagegd($image);
-$img = ob_get_contents();
-ob_end_clean();
-
-echo md5(base64_encode($img));
+include_once __DIR__ . '/func.inc';
+test_image_equals_file(__DIR__ . '/imagearc_error1.png', $image);
?>
--EXPECTF--
Warning: imagearc() expects exactly 8 parameters, 7 given in %s on line %d
-c5b7013900f5466aebfc42499a7ec8ec
+The images are equal.
diff --git a/ext/gd/tests/imagearc_error1.png b/ext/gd/tests/imagearc_error1.png
new file mode 100644
index 0000000000..9cbff6e164
--- /dev/null
+++ b/ext/gd/tests/imagearc_error1.png
Binary files differ
diff --git a/ext/gd/tests/imagearc_variation1.phpt b/ext/gd/tests/imagearc_variation1.phpt
index aaf6103b43..1b36eedf29 100644
--- a/ext/gd/tests/imagearc_variation1.phpt
+++ b/ext/gd/tests/imagearc_variation1.phpt
@@ -17,12 +17,8 @@ $white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
//create an arc with white color
imagearc($image, 50, 50, 30, 30, 0, -90, $white);
-ob_start();
-imagegd($image);
-$img = ob_get_contents();
-ob_end_clean();
-
-echo md5(base64_encode($img));
+include_once __DIR__ . '/func.inc';
+test_image_equals_file(__DIR__ . '/imagearc_variation1.png', $image);
?>
--EXPECT--
-fe662ebe7488057c43e38c5de43b1727
+The images are equal.
diff --git a/ext/gd/tests/imagearc_variation1.png b/ext/gd/tests/imagearc_variation1.png
new file mode 100644
index 0000000000..8bc15c423f
--- /dev/null
+++ b/ext/gd/tests/imagearc_variation1.png
Binary files differ
diff --git a/ext/gd/tests/imagearc_variation2.phpt b/ext/gd/tests/imagearc_variation2.phpt
index 0c1c6466e1..40227c3750 100644
--- a/ext/gd/tests/imagearc_variation2.phpt
+++ b/ext/gd/tests/imagearc_variation2.phpt
@@ -17,12 +17,8 @@ $white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
//create an arc with white color
imagearc($image, 50, 50, 30, 30, -90, 0, $white);
-ob_start();
-imagegd($image);
-$img = ob_get_contents();
-ob_end_clean();
-
-echo md5(base64_encode($img));
+include_once __DIR__ . '/func.inc';
+test_image_equals_file(__DIR__ . '/imagearc_variation2.png', $image);
?>
--EXPECT--
-8bd78aa775b5f29e7227eaeebaa84889
+The images are equal.
diff --git a/ext/gd/tests/imagearc_variation2.png b/ext/gd/tests/imagearc_variation2.png
new file mode 100644
index 0000000000..40779ed457
--- /dev/null
+++ b/ext/gd/tests/imagearc_variation2.png
Binary files differ
diff --git a/ext/gd/tests/imagechar_basic.phpt b/ext/gd/tests/imagechar_basic.phpt
index fa6dd4d935..f238aabae4 100644
--- a/ext/gd/tests/imagechar_basic.phpt
+++ b/ext/gd/tests/imagechar_basic.phpt
@@ -14,12 +14,8 @@ $white = imagecolorallocate($image, 255,255,255);
$result = imagechar($image, 1, 5, 5, 'C', $white);
-ob_start();
-imagegd($image);
-$img = ob_get_contents();
-ob_end_clean();
-
-echo md5(base64_encode($img));
+include_once __DIR__ . '/func.inc';
+test_image_equals_file(__DIR__ . '/imagechar_basic.png', $image);
?>
--EXPECT--
-f0291252e7ac2fadda25e63287e6860c
+The images are equal.
diff --git a/ext/gd/tests/imagechar_basic.png b/ext/gd/tests/imagechar_basic.png
new file mode 100644
index 0000000000..a01222aab8
--- /dev/null
+++ b/ext/gd/tests/imagechar_basic.png
Binary files differ
diff --git a/ext/gd/tests/imagecharup_basic.phpt b/ext/gd/tests/imagecharup_basic.phpt
index 194c32564d..50b0a59613 100644
--- a/ext/gd/tests/imagecharup_basic.phpt
+++ b/ext/gd/tests/imagecharup_basic.phpt
@@ -14,12 +14,8 @@ $white = imagecolorallocate($image, 255,255,255);
$result = imagecharup($image, 1, 5, 5, 'C', $white);
-ob_start();
-imagegd($image);
-$img = ob_get_contents();
-ob_end_clean();
-
-echo md5(base64_encode($img));
+include_once __DIR__ . '/func.inc';
+test_image_equals_file(__DIR__ . '/imagecharup_basic.png', $image);
?>
--EXPECT--
-c65aad5d78f934dee2a844e7978eabd5
+The images are equal.
diff --git a/ext/gd/tests/imagecharup_basic.png b/ext/gd/tests/imagecharup_basic.png
new file mode 100644
index 0000000000..e9628658ff
--- /dev/null
+++ b/ext/gd/tests/imagecharup_basic.png
Binary files differ
diff --git a/ext/gd/tests/imagecolorallocatealpha_basic.phpt b/ext/gd/tests/imagecolorallocatealpha_basic.phpt
index 8595b40507..f0d1e45e6e 100644
--- a/ext/gd/tests/imagecolorallocatealpha_basic.phpt
+++ b/ext/gd/tests/imagecolorallocatealpha_basic.phpt
@@ -20,14 +20,10 @@ $corA = imagecolorallocatealpha($img, 50, 100, 255, 50);
$half = imagefilledarc ( $img, 75, 75, 70, 70, 0, 180, $cor, IMG_ARC_PIE );
$half2 = imagefilledarc ( $img, 75, 75, 70, 70, 180, 360, $corA, IMG_ARC_PIE );
-ob_start();
-imagegd($img);
-$imgsrc = ob_get_contents();
-ob_end_clean();
-
-var_dump(md5(base64_encode($imgsrc)));
+include_once __DIR__ . '/func.inc';
+test_image_equals_file(__DIR__ . '/imagecolorallocatealpha_basic.png', $img);
var_dump($corA);
?>
--EXPECT--
-string(32) "0981ef94ee2209a8dccb59aa8ad07e18"
+The images are equal.
int(842163455) \ No newline at end of file
diff --git a/ext/gd/tests/imagecolorallocatealpha_basic.png b/ext/gd/tests/imagecolorallocatealpha_basic.png
new file mode 100644
index 0000000000..ef975af392
--- /dev/null
+++ b/ext/gd/tests/imagecolorallocatealpha_basic.png
Binary files differ
diff --git a/ext/gd/tests/imagecolorset_basic.phpt b/ext/gd/tests/imagecolorset_basic.phpt
index 01e5f7bfd5..f051a2202f 100644
--- a/ext/gd/tests/imagecolorset_basic.phpt
+++ b/ext/gd/tests/imagecolorset_basic.phpt
@@ -23,13 +23,9 @@ $bg = imagecolorat($im, 0, 0);
// Set the backgrund to be blue
imagecolorset($im, $bg, 0, 0, 255);
-// Get output and generate md5 hash
-ob_start();
-imagegd($im);
-$result_image = ob_get_contents();
-ob_end_clean();
-echo md5(base64_encode($result_image));
+include_once __DIR__ . '/func.inc';
+test_image_equals_file(__DIR__ . '/imagecolorset_basic.png', $im);
imagedestroy($im);
?>
--EXPECT--
-85e406abd0a975c97b3403cad5d078c9
+The images are equal.
diff --git a/ext/gd/tests/imagecolorset_basic.png b/ext/gd/tests/imagecolorset_basic.png
new file mode 100644
index 0000000000..b9e77d1169
--- /dev/null
+++ b/ext/gd/tests/imagecolorset_basic.png
Binary files differ
diff --git a/ext/gd/tests/imageconvolution_basic.phpt b/ext/gd/tests/imageconvolution_basic.phpt
index 9e629ac0e6..972de76f86 100644
--- a/ext/gd/tests/imageconvolution_basic.phpt
+++ b/ext/gd/tests/imageconvolution_basic.phpt
@@ -22,12 +22,8 @@ $gaussian = array(
imageconvolution($image, $gaussian, 16, 0);
-ob_start();
-imagegd($image);
-$img = ob_get_contents();
-ob_end_clean();
-
-echo md5(base64_encode($img));
+include_once __DIR__ . '/func.inc';
+test_image_equals_file(__DIR__ . '/imageconvolution_basic.png', $image);
?>
--EXPECT--
-20979b45f8772cdbd78262af4e332638
+The images are equal.
diff --git a/ext/gd/tests/imageconvolution_basic.png b/ext/gd/tests/imageconvolution_basic.png
new file mode 100644
index 0000000000..0558a1bb36
--- /dev/null
+++ b/ext/gd/tests/imageconvolution_basic.png
Binary files differ
diff --git a/ext/gd/tests/imagecreatetruecolor_basic.phpt b/ext/gd/tests/imagecreatetruecolor_basic.phpt
index a6eced15b3..e2a5a09fba 100644
--- a/ext/gd/tests/imagecreatetruecolor_basic.phpt
+++ b/ext/gd/tests/imagecreatetruecolor_basic.phpt
@@ -11,12 +11,8 @@ Rafael Dohms <rdohms [at] gmail [dot] com>
<?php
$image = imagecreatetruecolor(180, 30);
-ob_start();
-imagegd($image);
-$img = ob_get_contents();
-ob_end_clean();
-
-echo md5(base64_encode($img));
+include_once __DIR__ . '/func.inc';
+test_image_equals_file(__DIR__ . '/imagecreatetruecolor_basic.png', $image);
?>
--EXPECT--
-da884f488a851e0267a316ad232aee86
+The images are equal.
diff --git a/ext/gd/tests/imagecreatetruecolor_basic.png b/ext/gd/tests/imagecreatetruecolor_basic.png
new file mode 100644
index 0000000000..1728cb4d80
--- /dev/null
+++ b/ext/gd/tests/imagecreatetruecolor_basic.png
Binary files differ
diff --git a/ext/gd/tests/imageellipse_basic.phpt b/ext/gd/tests/imageellipse_basic.phpt
index 759e42ab72..f3b1e10bfe 100644
--- a/ext/gd/tests/imageellipse_basic.phpt
+++ b/ext/gd/tests/imageellipse_basic.phpt
@@ -16,12 +16,8 @@ $image = imagecreatetruecolor(400, 300);
// Draw a white ellipse
imageellipse($image, 200, 150, 300, 200, 16777215);
-ob_start();
-imagegd($image);
-$img = ob_get_contents();
-ob_end_clean();
-
-echo md5(base64_encode($img));
+include_once __DIR__ . '/func.inc';
+test_image_equals_file(__DIR__ . '/imageellipse_basic.png', $image);
?>
--EXPECT--
-49c1544b012c3460c74cd04f1332d4ad
+The images are equal.
diff --git a/ext/gd/tests/imageellipse_basic.png b/ext/gd/tests/imageellipse_basic.png
new file mode 100644
index 0000000000..7dda55a186
--- /dev/null
+++ b/ext/gd/tests/imageellipse_basic.png
Binary files differ
diff --git a/ext/gd/tests/imagefilledarc_basic.phpt b/ext/gd/tests/imagefilledarc_basic.phpt
index 8c76a83406..9969e6be95 100644
--- a/ext/gd/tests/imagefilledarc_basic.phpt
+++ b/ext/gd/tests/imagefilledarc_basic.phpt
@@ -20,12 +20,8 @@ $white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
//create an arc and fill it with white color
imagefilledarc($image, 50, 50, 30, 30, 0, 90, $white, IMG_ARC_PIE);
-ob_start();
-imagegd($image);
-$img = ob_get_contents();
-ob_end_clean();
-
-echo md5(base64_encode($img));
+include_once __DIR__ . '/func.inc';
+test_image_equals_file(__DIR__ . '/imagefilledarc_basic.png', $image);
?>
--EXPECT--
-87637c60ac0ceea48dbcaa4d98319f90
+The images are equal.
diff --git a/ext/gd/tests/imagefilledarc_basic.png b/ext/gd/tests/imagefilledarc_basic.png
new file mode 100644
index 0000000000..b6bfc61085
--- /dev/null
+++ b/ext/gd/tests/imagefilledarc_basic.png
Binary files differ
diff --git a/ext/gd/tests/imagefilledarc_error1.phpt b/ext/gd/tests/imagefilledarc_error1.phpt
index 46d51ba34b..81d04358fb 100644
--- a/ext/gd/tests/imagefilledarc_error1.phpt
+++ b/ext/gd/tests/imagefilledarc_error1.phpt
@@ -17,13 +17,9 @@ $white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
//create an arc and fill it with white color
imagefilledarc($image, 50, 50, 30, 30, 0, 90, $white);
-ob_start();
-imagegd($image);
-$img = ob_get_contents();
-ob_end_clean();
-
-echo md5(base64_encode($img));
+include_once __DIR__ . '/func.inc';
+test_image_equals_file(__DIR__ . '/imagefilledarc_error1.png', $image);
?>
--EXPECTF--
Warning: imagefilledarc() expects exactly 9 parameters, 8 given in %s on line %d
-c5b7013900f5466aebfc42499a7ec8ec
+The images are equal.
diff --git a/ext/gd/tests/imagefilledarc_error1.png b/ext/gd/tests/imagefilledarc_error1.png
new file mode 100644
index 0000000000..9cbff6e164
--- /dev/null
+++ b/ext/gd/tests/imagefilledarc_error1.png
Binary files differ
diff --git a/ext/gd/tests/imagefilledarc_variation1.phpt b/ext/gd/tests/imagefilledarc_variation1.phpt
index f4130a9c69..7eb2350cb3 100644
--- a/ext/gd/tests/imagefilledarc_variation1.phpt
+++ b/ext/gd/tests/imagefilledarc_variation1.phpt
@@ -20,12 +20,8 @@ $white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
//create an arc and fill it with white color
imagefilledarc($image, 50, 50, 30, 30, 0, -25, $white, IMG_ARC_PIE);
-ob_start();
-imagegd($image);
-$img = ob_get_contents();
-ob_end_clean();
-
-echo md5(base64_encode($img));
+include_once __DIR__ . '/func.inc';
+test_image_equals_file(__DIR__ . '/imagefilledarc_variation1.png', $image);
?>
--EXPECT--
-f25f589b5c5fa7deead7242652919bcf
+The images are equal.
diff --git a/ext/gd/tests/imagefilledarc_variation1.png b/ext/gd/tests/imagefilledarc_variation1.png
new file mode 100644
index 0000000000..802d22784c
--- /dev/null
+++ b/ext/gd/tests/imagefilledarc_variation1.png
Binary files differ
diff --git a/ext/gd/tests/imagefilledarc_variation2.phpt b/ext/gd/tests/imagefilledarc_variation2.phpt
index 033d6f65f0..28cb517631 100644
--- a/ext/gd/tests/imagefilledarc_variation2.phpt
+++ b/ext/gd/tests/imagefilledarc_variation2.phpt
@@ -20,12 +20,8 @@ $white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
//create an arc and fill it with white color
imagefilledarc($image, 50, 50, 30, 30, -25, 25, $white, IMG_ARC_PIE);
-ob_start();
-imagegd($image);
-$img = ob_get_contents();
-ob_end_clean();
-
-echo md5(base64_encode($img));
+include_once __DIR__ . '/func.inc';
+test_image_equals_file(__DIR__ . '/imagefilledarc_variation2.png', $image);
?>
--EXPECT--
-43c2973eb4872903eb6f5464c7965a93
+The images are equal.
diff --git a/ext/gd/tests/imagefilledarc_variation2.png b/ext/gd/tests/imagefilledarc_variation2.png
new file mode 100644
index 0000000000..7f3930bbac
--- /dev/null
+++ b/ext/gd/tests/imagefilledarc_variation2.png
Binary files differ
diff --git a/ext/gd/tests/imagefilledellipse_basic.phpt b/ext/gd/tests/imagefilledellipse_basic.phpt
index 8b3682bfa8..1dee961b13 100644
--- a/ext/gd/tests/imagefilledellipse_basic.phpt
+++ b/ext/gd/tests/imagefilledellipse_basic.phpt
@@ -14,12 +14,8 @@ $white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
//create an ellipse and fill it with white color
imagefilledellipse($image, 50, 50, 40, 30, $white);
-ob_start();
-imagegd($image);
-$img = ob_get_contents();
-ob_end_clean();
-
-echo md5(base64_encode($img));
+include_once __DIR__ . '/func.inc';
+test_image_equals_file(__DIR__ . '/imagefilledellipse_basic.png', $image);
?>
--EXPECT--
-233beffe003a41d3c9e788039e3191dd
+The images are equal.
diff --git a/ext/gd/tests/imagefilledellipse_basic.png b/ext/gd/tests/imagefilledellipse_basic.png
new file mode 100644
index 0000000000..8a56bec574
--- /dev/null
+++ b/ext/gd/tests/imagefilledellipse_basic.png
Binary files differ
diff --git a/ext/gd/tests/imagefilltoborder_basic.phpt b/ext/gd/tests/imagefilltoborder_basic.phpt
index 524022a15d..843eed473d 100644
--- a/ext/gd/tests/imagefilltoborder_basic.phpt
+++ b/ext/gd/tests/imagefilltoborder_basic.phpt
@@ -21,13 +21,9 @@ imageellipse( $image, 50, 50, 50, 50, imagecolorallocate( $image, 0, 0, 0 ) );
// Fill border
imagefilltoborder( $image, 50, 50, imagecolorallocate( $image, 0, 0, 0 ), imagecolorallocate( $image, 255, 0, 0 ) );
-ob_start();
-imagegd( $image);
-$img = ob_get_contents();
-ob_end_clean();
-
-echo md5(base64_encode($img));
+include_once __DIR__ . '/func.inc';
+test_image_equals_file(__DIR__ . '/imagefilltoborder_basic.png', $image);
?>
--EXPECT--
-8185a06ccff03c2abeb99d5e3ed60e45
+The images are equal.
diff --git a/ext/gd/tests/imagefilltoborder_basic.png b/ext/gd/tests/imagefilltoborder_basic.png
new file mode 100644
index 0000000000..7c163e3c49
--- /dev/null
+++ b/ext/gd/tests/imagefilltoborder_basic.png
Binary files differ
diff --git a/ext/gd/tests/imagegammacorrect_basic.phpt b/ext/gd/tests/imagegammacorrect_basic.phpt
index b803e9517f..c315c4688e 100644
--- a/ext/gd/tests/imagegammacorrect_basic.phpt
+++ b/ext/gd/tests/imagegammacorrect_basic.phpt
@@ -21,15 +21,11 @@ $half = imagefilledarc ( $image, 75, 75, 70, 70, 0, 180, $grey, IMG_ARC_PIE );
$half2 = imagefilledarc ( $image, 75, 75, 70, 70, 0, -180, $gray, IMG_ARC_PIE );
$gamma = imagegammacorrect($image, 1, 5);
+var_dump((bool) $gamma);
-if ($gamma){
- ob_start();
- imagegd($image);
- $img = ob_get_contents();
- ob_end_clean();
-}
-
-echo md5(base64_encode($img));
+include_once __DIR__ . '/func.inc';
+test_image_equals_file(__DIR__ . '/imagegammacorrect_basic.png', $image);
?>
--EXPECT--
-1f625723f9d27251a1f15b83a6a4bf55 \ No newline at end of file
+bool(true)
+The images are equal.
diff --git a/ext/gd/tests/imagegammacorrect_basic.png b/ext/gd/tests/imagegammacorrect_basic.png
new file mode 100644
index 0000000000..9eeaf26cb2
--- /dev/null
+++ b/ext/gd/tests/imagegammacorrect_basic.png
Binary files differ
diff --git a/ext/gd/tests/imagegammacorrect_variation1.phpt b/ext/gd/tests/imagegammacorrect_variation1.phpt
index a0df819a7d..73327c1eff 100644
--- a/ext/gd/tests/imagegammacorrect_variation1.phpt
+++ b/ext/gd/tests/imagegammacorrect_variation1.phpt
@@ -21,15 +21,11 @@ $half = imagefilledarc ( $image, 75, 75, 70, 70, 0, 180, $grey, IMG_ARC_PIE );
$half2 = imagefilledarc ( $image, 75, 75, 70, 70, 0, -180, $gray, IMG_ARC_PIE );
$gamma = imagegammacorrect($image, 1, 5);
+var_dump((bool) $gamma);
-if ($gamma){
- ob_start();
- imagegd($image);
- $img = ob_get_contents();
- ob_end_clean();
-}
-
-echo md5(base64_encode($img));
+include_once __DIR__ . '/func.inc';
+test_image_equals_file(__DIR__ . '/imagegammacorrect_variation1.png', $image);
?>
--EXPECT--
-32fdb7b3675e4a9fd601c6a0645c88b3
+bool(true)
+The images are equal.
diff --git a/ext/gd/tests/imagegammacorrect_variation1.png b/ext/gd/tests/imagegammacorrect_variation1.png
new file mode 100644
index 0000000000..f971889096
--- /dev/null
+++ b/ext/gd/tests/imagegammacorrect_variation1.png
Binary files differ
diff --git a/ext/gd/tests/imagelayereffect_basic.phpt b/ext/gd/tests/imagelayereffect_basic.phpt
index 2f1ee47aaf..2c948fd0c5 100644
--- a/ext/gd/tests/imagelayereffect_basic.phpt
+++ b/ext/gd/tests/imagelayereffect_basic.phpt
@@ -13,15 +13,11 @@ Rafael Dohms <rdohms [at] gmail [dot] com>
$image = imagecreatetruecolor(180, 30);
$layer = imagelayereffect($image, IMG_EFFECT_REPLACE);
+var_dump((bool) $layer);
-if ($layer){
- ob_start();
- imagegd($image);
- $img = ob_get_contents();
- ob_end_clean();
-}
-
-echo md5(base64_encode($img));
+include_once __DIR__ . '/func.inc';
+test_image_equals_file(__DIR__ . '/imagelayereffect_basic.png', $image);
?>
--EXPECT--
-da884f488a851e0267a316ad232aee86
+bool(true)
+The images are equal.
diff --git a/ext/gd/tests/imagelayereffect_basic.png b/ext/gd/tests/imagelayereffect_basic.png
new file mode 100644
index 0000000000..1728cb4d80
--- /dev/null
+++ b/ext/gd/tests/imagelayereffect_basic.png
Binary files differ
diff --git a/ext/gd/tests/imagerectangle_basic.phpt b/ext/gd/tests/imagerectangle_basic.phpt
index eaa1566f7f..507d715326 100644
--- a/ext/gd/tests/imagerectangle_basic.phpt
+++ b/ext/gd/tests/imagerectangle_basic.phpt
@@ -15,13 +15,8 @@ $image = imagecreatetruecolor( 100, 100 );
// Draw a rectangle
imagerectangle( $image, 0, 0, 50, 50, imagecolorallocate($image, 255, 255, 255) );
-ob_start();
-imagegd( $image );
-$img = ob_get_contents();
-ob_end_clean();
-
-echo md5(base64_encode($img));
-
+include_once __DIR__ . '/func.inc';
+test_image_equals_file(__DIR__ . '/imagerectangle_basic.png', $image);
?>
--EXPECT--
-e7f8ca8c63fb08b248f3ed6435983aed \ No newline at end of file
+The images are equal.
diff --git a/ext/gd/tests/imagerectangle_basic.png b/ext/gd/tests/imagerectangle_basic.png
new file mode 100644
index 0000000000..dcb4d2e630
--- /dev/null
+++ b/ext/gd/tests/imagerectangle_basic.png
Binary files differ
diff --git a/ext/gd/tests/imagesetbrush_basic.phpt b/ext/gd/tests/imagesetbrush_basic.phpt
index 763a4c414d..e1a9c6a80c 100644
--- a/ext/gd/tests/imagesetbrush_basic.phpt
+++ b/ext/gd/tests/imagesetbrush_basic.phpt
@@ -26,12 +26,8 @@ imagesetbrush($mainimg, $img);
// Draw a couple of brushes, each overlaying each
imageline($mainimg, 50, 50, 50, 60, IMG_COLOR_BRUSHED);
-// Get output and generate md5 hash
-ob_start();
-imagegd($mainimg);
-$result_image = ob_get_contents();
-ob_end_clean();
-echo md5(base64_encode($result_image));
+include_once __DIR__ . '/func.inc';
+test_image_equals_file(__DIR__ . '/imagesetbrush_basic.png', $mainimg);
?>
--EXPECT--
-2bb294c388d826cc9bba6c6fd31f265a
+The images are equal.
diff --git a/ext/gd/tests/imagesetbrush_basic.png b/ext/gd/tests/imagesetbrush_basic.png
new file mode 100644
index 0000000000..0242634db5
--- /dev/null
+++ b/ext/gd/tests/imagesetbrush_basic.png
Binary files differ
diff --git a/ext/gd/tests/imagesetthickness_basic.phpt b/ext/gd/tests/imagesetthickness_basic.phpt
index 205fe7e59e..3c91a886df 100644
--- a/ext/gd/tests/imagesetthickness_basic.phpt
+++ b/ext/gd/tests/imagesetthickness_basic.phpt
@@ -23,12 +23,8 @@ imagesetthickness($image, 5);
// Draw the rectangle
imagerectangle($image, 14, 14, 185, 85, $black);
-ob_start();
-imagegd($image);
-$img = ob_get_contents();
-ob_end_clean();
-
-echo md5(base64_encode($img));
+include_once __DIR__ . '/func.inc';
+test_image_equals_file(__DIR__ . '/imagesetthickness_basic.png', $image);
?>
--EXPECT--
-1a6bc882772310d2e9b32cca2574236c \ No newline at end of file
+The images are equal.
diff --git a/ext/gd/tests/imagesetthickness_basic.png b/ext/gd/tests/imagesetthickness_basic.png
new file mode 100644
index 0000000000..e38e7dbe00
--- /dev/null
+++ b/ext/gd/tests/imagesetthickness_basic.png
Binary files differ
diff --git a/ext/gd/tests/imagestring_basic.phpt b/ext/gd/tests/imagestring_basic.phpt
index f56a2d3226..311683f7af 100644
--- a/ext/gd/tests/imagestring_basic.phpt
+++ b/ext/gd/tests/imagestring_basic.phpt
@@ -14,12 +14,8 @@ $white = imagecolorallocate($image, 255,255,255);
$result = imagestring($image, 1, 5, 5, 'String Text', $white);
-ob_start();
-imagegd($image);
-$img = ob_get_contents();
-ob_end_clean();
-
-echo md5(base64_encode($img));
+include_once __DIR__ . '/func.inc';
+test_image_equals_file(__DIR__ . '/imagestring_basic.png', $image);
?>
--EXPECT--
-7f146e3cdcaf89c6b9d68ccbb44cf94e
+The images are equal.
diff --git a/ext/gd/tests/imagestring_basic.png b/ext/gd/tests/imagestring_basic.png
new file mode 100644
index 0000000000..7f9fd12c12
--- /dev/null
+++ b/ext/gd/tests/imagestring_basic.png
Binary files differ
diff --git a/ext/gd/tests/imagestringup_basic.phpt b/ext/gd/tests/imagestringup_basic.phpt
index 144dfc0d8d..015d375ede 100644
--- a/ext/gd/tests/imagestringup_basic.phpt
+++ b/ext/gd/tests/imagestringup_basic.phpt
@@ -14,12 +14,8 @@ $white = imagecolorallocate($image, 255,255,255);
$result = imagestringup($image, 1, 5, 25, 'Str', $white);
-ob_start();
-imagegd($image);
-$img = ob_get_contents();
-ob_end_clean();
-
-echo md5(base64_encode($img));
+include_once __DIR__ . '/func.inc';
+test_image_equals_file(__DIR__ . '/imagestringup_basic.png', $image);
?>
--EXPECT--
-7c55836800702bdd43b4c25d8ebcfcd0
+The images are equal.
diff --git a/ext/gd/tests/imagestringup_basic.png b/ext/gd/tests/imagestringup_basic.png
new file mode 100644
index 0000000000..875b5bae95
--- /dev/null
+++ b/ext/gd/tests/imagestringup_basic.png
Binary files differ
diff --git a/ext/gd/tests/imagetruecolortopalette_basic.phpt b/ext/gd/tests/imagetruecolortopalette_basic.phpt
index e7b327475b..9bc922a15b 100644
--- a/ext/gd/tests/imagetruecolortopalette_basic.phpt
+++ b/ext/gd/tests/imagetruecolortopalette_basic.phpt
@@ -22,13 +22,9 @@ $half2 = imagefilledarc ( $image, 75, 55, 80, 70, 0, -180, $b, IMG_ARC_PIE );
var_dump(imagetruecolortopalette($image, true, 2));
-ob_start();
-imagegd($image);
-$img = ob_get_contents();
-ob_end_clean();
-
-echo md5(base64_encode($img));
+include_once __DIR__ . '/func.inc';
+test_image_equals_file(__DIR__ . '/imagetruecolortopalette_basic.png', $image);
?>
--EXPECT--
bool(true)
-17c901cb2217eb7647deed1c79d445de \ No newline at end of file
+The images are equal.
diff --git a/ext/gd/tests/imagetruecolortopalette_basic.png b/ext/gd/tests/imagetruecolortopalette_basic.png
new file mode 100644
index 0000000000..7d042f2ac3
--- /dev/null
+++ b/ext/gd/tests/imagetruecolortopalette_basic.png
Binary files differ
diff --git a/ext/gd/tests/libgd00100.phpt b/ext/gd/tests/libgd00100.phpt
index 49716d7107..84f8858a9a 100644
--- a/ext/gd/tests/libgd00100.phpt
+++ b/ext/gd/tests/libgd00100.phpt
@@ -106,14 +106,10 @@ $points = array(
);
imagefilledpolygon($im, $points, 5, $black);
-ob_start();
-imagegd($im);
-$png = ob_get_contents();
-ob_end_clean();
-
-echo md5($png);
+include_once __DIR__ . '/func.inc';
+test_image_equals_file(__DIR__ . '/libgd00100.png', $im);
imagedestroy($im);
?>
--EXPECTF--
-df7253c765280396f303166f10ba9283
+The images are equal.
diff --git a/ext/gd/tests/libgd00100.png b/ext/gd/tests/libgd00100.png
new file mode 100644
index 0000000000..8d4f6a1be8
--- /dev/null
+++ b/ext/gd/tests/libgd00100.png
Binary files differ