xref: /PHP-7.1/ext/gd/tests/bug47946.phpt (revision 3f72c77c)
1--TEST--
2Bug #47946 (ImageConvolution overwrites background)
3--DESCRIPTION--
4The expected image has black pixel artifacts, what is another issue, though
5(perhaps #40158).
6--SKIPIF--
7<?php
8if (!extension_loaded('gd')) die('skip gd extension not available');
9?>
10--FILE--
11<?php
12function array_flatten($array)
13{
14    $tempArray = array();
15
16    foreach ($array as $value) {
17        if (is_array($value)) {
18            $tempArray = array_merge($tempArray, array_flatten($value));
19        } else {
20            $tempArray[] = $value;
21        }
22    }
23
24    return $tempArray;
25}
26
27function makeFilter($resource, $matrix, $offset = 1.0)
28{
29    $divisor = array_sum(array_flatten($matrix));
30    if ($divisor == 0) {
31        $divisor = .01;
32    }
33    return imageconvolution($resource, $matrix, $divisor, $offset);
34}
35
36$edgeMatrix = array(array(1, 0, 1), array(0, 5, 0), array(1, 0, 1));
37
38$im = imagecreatetruecolor(40, 40);
39imagealphablending($im, false);
40imagefilledrectangle($im, 0, 0, 39, 39, 0x7fffffff);
41imagefilledellipse($im, 19, 19, 20, 20, 0x00ff00);
42imagesavealpha($im, true);
43makeFilter($im, $edgeMatrix);
44
45require_once __DIR__ . '/func.inc';
46test_image_equals_file(__DIR__ . '/bug47946_exp.png', $im);
47?>
48===DONE===
49--EXPECT--
50The images are equal.
51===DONE===
52