summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph M. Becker <cmbecker69@gmx.de>2016-09-25 10:46:44 +0200
committerChristoph M. Becker <cmbecker69@gmx.de>2016-09-25 10:46:44 +0200
commitfa9d41f66cb2759dc7722081225eed5565f40716 (patch)
tree9bc60a19304163aa338e5b7a2a95f8fb2c32b6f4
parentbc22582cf7c8782a75e24395af23170d2c4400a7 (diff)
parentc696bc8cfac64a66bb69dffe96d312a621fcdab7 (diff)
downloadphp-git-fa9d41f66cb2759dc7722081225eed5565f40716.tar.gz
Merge branch 'PHP-5.6' into PHP-7.0
-rw-r--r--ext/gd/tests/func.inc23
-rw-r--r--ext/gd/tests/test_image_equals_file_palette.phpt42
2 files changed, 63 insertions, 2 deletions
diff --git a/ext/gd/tests/func.inc b/ext/gd/tests/func.inc
index 01ba83102e..708fccd3d1 100644
--- a/ext/gd/tests/func.inc
+++ b/ext/gd/tests/func.inc
@@ -82,7 +82,9 @@ function test_image_equals_file($filename, $actual)
save_actual_image($actual);
return;
}
+ $actual = test_to_truecolor($actual);
$expected = imagecreatefrompng($filename);
+ $expected = test_to_truecolor($expected);
$exp_x = imagesx($expected);
$exp_y = imagesy($expected);
$act_x = imagesx($actual);
@@ -90,7 +92,6 @@ function test_image_equals_file($filename, $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;
@@ -109,7 +110,25 @@ function test_image_equals_file($filename, $actual)
echo "The images differ in {$pixels_changed} pixels.\n";
save_actual_image($actual);
}
- imagedestroy($expected);
+}
+
+/**
+ * Returns the truecolor version of an image.
+ *
+ * @param resource $image
+ * @return resource
+ */
+function test_to_truecolor($image)
+{
+ if (imageistruecolor($image)) {
+ return $image;
+ } else {
+ $width = imagesx($image);
+ $height = imagesy($image);
+ $result = imagecreatetruecolor($width, $height);
+ imagecopy($result, $image, 0,0, 0,0, $width, $height);
+ return $result;
+ }
}
/**
diff --git a/ext/gd/tests/test_image_equals_file_palette.phpt b/ext/gd/tests/test_image_equals_file_palette.phpt
new file mode 100644
index 0000000000..130fa43202
--- /dev/null
+++ b/ext/gd/tests/test_image_equals_file_palette.phpt
@@ -0,0 +1,42 @@
+--TEST--
+test_image_equals_file(): comparing palette images
+--SKIPIF--
+<?php
+if (!extension_loaded('gd')) die('skip gd extension not available');
+?>
+--FILE--
+<?php
+require_once __DIR__ . DIRECTORY_SEPARATOR . 'func.inc';
+
+$im = imagecreate(10, 10);
+imagecolorallocate($im, 255, 255, 255);
+$red = imagecolorallocate($im, 255, 0, 0);
+imagefilledrectangle($im, 3,3, 7,7, $red);
+
+$filename = __DIR__ . DIRECTORY_SEPARATOR . 'test_image_equals_file_palette.png';
+imagepng($im, $filename);
+
+$im = imagecreate(10, 10);
+imagecolorallocate($im, 255, 255, 255);
+$blue = imagecolorallocate($im, 0, 0, 255);
+imagefilledrectangle($im, 3,3, 7,7, $blue);
+
+test_image_equals_file($filename, $im);
+
+$im = imagecreate(10, 10);
+imagecolorallocate($im, 255, 255, 255);
+imagecolorallocate($im, 0, 0, 0);
+$red = imagecolorallocate($im, 255, 0, 0);
+imagefilledrectangle($im, 3,3, 7,7, $red);
+
+test_image_equals_file($filename, $im);
+?>
+===DONE===
+--EXPECT--
+The images differ in 25 pixels.
+The images are equal.
+===DONE===
+--CLEAN--
+<?php
+unlink(__DIR__ . DIRECTORY_SEPARATOR . 'test_image_equals_file_palette.png');
+?>