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