xref: /php-src/ext/gd/tests/bug47946.phpt (revision 0b8466f2)
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');
8if (!(imagetypes() & IMG_PNG)) {
9    die("skip No PNG support");
10}
11?>
12--FILE--
13<?php
14function array_flatten($array)
15{
16    $tempArray = array();
17
18    foreach ($array as $value) {
19        if (is_array($value)) {
20            $tempArray = array_merge($tempArray, array_flatten($value));
21        } else {
22            $tempArray[] = $value;
23        }
24    }
25
26    return $tempArray;
27}
28
29function makeFilter($resource, $matrix, $offset = 1.0)
30{
31    $divisor = array_sum(array_flatten($matrix));
32    if ($divisor == 0) {
33        $divisor = .01;
34    }
35    return imageconvolution($resource, $matrix, $divisor, $offset);
36}
37
38$edgeMatrix = array(array(1, 0, 1), array(0, 5, 0), array(1, 0, 1));
39
40$im = imagecreatetruecolor(40, 40);
41imagealphablending($im, false);
42imagefilledrectangle($im, 0, 0, 39, 39, 0x7fffffff);
43imagefilledellipse($im, 19, 19, 20, 20, 0x00ff00);
44imagesavealpha($im, true);
45makeFilter($im, $edgeMatrix);
46
47require_once __DIR__ . '/func.inc';
48test_image_equals_file(__DIR__ . '/bug47946_exp.png', $im);
49?>
50--EXPECT--
51The images are equal.
52