1--TEST-- 2Bug #47946 (ImageConvolution overwrites background) 3--SKIPIF-- 4<?php 5if (!extension_loaded('gd')) die('skip gd extension not available'); 6if (!GD_BUNDLED && version_compare(GD_VERSION, '2.2.5', '<=')) die('skip upstream fix not yet released'); 7?> 8--FILE-- 9<?php 10function array_flatten($array) 11{ 12 $tempArray = array(); 13 14 foreach ($array as $value) { 15 if (is_array($value)) { 16 $tempArray = array_merge($tempArray, array_flatten($value)); 17 } else { 18 $tempArray[] = $value; 19 } 20 } 21 22 return $tempArray; 23} 24 25function makeFilter($resource, $matrix, $offset = 1.0) 26{ 27 $divisor = array_sum(array_flatten($matrix)); 28 if ($divisor == 0) { 29 $divisor = .01; 30 } 31 return imageconvolution($resource, $matrix, $divisor, $offset); 32} 33 34$edgeMatrix = array(array(1, 0, 1), array(0, 5, 0), array(1, 0, 1)); 35 36$im = imagecreatetruecolor(40, 40); 37imagealphablending($im, false); 38imagefilledrectangle($im, 0, 0, 39, 39, 0x7fffffff); 39imagefilledellipse($im, 19, 19, 20, 20, 0x00ff00); 40imagesavealpha($im, true); 41makeFilter($im, $edgeMatrix); 42 43require_once __DIR__ . '/func.inc'; 44test_image_equals_file(__DIR__ . '/bug47946_exp.png', $im); 45?> 46===DONE=== 47--EXPECT-- 48The images are equal. 49===DONE=== 50