xref: /PHP-8.4/ext/gd/tests/bug75124.phpt (revision 0b8466f2)
1--TEST--
2Bug #75124 (gdImageGrayScale() may produce colors)
3--EXTENSIONS--
4gd
5--SKIPIF--
6<?php
7if (!GD_BUNDLED && version_compare(GD_VERSION, '2.2.5', '<')) {
8    die('skip only for bundled libgd or external libgd >= 2.2.5');
9}
10if (!(imagetypes() & IMG_PNG)) {
11    die("skip No PNG support");
12}
13?>
14--FILE--
15<?php
16$im = imagecreatefrompng(__DIR__ . '/bug75124.png');
17var_dump(imageistruecolor($im));
18imagefilter($im, IMG_FILTER_GRAYSCALE);
19for ($i = 0, $width = imagesx($im); $i < $width; $i ++) {
20    for ($j = 0, $height = imagesy($im); $j < $height; $j++) {
21        $color = imagecolorat($im, $i, $j);
22        $red = ($color >> 16) & 0xff;
23        $green = ($color >> 8) & 0xff;
24        $blue = $color & 0xff;
25        if ($red != $green || $green != $blue) {
26            echo "non grayscale pixel detected\n";
27            break 2;
28        }
29    }
30}
31?>
32--EXPECT--
33bool(true)
34