@@ -70,12 +70,8 @@ function get_libxpm_version()
70
70
* message is printed, and the actual file is stored right beside the temporary
71
71
* .php test file with the extension .out.png, to be able to manually inspect
72
72
* the result.
73
- *
74
- * @param string $filename
75
- * @param resource $actual
76
- * @return void
77
73
*/
78
- function test_image_equals_file ($ filename , $ actual )
74
+ function test_image_equals_file (string $ filename , GdImage $ actual ): void
79
75
{
80
76
if (!file_exists ($ filename )) {
81
77
echo "The expected image does not exist. \n" ;
@@ -85,13 +81,29 @@ function test_image_equals_file($filename, $actual)
85
81
$ actual = test_to_truecolor ($ actual );
86
82
$ expected = imagecreatefrompng ($ filename );
87
83
$ 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
+ {
88
98
$ exp_x = imagesx ($ expected );
89
99
$ exp_y = imagesy ($ expected );
90
100
$ act_x = imagesx ($ actual );
91
101
$ act_y = imagesy ($ actual );
92
102
if ($ exp_x != $ act_x || $ exp_y != $ act_y ) {
93
103
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
+ }
95
107
return ;
96
108
}
97
109
$ pixels_changed = 0 ;
@@ -108,7 +120,9 @@ function test_image_equals_file($filename, $actual)
108
120
echo "The images are equal. \n" ;
109
121
} else {
110
122
echo "The images differ in {$ pixels_changed } pixels. \n" ;
111
- save_actual_image ($ actual );
123
+ if ($ save_actual ) {
124
+ save_actual_image ($ actual );
125
+ }
112
126
}
113
127
}
114
128
0 commit comments