*/tests/*/*.sh
*/*/tests/*.diff
*/*/tests/*.out
+*/*/tests/*.out.png
*/*/tests/*.php
*/*/tests/*.exp
*/*/tests/*.log
?>
--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.
$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.
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==
$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.
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==
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
//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.
//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.
//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.
//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.
$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.
$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.
$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
// 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.
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.
<?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.
// 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.
//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.
//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.
//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.
//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.
//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.
// 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.
$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.
$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.
$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.
// 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
// 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.
// 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.
$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.
$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.
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.
);
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.