1--TEST-- 2Test for correct colors of imagecopyresampled() wrt. alpha 3--EXTENSIONS-- 4gd 5--FILE-- 6<?php 7 8const EXP_RED = 66; 9const EXP_GREEN = 66; 10const EXP_BLUE = 133; 11const EXP_ALPHA = 32; 12 13/* create the source image */ 14$im = imagecreatetruecolor(10, 10); 15imagealphablending($im, false); 16$solid = imagecolorallocate($im, 0, 100, 150); 17$transparent = imagecolorallocatealpha($im, 200, 0, 100, 64); 18 19/* draw a checker pattern */ 20for ($i = 0; $i < imagesx($im); $i++) { 21 for ($j = 0; $j < imagesy($im); $j++) { 22 imagesetpixel($im, $i, $j, ($i%2 != $j%2 ? $solid : $transparent)); 23 } 24} 25 26/* create the destination image */ 27$copy = imagecreatetruecolor(5, 5); 28imagealphablending($copy, false); 29imagesavealpha($copy, true); 30imagecopyresampled($copy, $im, 0,0, 0,0, 5,5, 10, 10); 31 32/* assert all pixels have the same color */ 33$color = imagecolorat($copy, 3, 3); 34for ($i = 0; $i < imagesx($copy); $i++) { 35 for ($j = 0; $j < imagesy($copy); $j++) { 36 if (imagecolorat($copy, $i, $j) != $color) { 37 echo 'different pixel values', PHP_EOL; 38 } 39 } 40} 41 42/* assign actual component values */ 43$red = ($color & 0xFF0000) >> 16; 44$green = ($color & 0x00FF00) >> 8; 45$blue = ($color & 0x0000FF); 46$alpha = ($color & 0x7F000000) >> 24; 47 48/* test for expected component values */ 49if (!($red >= EXP_RED - 1 && $red <= EXP_RED + 1)) { 50 printf("red: expected roughly %d, got %d\n", EXP_RED, $red); 51} 52if (!($green >= EXP_GREEN - 1 && $green <= EXP_GREEN + 1)) { 53 printf("green: expected roughly %d, got %d\n", EXP_GREEN, $green); 54} 55if (!($blue >= EXP_BLUE - 1 && $blue <= EXP_BLUE + 1)) { 56 printf("blue: expected roughly %d, got %d\n", EXP_BLUE, $blue); 57} 58if (!($alpha >= EXP_ALPHA - 1 && $alpha <= EXP_ALPHA + 1)) { 59 printf("alpha: expected roughly %d, got %d\n", EXP_ALPHA, $alpha); 60} 61 62imagedestroy($copy); 63imagedestroy($im); 64 65echo 'DONE'; 66?> 67--EXPECT-- 68DONE 69