File: bug47946.phpt

package info (click to toggle)
php8.4 8.4.11-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 208,108 kB
  • sloc: ansic: 1,060,628; php: 35,345; sh: 11,866; cpp: 7,201; pascal: 4,913; javascript: 3,091; asm: 2,810; yacc: 2,411; makefile: 689; xml: 446; python: 301; awk: 148
file content (51 lines) | stat: -rw-r--r-- 1,245 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
--TEST--
Bug #47946 (ImageConvolution overwrites background)
--EXTENSIONS--
gd
--SKIPIF--
<?php
if (!GD_BUNDLED && version_compare(GD_VERSION, '2.2.5', '<=')) die('skip upstream fix not yet released');
if (!(imagetypes() & IMG_PNG)) {
    die("skip No PNG support");
}
?>
--FILE--
<?php
function array_flatten($array)
{
    $tempArray = array();

    foreach ($array as $value) {
        if (is_array($value)) {
            $tempArray = array_merge($tempArray, array_flatten($value));
        } else {
            $tempArray[] = $value;
        }
    }

    return $tempArray;
}

function makeFilter($resource, $matrix, $offset = 1.0)
{
    $divisor = array_sum(array_flatten($matrix));
    if ($divisor == 0) {
        $divisor = .01;
    }
    return imageconvolution($resource, $matrix, $divisor, $offset);
}

$edgeMatrix = array(array(1, 0, 1), array(0, 5, 0), array(1, 0, 1));

$im = imagecreatetruecolor(40, 40);
imagealphablending($im, false);
imagefilledrectangle($im, 0, 0, 39, 39, 0x7fffffff);
imagefilledellipse($im, 19, 19, 20, 20, 0x00ff00);
imagesavealpha($im, true);
makeFilter($im, $edgeMatrix);

require_once __DIR__ . '/func.inc';
test_image_equals_file(__DIR__ . '/bug47946_exp.png', $im);
?>
--EXPECT--
The images are equal.