summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph M. Becker <cmb@php.net>2016-07-20 19:26:29 +0200
committerChristoph M. Becker <cmb@php.net>2016-07-20 19:26:29 +0200
commitf3a89ff075fcc4628f0f15f0b5ebf18355644e7f (patch)
tree888c1e3d5e6cdaed93ce651b2239e6d660439b27
parentbe53fab51a27bff2d7a6d3e316ea491ce461896b (diff)
downloadphp-git-f3a89ff075fcc4628f0f15f0b5ebf18355644e7f.tar.gz
Add test case for imagecopyresampled() with alpha
-rw-r--r--ext/gd/tests/imagecopyresampled_variation1.phpt70
1 files changed, 70 insertions, 0 deletions
diff --git a/ext/gd/tests/imagecopyresampled_variation1.phpt b/ext/gd/tests/imagecopyresampled_variation1.phpt
new file mode 100644
index 0000000000..98547f8931
--- /dev/null
+++ b/ext/gd/tests/imagecopyresampled_variation1.phpt
@@ -0,0 +1,70 @@
+--TEST--
+Test for correct colors of imagecopyresampled() wrt. alpha
+--SKIPIF--
+<?php
+if (!extension_loaded('gd')) die('skip ext/gd required');
+?>
+--FILE--
+<?php
+
+const EXP_RED = 66;
+const EXP_GREEN = 66;
+const EXP_BLUE = 133;
+const EXP_ALPHA = 32;
+
+/* create the source image */
+$im = imagecreatetruecolor(10, 10);
+imagealphablending($im, false);
+$solid = imagecolorallocate($im, 0, 100, 150);
+$transparent = imagecolorallocatealpha($im, 200, 0, 100, 64);
+
+/* draw a checker pattern */
+for ($i = 0; $i < imagesx($im); $i++) {
+ for ($j = 0; $j < imagesy($im); $j++) {
+ imagesetpixel($im, $i, $j, ($i%2 != $j%2 ? $solid : $transparent));
+ }
+}
+
+/* create the destination image */
+$copy = imagecreatetruecolor(5, 5);
+imagealphablending($copy, false);
+imagesavealpha($copy, true);
+imagecopyresampled($copy, $im, 0,0, 0,0, 5,5, 10, 10);
+
+/* assert all pixels have the same color */
+$color = imagecolorat($copy, 3, 3);
+for ($i = 0; $i < imagesx($copy); $i++) {
+ for ($j = 0; $j < imagesy($copy); $j++) {
+ if (imagecolorat($copy, $i, $j) != $color) {
+ echo 'different pixel values', PHP_EOL;
+ }
+ }
+}
+
+/* assign actual component values */
+$red = ($color & 0xFF0000) >> 16;
+$green = ($color & 0x00FF00) >> 8;
+$blue = ($color & 0x0000FF);
+$alpha = ($color & 0x7F000000) >> 24;
+
+/* test for expected component values */
+if (!($red >= EXP_RED - 1 && $red <= EXP_RED + 1)) {
+ printf("red: expected roughly %d, got %d\n", EXP_RED, $red);
+}
+if (!($green >= EXP_GREEN - 1 && $green <= EXP_GREEN + 1)) {
+ printf("green: expected roughly %d, got %d\n", EXP_GREEN, $green);
+}
+if (!($blue >= EXP_BLUE - 1 && $blue <= EXP_BLUE + 1)) {
+ printf("blue: expected roughly %d, got %d\n", EXP_BLUE, $blue);
+}
+if (!($alpha >= EXP_ALPHA - 1 && $alpha <= EXP_ALPHA + 1)) {
+ printf("alpha: expected roughly %d, got %d\n", EXP_ALPHA, $alpha);
+}
+
+imagedestroy($copy);
+imagedestroy($im);
+
+echo 'DONE';
+?>
+--EXPECT--
+DONE