@@ -70,12 +70,8 @@ function get_libxpm_version()
7070 * message is printed, and the actual file is stored right beside the temporary
7171 * .php test file with the extension .out.png, to be able to manually inspect
7272 * the result.
73- *
74- * @param string $filename
75- * @param resource $actual
76- * @return void
7773 */
78- function test_image_equals_file ($ filename , $ actual )
74+ function test_image_equals_file (string $ filename , GdImage $ actual ): void
7975{
8076 if (!file_exists ($ filename )) {
8177 echo "The expected image does not exist. \n" ;
@@ -85,13 +81,29 @@ function test_image_equals_file($filename, $actual)
8581 $ actual = test_to_truecolor ($ actual );
8682 $ expected = imagecreatefrompng ($ filename );
8783 $ expected = test_to_truecolor ($ expected );
84+ test_image_equals_image ($ expected , $ actual , true );
85+ }
86+
87+ /**
88+ * Tests that an in-memory image equals another in-memory image.
89+ *
90+ * It checks for equal image sizes, and whether any pixels are different.
91+ * The textual result is printed, so the EXPECT section should contain the line
92+ * "The images are equal."
93+ *
94+ * If the images are not equal, a diagnostic message is printed.
95+ */
96+ function test_image_equals_image (GdImage $ expected , GdImage $ actual , bool $ save_actual = false ): void
97+ {
8898 $ exp_x = imagesx ($ expected );
8999 $ exp_y = imagesy ($ expected );
90100 $ act_x = imagesx ($ actual );
91101 $ act_y = imagesy ($ actual );
92102 if ($ exp_x != $ act_x || $ exp_y != $ act_y ) {
93103 echo "The image size differs: expected {$ exp_x }x {$ exp_y }, got {$ act_x }x {$ act_y }. \n" ;
94- save_actual_image ($ actual );
104+ if ($ save_actual ) {
105+ save_actual_image ($ actual );
106+ }
95107 return ;
96108 }
97109 $ pixels_changed = 0 ;
@@ -108,7 +120,9 @@ function test_image_equals_file($filename, $actual)
108120 echo "The images are equal. \n" ;
109121 } else {
110122 echo "The images differ in {$ pixels_changed } pixels. \n" ;
111- save_actual_image ($ actual );
123+ if ($ save_actual ) {
124+ save_actual_image ($ actual );
125+ }
112126 }
113127}
114128
0 commit comments