]> granicus.if.org Git - php/commitdiff
A picture is worth a thousand message digests
authorChristoph M. Becker <cmbecker69@gmx.de>
Sun, 19 Jun 2016 12:29:27 +0000 (14:29 +0200)
committerChristoph M. Becker <cmbecker69@gmx.de>
Sun, 11 Sep 2016 10:56:53 +0000 (12:56 +0200)
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)

66 files changed:
.gitignore
ext/gd/tests/bug22544.phpt
ext/gd/tests/bug22544.png [new file with mode: 0644]
ext/gd/tests/bug43828.phpt
ext/gd/tests/bug43828.png [new file with mode: 0644]
ext/gd/tests/bug66005.phpt
ext/gd/tests/bug66005.png [new file with mode: 0644]
ext/gd/tests/bug72604.phpt
ext/gd/tests/bug72604.png [new file with mode: 0644]
ext/gd/tests/bug72913.phpt
ext/gd/tests/bug72913.png [new file with mode: 0644]
ext/gd/tests/func.inc
ext/gd/tests/imagearc_basic.phpt
ext/gd/tests/imagearc_basic.png [new file with mode: 0644]
ext/gd/tests/imagearc_error1.phpt
ext/gd/tests/imagearc_error1.png [new file with mode: 0644]
ext/gd/tests/imagearc_variation1.phpt
ext/gd/tests/imagearc_variation1.png [new file with mode: 0644]
ext/gd/tests/imagearc_variation2.phpt
ext/gd/tests/imagearc_variation2.png [new file with mode: 0644]
ext/gd/tests/imagechar_basic.phpt
ext/gd/tests/imagechar_basic.png [new file with mode: 0644]
ext/gd/tests/imagecharup_basic.phpt
ext/gd/tests/imagecharup_basic.png [new file with mode: 0644]
ext/gd/tests/imagecolorallocatealpha_basic.phpt
ext/gd/tests/imagecolorallocatealpha_basic.png [new file with mode: 0644]
ext/gd/tests/imagecolorset_basic.phpt
ext/gd/tests/imagecolorset_basic.png [new file with mode: 0644]
ext/gd/tests/imageconvolution_basic.phpt
ext/gd/tests/imageconvolution_basic.png [new file with mode: 0644]
ext/gd/tests/imagecreatetruecolor_basic.phpt
ext/gd/tests/imagecreatetruecolor_basic.png [new file with mode: 0644]
ext/gd/tests/imageellipse_basic.phpt
ext/gd/tests/imageellipse_basic.png [new file with mode: 0644]
ext/gd/tests/imagefilledarc_basic.phpt
ext/gd/tests/imagefilledarc_basic.png [new file with mode: 0644]
ext/gd/tests/imagefilledarc_error1.phpt
ext/gd/tests/imagefilledarc_error1.png [new file with mode: 0644]
ext/gd/tests/imagefilledarc_variation1.phpt
ext/gd/tests/imagefilledarc_variation1.png [new file with mode: 0644]
ext/gd/tests/imagefilledarc_variation2.phpt
ext/gd/tests/imagefilledarc_variation2.png [new file with mode: 0644]
ext/gd/tests/imagefilledellipse_basic.phpt
ext/gd/tests/imagefilledellipse_basic.png [new file with mode: 0644]
ext/gd/tests/imagefilltoborder_basic.phpt
ext/gd/tests/imagefilltoborder_basic.png [new file with mode: 0644]
ext/gd/tests/imagegammacorrect_basic.phpt
ext/gd/tests/imagegammacorrect_basic.png [new file with mode: 0644]
ext/gd/tests/imagegammacorrect_variation1.phpt
ext/gd/tests/imagegammacorrect_variation1.png [new file with mode: 0644]
ext/gd/tests/imagelayereffect_basic.phpt
ext/gd/tests/imagelayereffect_basic.png [new file with mode: 0644]
ext/gd/tests/imagerectangle_basic.phpt
ext/gd/tests/imagerectangle_basic.png [new file with mode: 0644]
ext/gd/tests/imagesetbrush_basic.phpt
ext/gd/tests/imagesetbrush_basic.png [new file with mode: 0644]
ext/gd/tests/imagesetthickness_basic.phpt
ext/gd/tests/imagesetthickness_basic.png [new file with mode: 0644]
ext/gd/tests/imagestring_basic.phpt
ext/gd/tests/imagestring_basic.png [new file with mode: 0644]
ext/gd/tests/imagestringup_basic.phpt
ext/gd/tests/imagestringup_basic.png [new file with mode: 0644]
ext/gd/tests/imagetruecolortopalette_basic.phpt
ext/gd/tests/imagetruecolortopalette_basic.png [new file with mode: 0644]
ext/gd/tests/libgd00100.phpt
ext/gd/tests/libgd00100.png [new file with mode: 0644]

index 0a4efddeca6cc9a314db5f9168b924a7ae3e8d5f..1ce1eabfe986161764bc794d8cf2cfd391be2296 100644 (file)
@@ -135,6 +135,7 @@ tests/*/*.sh
 */tests/*/*.sh
 */*/tests/*.diff
 */*/tests/*.out
+*/*/tests/*.out.png
 */*/tests/*.php
 */*/tests/*.exp
 */*/tests/*.log
index b18eef4332ffadfd77da04041806fe7831c8bace..3d4335d461506241ab106838abc2ae7edb42e09d 100644 (file)
@@ -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 (file)
index 0000000..5e6251f
Binary files /dev/null and b/ext/gd/tests/bug22544.png differ
index 43d11ae35693f25847f9d1eefd1119f06e2c504f..0f130d28fd356af939a43bd2dc752c1d7553a287 100644 (file)
@@ -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 (file)
index 0000000..bb7fcd5
Binary files /dev/null and b/ext/gd/tests/bug43828.png differ
index a01c5c32b85ecf448963bfd34f23ad85be990f6b..307b06855c6d99f1c4dc52c096e1d53701d785eb 100644 (file)
@@ -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 (file)
index 0000000..f654b3d
Binary files /dev/null and b/ext/gd/tests/bug66005.png differ
index edc3ce327f190bd02d93c40c654a0b69bbb67747..f9592c05b7675051d13c289dc66929258c2294de 100644 (file)
@@ -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 (file)
index 0000000..a3daed2
Binary files /dev/null and b/ext/gd/tests/bug72604.png differ
index 0ad03a7d3c103b2b337783684f2e7b9d97e60e25..3ab068a13420fceb33132f151054dbae6426ec10 100644 (file)
@@ -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 (file)
index 0000000..83eeb81
Binary files /dev/null and b/ext/gd/tests/bug72913.png differ
index f17227eccda5e01f61b796d20ae0e2c7c5f1a55d..01ba83102ec15112d07f30dcc09c9c367fa45c55 100644 (file)
@@ -59,3 +59,71 @@ function get_libxpm_version()
        return $version;\r
 }\r
 \r
+/**\r
+ * Tests that an in-memory image equals a PNG file.\r
+ *\r
+ * It checks for equal image sizes, and whether any pixels are different.\r
+ * The textual result is printed, so the EXPECT section should contain the line\r
+ * "The images are equal."\r
+ *\r
+ * If the PNG file does not exists, or the images are not equal, a diagnostic\r
+ * message is printed, and the actual file is stored right beside the temporary\r
+ * .php test file with the extension .out.png, to be able to manually inspect\r
+ * the result.\r
+ *\r
+ * @param string $filename\r
+ * @param resource $actual\r
+ * @return void\r
+ */\r
+function test_image_equals_file($filename, $actual)\r
+{\r
+       if (!file_exists($filename)) {\r
+               echo "The expected image does not exist.\n";\r
+               save_actual_image($actual);\r
+               return;\r
+       }\r
+       $expected = imagecreatefrompng($filename);\r
+       $exp_x = imagesx($expected);\r
+       $exp_y = imagesy($expected);\r
+       $act_x = imagesx($actual);\r
+       $act_y = imagesy($actual);\r
+       if ($exp_x != $act_x || $exp_y != $act_y) {\r
+               echo "The image size differs: expected {$exp_x}x{$exp_y}, got {$act_x}x{$act_y}.\n";\r
+               save_actual_image($actual);\r
+               imagedestroy($expected);\r
+               return;\r
+       }\r
+       $pixels_changed = 0;\r
+       for ($y = 0; $y < $exp_y; $y++) {\r
+               for ($x = 0; $x < $exp_x; $x ++) {\r
+                       $exp_c = imagecolorat($expected, $x, $y);\r
+                       $act_c = imagecolorat($actual, $x, $y);\r
+                       if ($exp_c != $act_c) {\r
+                               $pixels_changed++;\r
+                       }\r
+               }\r
+       }\r
+       if (!$pixels_changed) {\r
+               echo "The images are equal.\n";\r
+       } else {\r
+               echo "The images differ in {$pixels_changed} pixels.\n";\r
+               save_actual_image($actual);\r
+       }\r
+       imagedestroy($expected);\r
+}\r
+\r
+/**\r
+ * Saves an actual image to disk.\r
+ *\r
+ * The image is saved right beside the temporary .php test file with the\r
+ * extension .out.png.\r
+ *\r
+ * @param resource $image\r
+ * @return void\r
+ */\r
+function save_actual_image($image)\r
+{\r
+       $pathinfo = pathinfo($_SERVER['SCRIPT_FILENAME']);\r
+       $filename = "{$pathinfo['dirname']}/{$pathinfo['filename']}.out.png";\r
+       imagepng($image, $filename);\r
+}\r
index 953428def9e554f2cc11d3fad9424343f67ebdbe..b4761f2399c1db0e8176cd07dbb04c13c4afcf53 100644 (file)
@@ -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 (file)
index 0000000..42a4d68
Binary files /dev/null and b/ext/gd/tests/imagearc_basic.png differ
index 05d1cd8186d375d4fe06c5202200cc584a03b488..1e63406832816977ca624db23dc8bb2eb75c1f72 100644 (file)
@@ -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 (file)
index 0000000..9cbff6e
Binary files /dev/null and b/ext/gd/tests/imagearc_error1.png differ
index aaf6103b4381b7c2780f255c9f113f3619553bc0..1b36eedf2905e3cc16926fae1ccc7a77561d9f8c 100644 (file)
@@ -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 (file)
index 0000000..8bc15c4
Binary files /dev/null and b/ext/gd/tests/imagearc_variation1.png differ
index 0c1c6466e14df9f4d49bafcbc4a20987047805ff..40227c3750f5667771e4d11f506c6d01ab75d2d9 100644 (file)
@@ -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 (file)
index 0000000..40779ed
Binary files /dev/null and b/ext/gd/tests/imagearc_variation2.png differ
index fa6dd4d93520ad4046a50323d5927dd350ff1c78..f238aabae45980c4ea215e6a5f1f81d7c8084481 100644 (file)
@@ -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 (file)
index 0000000..a01222a
Binary files /dev/null and b/ext/gd/tests/imagechar_basic.png differ
index 194c32564ddbe1a5ce1d76c5de06b3e58f9a1039..50b0a596133a40f4dc0e6d99e03b0829b208166c 100644 (file)
@@ -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 (file)
index 0000000..e962865
Binary files /dev/null and b/ext/gd/tests/imagecharup_basic.png differ
index 8595b405074e775c853f04f2ab8a1aa1939d7d36..f0d1e45e6efc44a0e117e67c3c1f213cf6d7e817 100644 (file)
@@ -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 (file)
index 0000000..ef975af
Binary files /dev/null and b/ext/gd/tests/imagecolorallocatealpha_basic.png differ
index 01e5f7bfd585d862f4b68ed2773d3ec8abe443b8..f051a2202f7682c29fdac3e39a2ec20696fe9e72 100644 (file)
@@ -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 (file)
index 0000000..b9e77d1
Binary files /dev/null and b/ext/gd/tests/imagecolorset_basic.png differ
index 9e629ac0e658ddd2cbd80023484582d2a03be599..972de76f86f97560c77a8954923a5f5d0d0b7cb2 100644 (file)
@@ -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 (file)
index 0000000..0558a1b
Binary files /dev/null and b/ext/gd/tests/imageconvolution_basic.png differ
index a6eced15b338f3baba929982e7eae5b1935cdc00..e2a5a09fbaea582806b758bf6927b6cf8c83a068 100644 (file)
@@ -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 (file)
index 0000000..1728cb4
Binary files /dev/null and b/ext/gd/tests/imagecreatetruecolor_basic.png differ
index 759e42ab72e4da10c42ed20b3b2949141e9b69d2..f3b1e10bfeaedda661d28f618a3a315aa8dab7cd 100644 (file)
@@ -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 (file)
index 0000000..7dda55a
Binary files /dev/null and b/ext/gd/tests/imageellipse_basic.png differ
index 8c76a83406b78ba04acf0e5a02f6f71d22de204e..9969e6be95d7c49e5bbd28a27d6e4c665f57f84b 100644 (file)
@@ -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 (file)
index 0000000..b6bfc61
Binary files /dev/null and b/ext/gd/tests/imagefilledarc_basic.png differ
index 46d51ba34bbb8d44ad9f0712bd6a2596695214dc..81d04358fbbde8d7e4ea05f13a5b95ccab95da55 100644 (file)
@@ -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 (file)
index 0000000..9cbff6e
Binary files /dev/null and b/ext/gd/tests/imagefilledarc_error1.png differ
index f4130a9c690a801040a4a96509a4133a0fa4caf1..7eb2350cb383d11b2be43721979d567d6c576c31 100644 (file)
@@ -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 (file)
index 0000000..802d227
Binary files /dev/null and b/ext/gd/tests/imagefilledarc_variation1.png differ
index 033d6f65f05eeef242f695b030377e7b02d26712..28cb517631a5bf74e5050a0787213c4266adba2f 100644 (file)
@@ -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 (file)
index 0000000..7f3930b
Binary files /dev/null and b/ext/gd/tests/imagefilledarc_variation2.png differ
index 8b3682bfa8524465b0852bb8f682c9385c6c3962..1dee961b13be97018bb183af3d53f59999d7ea77 100644 (file)
@@ -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 (file)
index 0000000..8a56bec
Binary files /dev/null and b/ext/gd/tests/imagefilledellipse_basic.png differ
index 524022a15db46d8d46a508a96e018899bcb4fda1..843eed473d23b3807be59030c6d6e18fc05497bf 100644 (file)
@@ -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 (file)
index 0000000..7c163e3
Binary files /dev/null and b/ext/gd/tests/imagefilltoborder_basic.png differ
index b803e9517f5225ce0d7c0ea27eba030a9d420a4a..c315c4688e9bb37b085f31738f103870fe7419d8 100644 (file)
@@ -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 (file)
index 0000000..9eeaf26
Binary files /dev/null and b/ext/gd/tests/imagegammacorrect_basic.png differ
index a0df819a7d970b97b04d9d6dfe645307a4d7d22f..73327c1eff977b424ff964a6cf82e6c6eb30e4d4 100644 (file)
@@ -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 (file)
index 0000000..f971889
Binary files /dev/null and b/ext/gd/tests/imagegammacorrect_variation1.png differ
index 2f1ee47aafa8825edc166da98ccf5dc0b459cf9a..2c948fd0c51ce3bbb700ffe2476058630e6cfdc8 100644 (file)
@@ -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 (file)
index 0000000..1728cb4
Binary files /dev/null and b/ext/gd/tests/imagelayereffect_basic.png differ
index eaa1566f7f3cae0f527dd4a2e17d830925db3c2d..507d71532663c7090e220d05d54555449017c6db 100644 (file)
@@ -15,13 +15,8 @@ $image = imagecreatetruecolor( 100, 100 );
 // Draw a rectangle\r
 imagerectangle( $image, 0, 0, 50, 50, imagecolorallocate($image, 255, 255, 255) );\r
 \r
-ob_start(); \r
-imagegd( $image );\r
-$img = ob_get_contents(); \r
-ob_end_clean();\r
-\r
-echo md5(base64_encode($img));\r
-\r
+include_once __DIR__ . '/func.inc';\r
+test_image_equals_file(__DIR__ . '/imagerectangle_basic.png', $image);\r
 ?> \r
 --EXPECT-- \r
-e7f8ca8c63fb08b248f3ed6435983aed
\ No newline at end of file
+The images are equal.\r
diff --git a/ext/gd/tests/imagerectangle_basic.png b/ext/gd/tests/imagerectangle_basic.png
new file mode 100644 (file)
index 0000000..dcb4d2e
Binary files /dev/null and b/ext/gd/tests/imagerectangle_basic.png differ
index 763a4c414d83285cd96ebc2230673373ee40f551..e1a9c6a80c837f551db2f325b97f77cea05f2ea3 100644 (file)
@@ -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 (file)
index 0000000..0242634
Binary files /dev/null and b/ext/gd/tests/imagesetbrush_basic.png differ
index 205fe7e59e84d0a413c9d50c4a6b92c19aa091c3..3c91a886df04c5fe2101c94a9185338ae1ee5e46 100644 (file)
@@ -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 (file)
index 0000000..e38e7db
Binary files /dev/null and b/ext/gd/tests/imagesetthickness_basic.png differ
index f56a2d3226878511c654680b132077bd872c9fba..311683f7af81c436cd1a1765a8cc6fec4d87df25 100644 (file)
@@ -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 (file)
index 0000000..7f9fd12
Binary files /dev/null and b/ext/gd/tests/imagestring_basic.png differ
index 144dfc0d8df3ed3a02e761cc8ce938e1bef5856f..015d375eded84a81173441dd5424c8d4e2585cfd 100644 (file)
@@ -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 (file)
index 0000000..875b5ba
Binary files /dev/null and b/ext/gd/tests/imagestringup_basic.png differ
index e7b327475bd09953f052462a4aa74632b573bb72..9bc922a15b822e7bf9a30a78afc106296c293a7c 100644 (file)
@@ -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 (file)
index 0000000..7d042f2
Binary files /dev/null and b/ext/gd/tests/imagetruecolortopalette_basic.png differ
index 49716d7107a56e129f5a35353c0b843429e0b046..84f8858a9ae0aa97c29beb701c856a485e1712c3 100644 (file)
@@ -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 (file)
index 0000000..8d4f6a1
Binary files /dev/null and b/ext/gd/tests/libgd00100.png differ